move main code to a function

master
neingeist 6 years ago
parent 8a2203ade7
commit 69f8a6470b

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

Loading…
Cancel
Save