Skip to content

Commit

Permalink
And even more linting...
Browse files Browse the repository at this point in the history
  • Loading branch information
karasu committed May 1, 2018
1 parent efcba86 commit b3c2724
Show file tree
Hide file tree
Showing 14 changed files with 237 additions and 225 deletions.
2 changes: 1 addition & 1 deletion src/info.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@

""" Set some Cnchi global constants """

CNCHI_VERSION = "0.14.434"
CNCHI_VERSION = "0.14.435"
CNCHI_WEBSITE = "http://www.antergos.com"
CNCHI_RELEASE_STAGE = "production"

Expand Down
34 changes: 17 additions & 17 deletions src/misc/tz.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand All @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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 """
Expand Down Expand Up @@ -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):
Expand Down
5 changes: 4 additions & 1 deletion src/misc/validation.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@
""" Validation module """

if __debug__:
def _(x): return x
def _(message):
return message


def check_grub_device(device):
Expand Down Expand Up @@ -102,6 +103,7 @@ def check_hostname(name):


def password_strength(password):
""" Checks password strength """
upper = lower = digit = symbol = 0
for char in password:
if char.isdigit():
Expand Down Expand Up @@ -133,6 +135,7 @@ def password_strength(password):


def human_password_strength(password):
""" Converts password strength to a human message """
strength = password_strength(password)
length = len(password)
if length == 0:
Expand Down
2 changes: 1 addition & 1 deletion src/pacman/alpm_events.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
#
# alpm_events.py
#
# Copyright © 2013-2017 Antergos
# Copyright © 2013-2018 Antergos
#
# This file is part of Cnchi.
#
Expand Down
31 changes: 16 additions & 15 deletions src/pacman/pac.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down Expand Up @@ -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
Expand All @@ -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"

Expand Down Expand Up @@ -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

Expand All @@ -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]

Expand Down Expand Up @@ -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

Expand All @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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:
Expand Down Expand Up @@ -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):
Expand Down
8 changes: 4 additions & 4 deletions src/pacman/pacman_conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
#
Expand Down Expand Up @@ -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
Expand Down
26 changes: 17 additions & 9 deletions src/pacman/pkginfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)
Expand All @@ -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'):
Expand Down Expand Up @@ -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)
Expand All @@ -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')

Expand Down Expand Up @@ -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)
Expand Down
Loading

0 comments on commit b3c2724

Please sign in to comment.