mirror of
https://github.com/GAM-team/GAM.git
synced 2026-07-04 04:41:35 +00:00
Fix customer/user report
This commit is contained in:
@@ -5,7 +5,7 @@ default_language_version:
|
|||||||
|
|
||||||
repos:
|
repos:
|
||||||
- repo: https://github.com/pre-commit/pre-commit-hooks
|
- repo: https://github.com/pre-commit/pre-commit-hooks
|
||||||
rev: v2.4.0
|
rev: v2.5.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: trailing-whitespace
|
- id: trailing-whitespace
|
||||||
- id: end-of-file-fixer
|
- id: end-of-file-fixer
|
||||||
@@ -17,13 +17,13 @@ repos:
|
|||||||
- id: check-merge-conflict
|
- id: check-merge-conflict
|
||||||
|
|
||||||
- repo: https://github.com/pre-commit/mirrors-yapf
|
- repo: https://github.com/pre-commit/mirrors-yapf
|
||||||
rev: v0.29.0
|
rev: v0.30.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: yapf
|
- id: yapf
|
||||||
args: [--style=google, --in-place]
|
args: [--style=google, --in-place]
|
||||||
|
|
||||||
- repo: https://github.com/PyCQA/pylint
|
- repo: https://github.com/PyCQA/pylint
|
||||||
rev: pylint-2.4.4
|
rev: pylint-2.5.0
|
||||||
hooks:
|
hooks:
|
||||||
- id: pylint
|
- id: pylint
|
||||||
args: [--output-format=colorized]
|
args: [--output-format=colorized]
|
||||||
|
|||||||
@@ -306,7 +306,9 @@ def showReport():
|
|||||||
elif myarg == 'fulldatarequired':
|
elif myarg == 'fulldatarequired':
|
||||||
fullDataRequired = []
|
fullDataRequired = []
|
||||||
fdr = sys.argv[i + 1].lower()
|
fdr = sys.argv[i + 1].lower()
|
||||||
if fdr and fdr != 'all':
|
if fdr and fdr == 'all':
|
||||||
|
fullDataRequired = 'all'
|
||||||
|
else:
|
||||||
fullDataRequired = fdr.replace(',', ' ').split()
|
fullDataRequired = fdr.replace(',', ' ').split()
|
||||||
i += 2
|
i += 2
|
||||||
elif myarg == 'start':
|
elif myarg == 'start':
|
||||||
@@ -338,23 +340,24 @@ def showReport():
|
|||||||
if report == 'user':
|
if report == 'user':
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if fullDataRequired is not None:
|
one_page = gapi.call(rep.userUsageReport(),
|
||||||
warnings = gapi.get_items(rep.userUsageReport(),
|
'get',
|
||||||
'get',
|
throw_reasons=throw_reasons,
|
||||||
'warnings',
|
date=tryDate,
|
||||||
throw_reasons=throw_reasons,
|
userKey=userKey,
|
||||||
date=tryDate,
|
customerId=customerId,
|
||||||
userKey=userKey,
|
orgUnitID=orgUnitId,
|
||||||
customerId=customerId,
|
fields='warnings,usageReports',
|
||||||
orgUnitID=orgUnitId,
|
maxResults=1)
|
||||||
fields='warnings')
|
warnings = one_page.get('warnings', [])
|
||||||
fullData, tryDate = _check_full_data_available(
|
has_reports = bool(one_page.get('usageReports'))
|
||||||
warnings, tryDate, fullDataRequired)
|
fullData, tryDate = _check_full_data_available(
|
||||||
if fullData < 0:
|
warnings, tryDate, fullDataRequired, has_reports)
|
||||||
print('No user report available.')
|
if fullData < 0:
|
||||||
sys.exit(1)
|
print('No user report available.')
|
||||||
if fullData == 0:
|
sys.exit(1)
|
||||||
continue
|
if fullData == 0:
|
||||||
|
continue
|
||||||
page_message = gapi.got_total_items_msg('Users', '...\n')
|
page_message = gapi.got_total_items_msg('Users', '...\n')
|
||||||
usage = gapi.get_all_pages(rep.userUsageReport(),
|
usage = gapi.get_all_pages(rep.userUsageReport(),
|
||||||
'get',
|
'get',
|
||||||
@@ -397,21 +400,21 @@ def showReport():
|
|||||||
elif report == 'customer':
|
elif report == 'customer':
|
||||||
while True:
|
while True:
|
||||||
try:
|
try:
|
||||||
if fullDataRequired is not None:
|
first_page = gapi.call(rep.customerUsageReports(),
|
||||||
warnings = gapi.get_items(rep.customerUsageReports(),
|
'get',
|
||||||
'get',
|
throw_reasons=throw_reasons,
|
||||||
'warnings',
|
customerId=customerId,
|
||||||
throw_reasons=throw_reasons,
|
date=tryDate,
|
||||||
customerId=customerId,
|
fields='warnings,usageReports')
|
||||||
date=tryDate,
|
warnings = first_page.get('warnings', [])
|
||||||
fields='warnings')
|
has_reports = bool(first_page.get('usageReports'))
|
||||||
fullData, tryDate = _check_full_data_available(
|
fullData, tryDate = _check_full_data_available(
|
||||||
warnings, tryDate, fullDataRequired)
|
warnings, tryDate, fullDataRequired, has_reports)
|
||||||
if fullData < 0:
|
if fullData < 0:
|
||||||
print('No customer report available.')
|
print('No customer report available.')
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
if fullData == 0:
|
if fullData == 0:
|
||||||
continue
|
continue
|
||||||
usage = gapi.get_all_pages(rep.customerUsageReports(),
|
usage = gapi.get_all_pages(rep.customerUsageReports(),
|
||||||
'get',
|
'get',
|
||||||
'usageReports',
|
'usageReports',
|
||||||
@@ -558,16 +561,21 @@ def _adjust_date(errMsg):
|
|||||||
return str(match_date.group(1))
|
return str(match_date.group(1))
|
||||||
|
|
||||||
|
|
||||||
def _check_full_data_available(warnings, tryDate, fullDataRequired):
|
def _check_full_data_available(warnings, tryDate, fullDataRequired,
|
||||||
|
has_reports):
|
||||||
one_day = datetime.timedelta(days=1)
|
one_day = datetime.timedelta(days=1)
|
||||||
|
tryDateTime = datetime.datetime.strptime(tryDate, YYYYMMDD_FORMAT)
|
||||||
|
# move to day before if we don't have at least one usageReport
|
||||||
|
if not has_reports:
|
||||||
|
tryDateTime -= one_day
|
||||||
|
return (0, tryDateTime.strftime(YYYYMMDD_FORMAT))
|
||||||
for warning in warnings:
|
for warning in warnings:
|
||||||
if warning['code'] == 'PARTIAL_DATA_AVAILABLE':
|
if warning['code'] == 'PARTIAL_DATA_AVAILABLE':
|
||||||
for app in warning['data']:
|
for app in warning['data']:
|
||||||
if app['key'] == 'application' and \
|
if app['key'] == 'application' and \
|
||||||
app['value'] != 'docs' and \
|
app['value'] != 'docs' and \
|
||||||
(not fullDataRequired or app['value'] in fullDataRequired):
|
fullDataRequired is not None and \
|
||||||
tryDateTime = datetime.datetime.strptime(
|
(fullDataRequired == 'all' or app['value'] in fullDataRequired):
|
||||||
tryDate, YYYYMMDD_FORMAT)
|
|
||||||
tryDateTime -= one_day
|
tryDateTime -= one_day
|
||||||
return (0, tryDateTime.strftime(YYYYMMDD_FORMAT))
|
return (0, tryDateTime.strftime(YYYYMMDD_FORMAT))
|
||||||
elif warning['code'] == 'DATA_NOT_AVAILABLE':
|
elif warning['code'] == 'DATA_NOT_AVAILABLE':
|
||||||
|
|||||||
Reference in New Issue
Block a user