Esempio n. 1
0
				return self.directories[repo.directory]
			else:
				r = self.process_repo(repo)
				self.directories[repo.directory] = r
				return r


class RepositoryStatusSegment(RepositorySegment):
	interval = 2

	@staticmethod
	def process_repo(repo):
		return repo.status()


repository_status = with_docstring(RepositoryStatusSegment(),
'''Return the status for the current VCS repository.''')


class BranchSegment(RepositorySegment):
	interval = 0.2
	started_repository_status = False

	@staticmethod
	def process_repo(repo):
		return repo.branch()

	@staticmethod
	def render_one(branch, status_colors=False, **kwargs):
		if branch and status_colors:
			return [{
				'contents': branch,
Esempio n. 2
0
    def render(self, ip, **kwargs):
        if not ip:
            return None
        return [{
            'contents': ip,
            'divider_highlight_group': 'background:divider'
        }]


external_ip = with_docstring(
    ExternalIpSegment(), '''Return external IP address.

:param str query_url:
	URI to query for IP address, should return only the IP address as a text string

	Suggested URIs:

	* http://ipv4.icanhazip.com/
	* http://ipv6.icanhazip.com/
	* http://icanhazip.com/ (returns IPv6 address if available, else IPv4)

Divider highlight group used: ``background:divider``.
''')

# Weather condition code descriptions available at
# http://developer.yahoo.com/weather/#codes
weather_conditions_codes = (
    ('tornado', 'stormy'),  # 0
    ('tropical_storm', 'stormy'),  # 1
    ('hurricane', 'stormy'),  # 2
    ('severe_thunderstorms', 'stormy'),  # 3
    ('thunderstorms', 'stormy'),  # 4
Esempio n. 3
0
class SecureEmailIMAPSegment(EmailIMAPSegment):
    @staticmethod
    def key(server='imap.gmail.com', port=993, folder='INBOX', **kwargs):
        username = os.getenv("PL_EMAIL_SEGMENT_USERNAME", '')
        password = os.getenv("PL_EMAIL_SEGMENT_PASSWORD", '')

        return _IMAPKey(username, password, server, port, folder)


secure_email_imap_alert = with_docstring(
    SecureEmailIMAPSegment(), '''Return unread e-mail count for IMAP servers.

:param str username:
	login username (defaults to $PL_EMAIL_SEGMENT_USERNAME)
:param str password:
	login password (defaults to $PL_EMAIL_SEGMENT_PASSWORD)
:param str server:
	e-mail server
:param int port:
	e-mail server port
:param str folder:
	folder to check for e-mails
:param int max_msgs:
	Maximum number of messages. If there are more messages then max_msgs then it
	will use gradient level equal to 100, otherwise gradient level is equal to
	``100 * msgs_num / max_msgs``. If not present gradient is not computed.

Highlight groups used: ``email_alert_gradient`` (gradient), ``email_alert``.
''')
Esempio n. 4
0
		return {
				'artist': artist,
				'title': title,
				'playing': status,
				}

	def shorten_artist(self, artist):
		r = re.compile(r'''
			(.+?)
			\s*
			(?:
				feat(?:uring)?\.?
				|
				Ft\.
				|
				pres(?:sents)?\.?
			)\b
			''', re.I | re.X)
		m = r.match(artist)
		if m:
			artist = m.group(1)
		return artist

	def shorten_title(self, title):
		m = re.match(r'(.+?)\s*\(.*\)', title)
		if m:
			title = m.group(1)
		return title

now_playing = with_docstring(NowPlayingLastFM(), '')
Esempio n. 5
0
        except OSError:
            return None

    def render(self, update_value, only_ruby=True, **kwargs):
        ret = [{'contents': update_value,
                'highlight_group': ['ruby_version']}]
        if only_ruby:
            ft = getbufvar('%', '&ft')
            if not ft.find('ruby') >= 0:
                ret = None
        return ret


rvm_current = with_docstring(RVMSegment(),
                             '''Return the rvm current ruby name.

Highlight groups used: ``ruby_version``.
''')


class RbEnvSegment(RVMSegment):

    def update(self, old_rbenv_version):
        try:
            p = Popen(['rbenv', 'version'],
                      shell=False, stdout=PIPE, stderr=PIPE)
            p.stderr.close()
            return p.stdout.read().split()[0]
        except OSError:
            return None
Esempio n. 6
0
				'draw_soft_divider': False,
				'highlight_group': ['battery_gradient', 'battery'],
				'gradient_level': 1,
				})

			return ret
		else:
			return [{
				'contents': key.format.format(**battery),
				'highlight_group': ['battery_gradient', 'battery'],
				'draw_divider': True,
				'divider_highlight_group': 'background:divider',
				'gradient_level': 100 - battery['percent'],
				}]

host_battery = with_docstring(HostBattery(), '')

_LastMessageKey = namedtuple('Key', 'time_format max_length')

class LastMessage(KwThreadedSegment):
	interval = 3

	@staticmethod
	def key(time_format='%Y-%m-%d %H:%M%S', max_length=30, **kwargs):
		return _LastMessageKey(time_format, max_length)

	def compute_state(self, key):
		#raw_res = urllib_read('http://127.0.0.1:18080')
		raw_res = urllib_read('http://172.23.90.57:18080')

		if not raw_res:
            'title': title,
            'playing': status,
        }

    def shorten_artist(self, artist):
        r = re.compile(
            r'''
			(.+?)
			\s*
			(?:
				feat(?:uring)?\.?
				|
				Ft\.
				|
				pres(?:sents)?\.?
			)\b
			''', re.I | re.X)
        m = r.match(artist)
        if m:
            artist = m.group(1)
        return artist

    def shorten_title(self, title):
        m = re.match(r'(.+?)\s*\(.*\)', title)
        if m:
            title = m.group(1)
        return title


