move main code to a function

master
neingeist 6 years ago
parent 8a2203ade7
commit 69f8a6470b

@ -37,37 +37,43 @@ def folder_id(folder_name):
return file1['id'] return file1['id']
read_seen() def main():
global seen, drive
gauth = GoogleAuth(settings_file=os.path.expanduser('~/.config/drive-download/settings.yaml'))
gauth.CommandLineAuth() read_seen()
drive = GoogleDrive(gauth)
gauth = GoogleAuth(settings_file=os.path.expanduser('~/.config/drive-download/settings.yaml'))
file_query = "'%s' in parents and trashed=false" % folder_id(FOLDER) gauth.CommandLineAuth()
file_list = drive.ListFile({'q': file_query}).GetList() drive = GoogleDrive(gauth)
file_names = [f['title'] for f in file_list] file_query = "'%s' in parents and trashed=false" % folder_id(FOLDER)
file_names_dupes = [f for f, count in collections.Counter(file_names).items() if count > 1] file_list = drive.ListFile({'q': file_query}).GetList()
if len(file_names_dupes) > 0:
print('Duplicate filenames on Drive!') file_names = [f['title'] for f in file_list]
for fn in sorted(file_names_dupes): file_names_dupes = [f for f, count in collections.Counter(file_names).items() if count > 1]
print(fn) if len(file_names_dupes) > 0:
sys.exit(1) print('Duplicate filenames on Drive!')
for fn in sorted(file_names_dupes):
for file1 in file_list: print(shlex.quote(fn))
if file1['mimeType'] == 'application/vnd.google-apps.folder': sys.exit(1)
continue
if file1['id'] in seen: # XXX could update the file if it needs updating for file1 in file_list:
continue if file1['mimeType'] == 'application/vnd.google-apps.folder':
continue
local_filename = file1['title'] if file1['id'] in seen: # XXX could update the file if it needs updating
print(shlex.quote(local_filename)) continue
if not os.path.exists(local_filename):
file1.GetContentFile(local_filename) local_filename = file1['title']
seen.add(file1['id']) print(shlex.quote(local_filename))
save_seen() if not os.path.exists(local_filename):
else: file1.GetContentFile(local_filename)
print("{} exists locally!".format(shlex.quote(local_filename))) seen.add(file1['id'])
sys.exit(2) save_seen()
else:
print("{} exists locally!".format(shlex.quote(local_filename)))
sys.exit(2)
main()
# vim:tw=100: # vim:tw=100:

Loading…
Cancel
Save