[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]
[tor-commits] [gettor/master] Minor changes to drive script
commit 4ed9de8fe5760a60e04298d86bc05780ea7378eb
Author: ilv <ilv@xxxxxxxxxxxxxxxxxxxxxxxx>
Date: Mon Aug 3 15:07:34 2015 -0300
Minor changes to drive script
---
upload/bundles2drive.py | 108 ++++++++++++++++++++++++++++-------------------
1 file changed, 65 insertions(+), 43 deletions(-)
diff --git a/upload/bundles2drive.py b/upload/bundles2drive.py
index 8c329bf..9612382 100644
--- a/upload/bundles2drive.py
+++ b/upload/bundles2drive.py
@@ -16,10 +16,11 @@ import re
import os
import gnupg
import hashlib
+import logging
import ConfigParser
import gettor.core
-#import google drive libs
+# import google drive libs
import httplib2
from apiclient.discovery import build
from apiclient.http import MediaFileUpload
@@ -51,7 +52,7 @@ def valid_format(file, osys):
file)
elif(osys == 'osx'):
m = re.search(
- 'TorBrowser-\d\.\d\.\d-osx\d\d_(\w\w)(-\w\w)?\.dmg',
+ 'TorBrowser-\d\.\d\.\d-osx\d\d_(\w\w)(-\w\w)?\.dmg',
file)
if m:
return True
@@ -143,21 +144,21 @@ def upload_files(client, basedir):
for name in os.listdir(basedir):
path = os.path.abspath(os.path.join(basedir, name))
if os.path.isfile(path) and p.match(path)\
- and valid_format(name, 'linux'):
+ and valid_format(name, 'linux'):
files.append(name)
p = re.compile('.*\.exe$')
for name in os.listdir(basedir):
path = os.path.abspath(os.path.join(basedir, name))
if os.path.isfile(path) and p.match(path)\
- and valid_format(name, 'windows'):
+ and valid_format(name, 'windows'):
files.append(name)
p = re.compile('.*\.dmg$')
for name in os.listdir(basedir):
path = os.path.abspath(os.path.join(basedir, name))
if os.path.isfile(path) and p.match(path)\
- and valid_format(name, 'osx'):
+ and valid_format(name, 'osx'):
files.append(name)
# dictionary to store file names and IDs
@@ -173,33 +174,44 @@ def upload_files(client, basedir):
continue
# upload tor browser installer
- file_body = MediaFileUpload(abs_file, resumable=True)
+ file_body = MediaFileUpload(
+ abs_file,
+ mimetype="application/octet-stream",
+ resumable=True
+ )
body = {
- 'title': file
+ 'title': file
}
print "Uploading '%s'..." % file
try:
- file_data = drive_service.files().insert(body=body, media_body=file_body).execute()
+ file_data = drive_service.files().insert(
+ body=body,
+ media_body=file_body
+ ).execute()
except errors.HttpError, e:
print str(e)
# upload signature
asc_body = MediaFileUpload(abs_asc, resumable=True)
asc_head = {
- 'title': "%s.asc" % file
+ 'title': "%s.asc" % file
}
print "Uploading '%s'..." % asc
try:
- asc_data = drive_service.files().insert(body=asc_head, media_body=asc_body).execute()
+ asc_data = drive_service.files().insert(
+ body=asc_head,
+ media_body=asc_body
+ ).execute()
except errors.HttpError, e:
print str(e)
# add filenames and file id to dict
files_dict[file] = file_data['id']
- files_dict[asc] = asc_data['id']
+ files_dict[asc] = asc_data['id']
return files_dict
+
def share_file(service, file_id):
"""Make files public
@@ -207,26 +219,28 @@ def share_file(service, file_id):
link to file.
:param: file_id (string)
-
+
:return: (string) url to shared file
-
+
"""
permission = {
- 'type': "anyone",
- 'role': "reader",
- 'withLink': True
+ 'type': "anyone",
+ 'role': "reader",
+ 'withLink': True
}
-
+
try:
service.permissions().insert(
- fileId=file_id, body=permission).execute()
+ fileId=file_id,
+ body=permission
+ ).execute()
except errors.HttpError, error:
- print('An error occured while sharing: %s' % file_id)
+ print('An error occured while sharing: %s' % file_id)
try:
file = service.files().get(fileId=file_id).execute()
except errors.HttpError, error:
- print('Error occured while fetch public link for file: %s' % file_id)
+ print('Error occured while fetch public link for file: %s' % file_id)
print("Uploaded to %s" % file['webContentLink'])
return file['webContentLink']
@@ -250,29 +264,33 @@ if __name__ == '__main__':
print "Authenticating..."
- flow = OAuth2WebServerFlow(client_id, app_secret, OAUTH_SCOPE,
- redirect_uri=REDIRECT_URI)
+ flow = OAuth2WebServerFlow(
+ client_id,
+ app_secret,
+ OAUTH_SCOPE,
+ redirect_uri=REDIRECT_URI
+ )
# If no valid token found, need to prompt user.
# this should only occur once
if not refresh_token:
- flow.params['access_type'] = 'offline'
- flow.params['approval_prompt'] = 'force'
- authorize_url = flow.step1_get_authorize_url()
- print 'Go to the following link in your browser: ' + authorize_url
- code = raw_input('Enter verification code: ').strip()
- try:
- credentials = flow.step2_exchange(code)
- except FlowExchangeError as e:
- print str(e)
-
- # oauth2 credentials instance must be stored as json string
- config.set('app', 'refresh_token', credentials.to_json())
- with open('drive.cfg', 'wb') as configfile:
+ flow.params['access_type'] = 'offline'
+ flow.params['approval_prompt'] = 'force'
+ authorize_url = flow.step1_get_authorize_url()
+ print 'Go to the following link in your browser: ' + authorize_url
+ code = raw_input('Enter verification code: ').strip()
+ try:
+ credentials = flow.step2_exchange(code)
+ except FlowExchangeError as e:
+ print str(e)
+
+ # oauth2 credentials instance must be stored as json string
+ config.set('app', 'refresh_token', credentials.to_json())
+ with open('drive.cfg', 'wb') as configfile:
config.write(configfile)
else:
- # we already have a valid token
- credentials = Credentials.new_from_json(refresh_token)
+ # we already have a valid token
+ credentials = Credentials.new_from_json(refresh_token)
# authenticate with oauth2
http = httplib2.Http()
@@ -281,7 +299,6 @@ if __name__ == '__main__':
# initialize drive instance
drive_service = build('drive', 'v2', http=http)
-
# import key fingerprint
gpg = gnupg.GPG()
key_data = open(tbb_key).read()
@@ -309,7 +326,7 @@ if __name__ == '__main__':
for file in uploaded_files.keys():
# only run for tor browser installers
if p4.match(file):
- continue
+ continue
asc = "%s.asc" % file
abs_file = os.path.abspath(os.path.join(upload_dir, file))
abs_asc = os.path.abspath(os.path.join(upload_dir, asc))
@@ -317,10 +334,15 @@ if __name__ == '__main__':
sha_file = get_file_sha256(abs_file)
# build links
- link_file = share_file(drive_service,
- uploaded_files[file])
- link_asc = share_file(drive_service,
- uploaded_files["%s.asc" % file])
+ link_file = share_file(
+ drive_service,
+ uploaded_files[file]
+ )
+
+ link_asc = share_file(
+ drive_service,
+ uploaded_files["%s.asc" % file]
+ )
if p1.match(file):
osys, arch, lc = get_bundle_info(file, 'linux')
_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits