mirror of
https://github.com/GAM-team/GAM.git
synced 2026-06-28 09:51:36 +00:00
Pylint cleanup, bug fixing (#1134)
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
"""Methods related to display of information to the user."""
|
||||
|
||||
import csv
|
||||
import datetime
|
||||
import io
|
||||
import sys
|
||||
import webbrowser
|
||||
|
||||
11
src/gam.py
11
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:'):
|
||||
|
||||
@@ -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']
|
||||
|
||||
@@ -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):
|
||||
|
||||
@@ -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))
|
||||
|
||||
18
src/utils.py
18
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}
|
||||
|
||||
Reference in New Issue
Block a user