Guest User

Untitled

a guest
May 21st, 2018
56
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.86 KB | None | 0 0
  1. #!/usr/bin/python
  2.  
  3. import sys
  4. import os
  5.  
  6. from optparse import OptionParser
  7. from os.path import expanduser
  8.  
  9. from pydrive.auth import GoogleAuth
  10. from pydrive.drive import GoogleDrive
  11. from pydrive.settings import LoadSettingsFile
  12.  
  13. usage= "usage: %prog [options] FILE"
  14. parser = OptionParser(usage= usage)
  15. parser.add_option("-v", "--verbose", action="store_true", dest="verbose",
  16. help="verbose status messages", default=False)
  17. parser.add_option("-t", "--title", dest="title", metavar="DEST",
  18. help="title", default=False)
  19. parser.add_option("-s", "--subdir", dest="subdir", metavar="DEST",
  20. help="subdir", default=False)
  21. parser.add_option("-d", "--destination", dest="destination", metavar="DEST",
  22. help="destination directory (defaults to 'Dumps')",
  23. default="Dumps")
  24.  
  25. (options, args) = parser.parse_args()
  26.  
  27. home = expanduser("~")
  28. cwd= os.getcwd()
  29.  
  30. home_upload= home + os.sep + ".upload.py" + os.sep
  31.  
  32. if os.path.exists(home_upload):
  33. os.chdir(home_upload)
  34.  
  35. gauth = GoogleAuth()
  36. #gauth.LocalWebserverAuth()
  37. gauth.CommandLineAuth()
  38.  
  39. drive = GoogleDrive(gauth)
  40. os.chdir(cwd)
  41.  
  42. file_list = drive.ListFile({'q': "title='" + options.destination + "'"}).GetList()
  43.  
  44. parent = drive.CreateFile({'id': file_list[0]['id']})
  45. file1 = drive.CreateFile()
  46. if not options.title:
  47. title = args[0].replace(os.sep, '|')
  48. else:
  49. title = options.title
  50. if options.subdir:
  51. subdir = drive.CreateFile({'title': options.subdir, "mimeType": "application/vnd.google-apps.folder"})
  52. subdir['parents']= [parent]
  53. subdir.Upload()
  54. parent = subdir
  55. file1['title']= title
  56. file1['parents']= [parent]
  57. file1.SetContentFile(args[0])
  58.  
  59. if options.verbose:
  60. print "Start upload of " + file1['title'] + " to dir '" + options.destination + ('/' + options.subdir if options.subdir else '') + "'"
  61. file1.Upload()
  62. if options.verbose:
  63. print "Done"
Add Comment
Please, Sign In to add comment