コード例 #1
0
ファイル: common.py プロジェクト: DaneelOliwan/dotfiles-vim
				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,
コード例 #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
コード例 #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``.
''')
コード例 #4
0
ファイル: nowplayinglastfm.py プロジェクト: cmcdade/dotfiles
		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(), '')
コード例 #5
0
ファイル: segments.py プロジェクト: jdonaldson/linepower.vim
        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
コード例 #6
0
ファイル: host_info.py プロジェクト: delphinus35/dotfiles
				'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:
コード例 #7
0
            '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(), '')
コード例 #8
0
ファイル: email.py プロジェクト: danieltdt/dotfiles
_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``.
''')

コード例 #9
0
#!/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""")
コード例 #10
0
ファイル: host_info.py プロジェクト: sgoranson/dotfiles-2
                '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')
コード例 #11
0
ファイル: vim.py プロジェクト: BenTobias/vim-bash-files
			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
コード例 #12
0
ファイル: ps.py プロジェクト: ikhoon/powerline-config
        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(), '')
コード例 #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
コード例 #14
0
ファイル: battery.py プロジェクト: cmcdade/dotfiles
				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(), '')
コード例 #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(), '')