forked from Antergos/Cnchi
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
237 additions
and
225 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
# | ||
# Copyright (C) 2006, 2007 Canonical Ltd. | ||
# Written by Colin Watson <[email protected]>. | ||
# New modifications Copyright © 2013-2017 Antergos | ||
# New modifications Copyright © 2013-2018 Antergos | ||
# | ||
# 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 | ||
|
@@ -46,16 +46,16 @@ def _seconds_since_epoch(my_datetime): | |
class SystemTzInfo(datetime.tzinfo): | ||
""" Class that represents current timezone info """ | ||
|
||
def __init__(self, tz=None): | ||
self.tz = tz | ||
def __init__(self, timezone=None): | ||
self.timezone = timezone | ||
|
||
def _select_tz(self): | ||
""" Select timezone """ | ||
tzbackup = None | ||
if 'TZ' in os.environ: | ||
tzbackup = os.environ['TZ'] | ||
if self.tz is not None: | ||
os.environ['TZ'] = self.tz | ||
if self.timezone is not None: | ||
os.environ['TZ'] = self.timezone | ||
time.tzset() | ||
return tzbackup | ||
|
||
|
@@ -69,15 +69,15 @@ def _restore_tz(tzbackup): | |
os.environ['TZ'] = tzbackup | ||
time.tzset() | ||
|
||
def utcoffset(self, dt): | ||
def utcoffset(self, my_datetime): | ||
""" Get utc offset (taking dst into account) """ | ||
tzbackup = self._select_tz() | ||
try: | ||
if time.daylight == 0: | ||
# no Daylight Saving Time (DST) information | ||
dst_minutes = -time.timezone / 60 | ||
else: | ||
localtime = time.localtime(_seconds_since_epoch(dt)) | ||
localtime = time.localtime(_seconds_since_epoch(my_datetime)) | ||
if localtime.tm_isdst != 1: | ||
# not in DST | ||
dst_minutes = -time.timezone / 60 | ||
|
@@ -95,10 +95,10 @@ def get_daylight(self): | |
self._restore_tz(tzbackup) | ||
return daylight | ||
|
||
def is_dst(self, dt): | ||
def is_dst(self, my_datetime): | ||
""" Are we in DST? """ | ||
tzbackup = self._select_tz() | ||
localtime = time.localtime(_seconds_since_epoch(dt)) | ||
localtime = time.localtime(_seconds_since_epoch(my_datetime)) | ||
isdst = localtime.tm_isdst | ||
self._restore_tz(tzbackup) | ||
return isdst | ||
|
@@ -133,7 +133,7 @@ def dst(self, dt): | |
|
||
def tzname(self, unused_dt): | ||
""" Return timezone """ | ||
return self.tz | ||
return self.timezone | ||
|
||
def tzname_letters(self, my_datetime): | ||
""" Get localtime """ | ||
|
@@ -303,30 +303,30 @@ def __init__(self): | |
else: | ||
self.cc_to_locs[loc.country] = [loc] | ||
|
||
def get_loc(self, tz): | ||
def get_loc(self, timezone): | ||
""" Get timezone's location """ | ||
try: | ||
return self.tz_to_loc[tz] | ||
except: | ||
return self.tz_to_loc[timezone] | ||
except IndexError: | ||
# Sometimes we'll encounter timezones that aren't really | ||
# city-zones, like "US/Eastern" or "Mexico/General". So first, | ||
# we check if the timezone is known. If it isn't, we search for | ||
# one with the same md5sum and make a reference to it | ||
try: | ||
zone_path = os.path.join('/usr/share/zoneinfo', tz) | ||
zone_path = os.path.join('/usr/share/zoneinfo', timezone) | ||
with open(zone_path, 'rb') as tz_file: | ||
md5sum = hashlib.md5(tz_file.read()).digest() | ||
|
||
for loc in self.locations: | ||
if md5sum == loc.md5sum: | ||
self.tz_to_loc[tz] = loc | ||
self.tz_to_loc[timezone] = loc | ||
return loc | ||
except IOError: | ||
pass | ||
|
||
# If not found, oh well, just warn and move on. | ||
logging.error('Could not understand timezone %s', tz) | ||
self.tz_to_loc[tz] = None # save it for the future | ||
logging.error('Could not understand timezone %s', timezone) | ||
self.tz_to_loc[timezone] = None # save it for the future | ||
return None | ||
|
||
def get_locations(self): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
# | ||
# This code is based on previous work by Rémy Oudompheng <[email protected]> | ||
# | ||
# Copyright © 2013-2017 Antergos | ||
# Copyright © 2013-2018 Antergos | ||
# | ||
# This file is part of Cnchi. | ||
# | ||
|
@@ -40,12 +40,6 @@ | |
import traceback | ||
from collections import OrderedDict | ||
|
||
try: | ||
_("x") | ||
except NameError: | ||
import gettext | ||
_ = gettext.gettext | ||
|
||
import pacman.alpm_events as alpm | ||
import pacman.pkginfo as pkginfo | ||
import pacman.pacman_conf as config | ||
|
@@ -57,6 +51,13 @@ | |
# logging.error(err) | ||
pass | ||
|
||
# When testing, no _() is available | ||
try: | ||
_("") | ||
except NameError as err: | ||
def _(message): | ||
return message | ||
|
||
_DEFAULT_ROOT_DIR = "/" | ||
_DEFAULT_DB_PATH = "/var/lib/pacman" | ||
|
||
|
@@ -255,7 +256,7 @@ def install(self, pkgs, conflicts=None, options=None): | |
logging.error("alpm is not initialised") | ||
raise pyalpm.error | ||
|
||
if len(pkgs) == 0: | ||
if not pkgs: | ||
logging.error("Package list is empty") | ||
raise pyalpm.error | ||
|
||
|
@@ -267,7 +268,7 @@ def install(self, pkgs, conflicts=None, options=None): | |
repos = OrderedDict() | ||
repo_order = [] | ||
db_match = [db for db in self.handle.get_syncdbs() | ||
if 'antergos' == db.name] | ||
if db.name == 'antergos'] | ||
antdb = OrderedDict() | ||
antdb['antergos'] = db_match[0] | ||
|
||
|
@@ -327,7 +328,7 @@ def install(self, pkgs, conflicts=None, options=None): | |
targets = list(set(targets)) | ||
logging.debug(targets) | ||
|
||
if len(targets) == 0: | ||
if not targets: | ||
logging.error("No targets found") | ||
return False | ||
|
||
|
@@ -344,7 +345,7 @@ def install(self, pkgs, conflicts=None, options=None): | |
logging.error("Can't initialize alpm transaction") | ||
return False | ||
|
||
for i in range(0, num_targets): | ||
for _index in range(0, num_targets): | ||
result_ok, pkg = self.find_sync_package(targets.pop(), repos) | ||
if result_ok: | ||
transaction.add_pkg(pkg) | ||
|
@@ -363,7 +364,7 @@ def upgrade(self, pkgs, conflicts=None, options=None): | |
logging.error("alpm is not initialised") | ||
raise pyalpm.error | ||
|
||
if len(pkgs) == 0: | ||
if not pkgs: | ||
logging.error("Package list is empty") | ||
raise pyalpm.error | ||
|
||
|
@@ -405,7 +406,7 @@ def get_group_pkgs(self, group): | |
for repo in self.handle.get_syncdbs(): | ||
grp = repo.read_grp(group) | ||
if grp is not None: | ||
name, pkgs = grp | ||
_name, pkgs = grp | ||
return pkgs | ||
return None | ||
|
||
|
@@ -414,7 +415,7 @@ def get_packages_info(self, pkg_names=None): | |
if not pkg_names: | ||
pkg_names = [] | ||
packages_info = {} | ||
if len(pkg_names) == 0: | ||
if not pkg_names: | ||
# Store info from all packages from all repos | ||
for repo in self.handle.get_syncdbs(): | ||
for pkg in repo.pkgcache: | ||
|
@@ -541,7 +542,7 @@ def cb_event(self, event_type, event_txt): | |
else: | ||
action = "" | ||
|
||
if len(action) > 0: | ||
if action: | ||
self.queue_event('info', action) | ||
|
||
def cb_log(self, level, line): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
# pacman_conf.py | ||
# | ||
# Based on pyalpm code Copyright (C) 2011 Rémy Oudompheng <[email protected]> | ||
# Copyright © 2013-2017 Antergos | ||
# Copyright © 2013-2018 Antergos | ||
# | ||
# This file is part of Cnchi. | ||
# | ||
|
@@ -93,17 +93,17 @@ def pacman_conf_enumerator(path): | |
filestack = [] | ||
current_section = None | ||
filestack.append(open(path)) | ||
while len(filestack) > 0: | ||
while filestack: | ||
file_obj = filestack[-1] | ||
line = file_obj.readline() | ||
if len(line) == 0: | ||
if not line: | ||
# end of file | ||
file_obj.close() | ||
filestack.pop() | ||
continue | ||
|
||
line = line.strip() | ||
if len(line) == 0: | ||
if not line: | ||
continue | ||
if line[0] == '#': | ||
continue | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,7 +4,7 @@ | |
# pycman.pkginfo - A Python implementation of Pacman | ||
# | ||
# Copyright © 2011 Rémy Oudompheng <[email protected]> | ||
# Copyright © 2013-2017 Antergos | ||
# Copyright © 2013-2018 Antergos | ||
# | ||
# 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 | ||
|
@@ -38,13 +38,20 @@ | |
|
||
import pyalpm | ||
|
||
# When testing, no _() is available | ||
try: | ||
_("") | ||
except NameError as err: | ||
def _(message): | ||
return message | ||
|
||
ATTRNAME_FORMAT = '%-14s : ' | ||
ATTR_INDENT = 17 * ' ' | ||
|
||
|
||
def get_term_size(): | ||
if sys.stdout.isatty(): | ||
height, width = struct.unpack( | ||
_height, width = struct.unpack( | ||
"HH", fcntl.ioctl(1, termios.TIOCGWINSZ, 4 * b"\x00")) | ||
return width | ||
else: | ||
|
@@ -53,7 +60,7 @@ def get_term_size(): | |
|
||
def format_attr(attrname, value, attrformat=None): | ||
if isinstance(value, list): | ||
if len(value) == 0: | ||
if not value: | ||
valuestring = 'None' | ||
else: | ||
valuestring = ' '.join(str(v) for v in value) | ||
|
@@ -72,11 +79,11 @@ def format_attr(attrname, value, attrformat=None): | |
|
||
|
||
def format_attr_oneperline(attrname, value): | ||
if len(value) == 0: | ||
if not value: | ||
value = ['None'] | ||
s = ATTRNAME_FORMAT % attrname | ||
s += ('\n' + ATTR_INDENT).join(value) | ||
return s | ||
my_string = ATTRNAME_FORMAT % attrname | ||
my_string += ('\n' + ATTR_INDENT).join(value) | ||
return my_string | ||
|
||
|
||
def display_pkginfo(pkg, level=1, style='local'): | ||
|
@@ -145,7 +152,7 @@ def display_pkginfo(pkg, level=1, style='local'): | |
if level >= 2 and style == 'local': | ||
# print backup information | ||
print('Backup files:') | ||
if len(pkg.backup) == 0: | ||
if not pkg.backup: | ||
print('(none)') | ||
else: | ||
print('\n'.join(["%s %s" % (md5, filename) | ||
|
@@ -154,6 +161,7 @@ def display_pkginfo(pkg, level=1, style='local'): | |
|
||
|
||
def get_pkginfo(pkg, level=1, style='local'): | ||
""" Stores package info into a dictonary """ | ||
if style not in ['local', 'sync', 'file']: | ||
raise ValueError('Invalid style for package info formatting') | ||
|
||
|
@@ -216,7 +224,7 @@ def get_pkginfo(pkg, level=1, style='local'): | |
info['description'] = pkg.desc | ||
|
||
if level >= 2 and style == 'local': | ||
if len(pkg.backup) == 0: | ||
if not pkg.backup: | ||
info['backup files'] = None | ||
else: | ||
info['backup files'] = [(md5, filename) | ||
|
Oops, something went wrong.