now_playing = with_docstring(NowPlayingLastFM(), '')
Esempio n. 8
0
_IMAPKey = namedtuple('Key', 'username password server port folder')
class SecureEmailIMAPSegment(EmailIMAPSegment):
	@staticmethod
	def key(server='imap.gmail.com', port=993, folder='INBOX', **kwargs):
		username = os.getenv("PL_EMAIL_SEGMENT_USERNAME", '')
		password = os.getenv("PL_EMAIL_SEGMENT_PASSWORD", '')

		return _IMAPKey(username, password, server, port, folder)

secure_email_imap_alert = with_docstring(SecureEmailIMAPSegment(),
'''Return unread e-mail count for IMAP servers.

:param str username:
	login username (defaults to $PL_EMAIL_SEGMENT_USERNAME)
:param str password:
	login password (defaults to $PL_EMAIL_SEGMENT_PASSWORD)
:param str server:
	e-mail server
:param int port:
	e-mail server port
:param str folder:
	folder to check for e-mails
:param int max_msgs:
	Maximum number of messages. If there are more messages then max_msgs then it
	will use gradient level equal to 100, otherwise gradient level is equal to
	``100 * msgs_num / max_msgs``. If not present gradient is not computed.

Highlight groups used: ``email_alert_gradient`` (gradient), ``email_alert``.
''')

#!/usr/bin/env python
try:
    import apt
except ImportError:
    pass

from powerline.lib.threaded import ThreadedSegment, with_docstring


class AptUpgradesSegment(ThreadedSegment):
    interval = 300

    def update(self, oldthing):
        upgrades = 0
        for pkg in apt.Cache():
            if pkg.is_upgradable:
                upgrades += 1
        return upgrades
    def render(self, upgrades, **kwargs):
        if upgrades > 0:
            return [{
                "contents": "%i packages can be upgraded" % upgrades,
                "highlight_groups": ["packages:upgrades", "packages"]
                }]
        else:
            return None

AptUpgrades = with_docstring(AptUpgradesSegment(),
    """Displays the number of upgradable packages""")
Esempio n. 10
0
                'highlight_group': ['battery_gradient', 'battery'],
                'gradient_level': 1,
            })

            return ret
        else:
            return [{
                'contents': key.format.format(**battery),
                'highlight_group': ['battery_gradient', 'battery'],
                'draw_divider': True,
                'divider_highlight_group': 'background:divider',
                'gradient_level': 100 - battery['percent'],
            }]


host_battery = with_docstring(HostBattery(), '')

_LastMessageKey = namedtuple('Key', 'time_format max_length')


