about summary refs log tree commit diff stats
path: root/arc/.traces/sleep-long
blob: 5a7d10e8b0b32e28c477bbb7beabb38eca2e1f57 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
c{0: 0 (((sleep)) ((for-some-cycles literal)) ((20 literal))) -- nil
c{0: 1 (((1 integer)) <- ((copy)) ((0 literal))) -- nil
c{0: 2 (((1 integer)) <- ((copy)) ((0 literal))) -- nil
c{1: 0 ✓ (((sleep)) ((for-some-cycles literal)) ((20 literal)))
c{1: 1 ✓ (((1 integer)) <- ((copy)) ((0 literal)))
c{1: 2 ✓ (((1 integer)) <- ((copy)) ((0 literal)))
c{0: 0 (((2 integer)) <- ((copy)) ((0 literal))) -- nil
c{0: 1 (((2 integer)) <- ((copy)) ((0 literal))) -- nil
c{1: 0 ✓ (((2 integer)) <- ((copy)) ((0 literal)))
c{1: 1 ✓ (((2 integer)) <- ((copy)) ((0 literal)))
cn0: convert-names in f1
cn0: (((sleep)) ((for-some-cycles literal)) ((20 literal))) nil nil
cn0: checking arg ((for-some-cycles literal))
cn0: checking arg ((20 literal))
cn0: (((1 integer)) <- ((copy)) ((0 literal))) nil nil
cn0: checking arg ((0 literal))
cn0: checking oarg ((1 integer))
maybe-add: ((1 integer))
cn0: (((1 integer)) <- ((copy)) ((0 literal))) nil nil
cn0: checking arg ((0 literal))
cn0: checking oarg ((1 integer))
maybe-add: ((1 integer))
cn0: convert-names in f2
cn0: (((2 integer)) <- ((copy)) ((0 literal))) nil nil
cn0: checking arg ((0 literal))
cn0: checking oarg ((2 integer))
maybe-add: ((2 integer))
cn0: (((2 integer)) <- ((copy)) ((0 literal))) nil nil
cn0: checking arg ((0 literal))
cn0: checking oarg ((2 integer))
maybe-add: ((2 integer))
cn1: (((sleep)) ((for-some-cycles literal)) ((20 literal)))
cn1: (((1 integer)) <- ((copy)) ((0 literal)))
cn1: (((1 integer)) <- ((copy)) ((0 literal)))
cn1: (((2 integer)) <- ((copy)) ((0 literal)))
cn1: (((2 integer)) <- ((copy)) ((0 literal)))
schedule: f1
run: f1 0: (((sleep)) ((for-some-cycles literal)) ((20 literal)))
run: f1 0: sleeping until 21
schedule: pushing f1 to sleep queue
schedule: f2
run: f2 0: (((2 integer)) <- ((copy)) ((0 literal)))
run: f2 0: 0 => ((2 integer))
mem: ((2 integer)): 2 <= 0
run: f2 1: (((2 integer)) <- ((copy)) ((0 literal)))
run: f2 1: 0 => ((2 integer))
mem: ((2 integer)): 2 <= 0
schedule: done with routine nil
schedule: skipping to cycle 22
schedule: waking up f1
schedule: f1
run: f1 1: (((1 integer)) <- ((copy)) ((0 literal)))
run: f1 1: 0 => ((1 integer))
mem: ((1 integer)): 1 <= 0
run: f1 2: (((1 integer)) <- ((copy)) ((0 literal)))
run: f1 2: 0 => ((1 integer))
mem: ((1 integer)): 1 <= 0
schedule: done with routine nil
or: #888888 } /* Comment.Multiline */ .highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */ .highlight .cpf { color: #888888 } /* Comment.PreprocFile */ .highlight .c1 { color: #888888 } /* Comment.Single */ .highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */ .highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */ .highlight .ge { font-style: italic } /* Generic.Emph */ .highlight .ges { font-weight: bold; font-style: italic } /* Generic.EmphStrong */ .highlight .gr { color: #aa0000 } /* Generic.Error */ .highlight .gh { color: #333333 } /* Generic.Heading */ .highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */ .highlight .go { color: #888888 } /* Generic.Output */ .highlight .gp { color: #555555 } /* Generic.Prompt */ .highlight .gs { font-weight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
# Copyright (C) 2009, 2010  Roman Zimbelmann <romanz@lavabit.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

"""
The statusbar displays information about the current file and directory.

On the left side, there is a display similar to what "ls -l" would
print for the current file.  The right side shows directory information
such as the space used by all the files in this directory.
"""

from pwd import getpwuid
from grp import getgrgid
from os import getuid, readlink
from time import time, strftime, localtime

from ranger.ext.human_readable import human_readable
from . import Widget
from ranger.gui.bar import Bar

class StatusBar(Widget):
	__doc__ = __doc__
	owners = {}
	groups = {}
	timeformat = '%Y-%m-%d %H:%M'
	hint = None
	msg = None

	old_cf = None
	old_mtime = None
	old_du = None
	old_hint = None
	result = None

	def __init__(self, win, column=None):
		Widget.__init__(self, win)
		self.column = column
		self.settings.signal_bind('setopt.display_size_in_status_bar',
				self.request_redraw, weak=True)

	def request_redraw(self):
		self.need_redraw = True

	def notify(self, text, duration=4, bad=False):
		self.msg = Message(text, duration, bad)

	def draw(self):
		"""Draw the statusbar"""

		if self.hint and isinstance(self.hint, str):
			if self.old_hint != self.hint:
				self.need_redraw = True
			if self.need_redraw:
				self._draw_hint()
			return

		if self.old_hint and not self.hint:
			self.old_hint = None
			self.need_redraw = True

		if self.msg:
			if self.msg.is_alive():
				self._draw_message()
				return
			else:
				self.msg = None
				self.need_redraw = True

		try:
			mtime = self.env.cf.stat.st_mtime
		except:
			mtime = -1

		if not self.result:
			self.need_redraw = True

		if self.old_du and not self.env.cwd.disk_usage:
			self.old_du = self.env.cwd.disk_usage
			self.need_redraw = True

		if self.old_cf != self.env.cf:
			self.old_cf = self.env.cf
			self.need_redraw = True

		if self.old_mtime != mtime:
			self.old_mtime = mtime
			self.need_redraw = True

		if self.need_redraw:
			self.need_redraw = False

			self._calc_bar()
			self._print_result(self.result)

	def _calc_bar(self):
		bar = Bar('in_statusbar')
		self._get_left_part(bar)
		self._get_right_part(bar)
		bar.shrink_by_removing(self.wid)

		self.result = bar.combine()

	def _draw_message(self):
		self.win.erase()
		self.color('in_statusbar', 'message',
				self.msg.bad and 'bad' or 'good')
		self.addnstr(0, 0, self.msg.text, self.wid)

	def _draw_hint(self):
		self.win.erase()
		highlight = True
		space_left = self.wid
		starting_point = self.x
		for string in self.hint.split('*'):
			highlight = not highlight
			if highlight:
				self.color('in_statusbar', 'text', 'highlight')
			else:
				self.color('in_statusbar', 'text')

			try:
				self.addnstr(0, starting_point, string, space_left)
			except:
				break
			space_left -= len(string)
			starting_point += len(string)

	def _get_left_part(self, bar):
		left = bar.left

		if self.column is not None and self.column.target is not None\
				and self.column.target.is_directory:
			target = self.column.target.pointed_obj
		else:
			target = self.env.at_level(0).pointed_obj
		try:
			stat = target.stat
		except:
			return
		if stat is None:
			return

		perms = target.get_permission_string()
		how = getuid() == stat.st_uid and 'good' or 'bad'
		left.add(perms, 'permissions', how)
		left.add_space()
		left.add(str(stat.st_nlink), 'nlink')
		left.add_space()
		left.add(self._get_owner(target), 'owner')
		left.add_space()
		left.add(self._get_group(target), 'group')

		if target.is_link:
			how = target.exists and 'good' or 'bad'
			try:
				dest = readlink(target.path)
			except:
				dest = '?'
			left.add(' -> ' + dest, 'link', how)
		else:
			if self.settings.display_size_in_status_bar and target.infostring:
				left.add(target.infostring)

			left.add_space()

			left.add(strftime(self.timeformat,
					localtime(stat.st_mtime)), 'mtime')

	def _get_owner(self, target):
		uid = target.stat.st_uid

		try:
			return self.owners[uid]
		except KeyError:
			try:
				self.owners[uid] = getpwuid(uid)[0]
				return self.owners[uid]
			except KeyError:
				return str(uid)

	def _get_group(self, target):
		gid = target.stat.st_gid

		try:
			return self.groups[gid]
		except KeyError:
			try:
				self.groups[gid] = getgrgid(gid)[0]
				return self.groups[gid]
			except KeyError:
				return str(gid)

	def _get_right_part(self, bar):
		right = bar.right
		if self.column is None:
			return

		target = self.column.target
		if target is None \
				or not target.accessible \
				or (target.is_directory and target.files is None):
			return

		pos = target.scroll_begin
		max_pos = len(target) - self.column.hei
		base = 'scroll'

		if target.marked_items:
			if len(target.marked_items) == len(target.files):
				right.add(human_readable(target.disk_usage, seperator=''))
			else:
				right.add(human_readable(sum(f.size \
					for f in target.marked_items \
					if f.is_file), seperator=''))
			right.add("/" + str(len(target.marked_items)))
		else:
			right.add(human_readable(target.disk_usage, seperator='') +
					" sum, ")
			right.add(human_readable(self.env.get_free_space( \
					target.mount_path), seperator='') + " free")
		right.add("  ", "space")

		if target.marked_items:
			# Indicate that there are marked files. Useful if you scroll
			# away and don't see them anymore.
			right.add('Mrk', base, 'marked')
		elif len(target.files):
			right.add(str(target.pointer + 1) + '/'
					+ str(len(target.files)) + '  ', base)
			if max_pos == 0:
				right.add('All', base, 'all')
			elif pos == 0:
				right.add('Top', base, 'top')
			elif pos >= max_pos:
				right.add('Bot', base, 'bot')
			else:
				right.add('{0:0>.0f}%'.format(100.0 * pos / max_pos),
						base, 'percentage')
		else:
			right.add('0/0  All', base, 'all')

	def _print_result(self, result):
		self.win.move(0, 0)
		for part in result:
			self.color(*part.lst)
			self.addstr(part.string)
		self.color_reset()

class Message(object):
	elapse = None
	text = None
	bad = False

	def __init__(self, text, duration, bad):
		self.text = text
		self.bad = bad
		self.elapse = time() + duration

	def is_alive(self):
		return time() <= self.elapse