From 2c049dc38e6e9f34c7139d14b57b126a0734c61a Mon Sep 17 00:00:00 2001 From: Ross Scroggs Date: Fri, 27 Mar 2020 06:07:44 -0700 Subject: [PATCH] Pylint cleanup, bug fixing (#1134) --- src/display.py | 1 + src/gam.py | 11 +---------- src/gapi/directory/cros.py | 1 - src/gapi/storage.py | 2 +- src/gapi/vault.py | 12 ++++-------- src/utils.py | 18 +++++++++++++++--- 6 files changed, 22 insertions(+), 23 deletions(-) diff --git a/src/display.py b/src/display.py index c5b0e949..a6ffbe2f 100644 --- a/src/display.py +++ b/src/display.py @@ -1,6 +1,7 @@ """Methods related to display of information to the user.""" import csv +import datetime import io import sys import webbrowser diff --git a/src/gam.py b/src/gam.py index f97434f1..83d9e4d0 100755 --- a/src/gam.py +++ b/src/gam.py @@ -228,15 +228,6 @@ def getLabelColor(color): controlflow.expected_argument_exit("label color", ", ".join(LABEL_COLORS), color) controlflow.system_error_exit(2, f'A label color must be # and six hex characters (#012345); got {color}') -def integerLimits(minVal, maxVal, item='integer'): - if (minVal is not None) and (maxVal is not None): - return f'{item} {minVal}<=x<={maxVal}' - if minVal is not None: - return f'{item} x>={minVal}' - if maxVal is not None: - return f'{item} x<={maxVal}' - return f'{item} x' - def getInteger(value, item, minVal=None, maxVal=None): try: number = int(value.strip()) @@ -244,7 +235,7 @@ def getInteger(value, item, minVal=None, maxVal=None): return number except ValueError: pass - controlflow.system_error_exit(2, f'expected {item} in range <{integerLimits(minVal, maxVal)}>, got {value}') + controlflow.system_error_exit(2, f'expected {item} in range <{utils.integerLimits(minVal, maxVal)}>, got {value}') def removeCourseIdScope(courseId): if courseId.startswith('d:'): diff --git a/src/gapi/directory/cros.py b/src/gapi/directory/cros.py index 85caaf2e..9628f968 100644 --- a/src/gapi/directory/cros.py +++ b/src/gapi/directory/cros.py @@ -707,7 +707,6 @@ def doPrintCrosDevices(): tempInfos = cpuStatusReports[i].get('cpuTemperatureInfo', []) for tempInfo in tempInfos: - temperature = tempInfo['temperature'] label = tempInfo["label"].strip() base = 'cpuStatusReports.cpuTemperatureInfo.' nrow[f'{base}{label}'] = tempInfo['temperature'] diff --git a/src/gapi/storage.py b/src/gapi/storage.py index 27219063..546c7958 100644 --- a/src/gapi/storage.py +++ b/src/gapi/storage.py @@ -18,7 +18,7 @@ def build_gapi(): def get_cloud_storage_object(s, bucket, object_, local_file=None, - expectedMd5=None): + expectedMd5=None): if not local_file: local_file = object_ if os.path.exists(local_file): diff --git a/src/gapi/vault.py b/src/gapi/vault.py index 3520f585..d05d6a92 100644 --- a/src/gapi/vault.py +++ b/src/gapi/vault.py @@ -695,13 +695,11 @@ def printExports(): else: controlflow.invalid_argument_exit(myarg, "gam print exports") if not matters: - fields = 'matters(matterId,state),nextPageToken' + fields = 'matters(matterId),nextPageToken' matters_results = gapi.get_all_pages(v.matters( ), 'list', 'matters', view='BASIC', state='OPEN', fields=fields) for matter in matters_results: - matterState = matter['state'] - matterId = matter['matterId'] - matterIds.append(matterId) + matterIds.append(matter['matterId']) else: for matter in matters: matterIds.append(getMatterItem(v, matter)) @@ -736,13 +734,11 @@ def printHolds(): else: controlflow.invalid_argument_exit(myarg, "gam print holds") if not matters: - fields = 'matters(matterId,state),nextPageToken' + fields = 'matters(matterId),nextPageToken' matters_results = gapi.get_all_pages(v.matters( ), 'list', 'matters', view='BASIC', state='OPEN', fields=fields) for matter in matters_results: - matterState = matter['state'] - matterId = matter['matterId'] - matterIds.append(matterId) + matterIds.append(matter['matterId']) else: for matter in matters: matterIds.append(getMatterItem(v, matter)) diff --git a/src/utils.py b/src/utils.py index cd245258..fead8e6a 100644 --- a/src/utils.py +++ b/src/utils.py @@ -1,14 +1,17 @@ import datetime import re import sys +import time from hashlib import md5 from html.entities import name2codepoint from html.parser import HTMLParser import json +import dateutil.parser -from var import * +import controlflow import fileutils import transport +from var import * class _DeHTMLParser(HTMLParser): @@ -111,6 +114,15 @@ def formatMilliSeconds(millis): hours, minutes = divmod(minutes, 60) return f'{hours:02d}:{minutes:02d}:{seconds:02d}' +def integerLimits(minVal, maxVal, item='integer'): + if (minVal is not None) and (maxVal is not None): + return f'{item} {minVal}<=x<={maxVal}' + if minVal is not None: + return f'{item} x>={minVal}' + if maxVal is not None: + return f'{item} x<={maxVal}' + return f'{item} x' + def get_string(i, item, optional=False, minLen=1, maxLen=None): if i < len(sys.argv): argstr = sys.argv[i] @@ -163,7 +175,7 @@ def get_yyyymmdd(argstr, minLen=1, returnTimeStamp=False, returnDateTime=False): if argstr: if argstr[0] in ['+', '-']: today = datetime.date.today() - argstr = (datetime.datetime(today.year, today.month, today.day)+getDeltaDate(argstr)).strftime(YYYYMMDD_FORMAT) + argstr = (datetime.datetime(today.year, today.month, today.day)+get_delta_date(argstr)).strftime(YYYYMMDD_FORMAT) try: dateTime = datetime.datetime.strptime(argstr, YYYYMMDD_FORMAT) if returnTimeStamp: @@ -256,7 +268,7 @@ def md5_matches_file(local_file, expected_md5, exitOnError): URL_SHORTENER_ENDPOINT = 'https://gam-shortn.appspot.com/create' -def shorten_url(long_url, httpc=None): +def shorten_url(long_url, httpc=None): if not httpc: httpc = transport.create_http(timeout=10) headers = {'Content-Type': 'application/json', 'User-Agent': GAM_INFO}