Skip to content
This repository has been archived by the owner on Oct 5, 2020. It is now read-only.

Commit

Permalink
print progress when scanning
Browse files Browse the repository at this point in the history
  • Loading branch information
cfbao committed Jul 3, 2017
1 parent 8406090 commit 7854553
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions cleaner.py
Original file line number Diff line number Diff line change
Expand Up @@ -204,6 +204,7 @@ def get_deletion_list(service, pageToken, maxTrashDays, timeout):
pageToken = 1
pageTokenBefore = pageToken
pageSize = PAGE_SIZE_LARGE
progress = ScanProgress()
while pageToken:
if latestPageToken - int(pageToken) < PAGE_SIZE_SWITCH_THRESHOLD:
pageSize = PAGE_SIZE_SMALL
Expand All @@ -218,13 +219,16 @@ def get_deletion_list(service, pageToken, maxTrashDays, timeout):
for item in items:
itemTime = parse_time(item['time'])
if currentTime - itemTime < maxTrashDays*24*3600:
progress.clear_line()
return deletionList, pageTokenBefore, pageToken
progress.print(item['time'])
if item['file']['explicitlyTrashed']:
deletionList.append({'fileId': item['fileId'], 'time': item['time'],
'name': item['file']['name']})
pageToken = response.get('nextPageToken')
if not deletionList:
pageTokenBefore = pageToken
progress.clear_line()
return deletionList, pageTokenBefore, int(response.get('newStartPageToken'))

def delete_old_files(service, deletionList, flags):
Expand Down Expand Up @@ -265,6 +269,21 @@ def delete_old_files(service, deletionList, flags):
print('Files successfully deleted')
return True

class ScanProgress:
def __init__(self):
self.printed = "0000-00-00"

def print(self, timeStr):
"""print yyyy-mm-dd only if not yet printed"""
ymd = timeStr[:10]
if ymd > self.printed:
print('\rScanning files trashed on ' + ymd, end='')
self.printed = ymd

def clear_line(self):
if self.printed > '0000-00-00':
print('\r' + ''.ljust(40) + '\r', end='')

def execute_request(request, timeout=TIMEOUT_DEFAULT):
"""Execute Google API request
Automatic retry upon Google backend error (500) until timeout
Expand Down

0 comments on commit 7854553

Please sign in to comment.