class LastMessage(KwThreadedSegment):
    interval = 3

    @staticmethod
    def key(time_format='%Y-%m-%d %H:%M%S', max_length=30, **kwargs):
        return _LastMessageKey(time_format, max_length)

    def compute_state(self, key):
        #raw_res = urllib_read('http://127.0.0.1:18080')
        raw_res = urllib_read('http://172.23.90.57:18080')
Esempio n. 11
0
			else:
				r = self.process_repo(repo)
				self.directories[repo.directory] = r
				return r


@requires_segment_info
class RepositoryStatusSegment(RepositorySegment):
	interval = 2

	@staticmethod
	def process_repo(repo):
		return repo.status()


repository_status = with_docstring(RepositoryStatusSegment(),
'''Return the status for the current repo.''')


@requires_segment_info
class BranchSegment(RepositorySegment):
	interval = 0.2
	started_repository_status = False

	@staticmethod
	def process_repo(repo):
		return repo.branch()

	def render_one(self, branch, segment_info, status_colors=False, **kwargs):
		if not branch:
			return None
Esempio n. 12
0
        ret.append({
            'contents': cpu_glyph + ' ',
            'draw_soft_divider': False,
            'divider_highlight_group': 'background:divider',
            'highlight_group': ['cpu_load'],
            'gradient_level': 30,
        })
        ret.append({
            'contents': circle_glyph * numer,
            'draw_soft_divider': False,
            'highlight_group': ['cpu_load'],
            'gradient_level': 99,
        })
        ret.append({
            'contents': circle_glyph * (denom - numer),
            'draw_soft_divider': False,
            'highlight_group': ['cpu_load'],
            'gradient_level': 1,
        })
        ret.append({
            'contents': ' ' + format.format(cpu_percent),
            'draw_soft_divider': True,
            'highlight_group': ['cpu_load'],
            'gradient_level': 1,
        })

        return ret


cpu_load = with_docstring(CPULoad(), '')
Esempio n. 13
0
        except OSError:
            return None

    def render(self, update_value, only_ruby=True, **kwargs):
        ret = [{'contents': update_value,
                'highlight_group': ['ruby_version']}]
        if only_ruby:
            ft = getbufvar('%', '&ft')
            if not ft.find('ruby') >= 0:
                ret = None
        return ret


rvm_current = with_docstring(RVMSegment(),
                             '''Return the rvm current ruby name.

Highlight groups used: ``ruby_version``.
''')


class RbEnvSegment(RVMSegment):

    def update(self, old_rbenv_version):
        try:
            p = Popen(['rbenv', 'version'],
                      shell=False, stdout=PIPE, stderr=PIPE)
            p.stderr.close()
            return p.stdout.read().split()[0]
        except OSError:
            return None
Esempio n. 14
0
				r'\s+((\d+:\d+)? remaining|\(no estimate\))', re.S)
		m = r.search(pmset_output)

		if m == None: return

		if m.lastindex == 3 : remain = ''
		else                : remain = key.remain.format(m.group(5))

		if   m.group(3) == 'charging'    : status = key.charging
		elif m.group(3) == 'discharging' : status = key.discharging
		elif m.group(3) == 'charged'     : status = key.charged; remain = ''

		battery = {
				'percent': int(m.group(2)),
				'status': status,
				'remain': remain,
				}

		return battery

	def render_one(self, battery, format='{percent}%', **kwargs):
		return [{
			'contents': format.format(**battery),
			'highlight_group': ['battery_percent_gradient', 'battery_percent'],
			'draw_divider': True,
			'divider_highlight_group': 'background:divider',
			'gradient_level': 100 - battery['percent'],
			}]

battery_percent = with_docstring(BatteryPercent(), '')
Esempio n. 15
0
        if m.group(3) == 'charging': status = key.charging
        elif m.group(3) == 'discharging': status = key.discharging
        elif m.group(3) == 'charged':
            status = key.charged
            remain = ''

        battery = {
            'percent': int(m.group(2)),
            'status': status,
            'remain': remain,
        }

        return battery

    def render_one(self, battery, format='{percent}%', **kwargs):
        return [{
            'contents':
            format.format(**battery),
            'highlight_group': ['battery_percent_gradient', 'battery_percent'],
            'draw_divider':
            True,
            'divider_highlight_group':
            'background:divider',
            'gradient_level':
            100 - battery['percent'],
        }]


battery_percent = with_docstring(BatteryPercent(), '')