def upload_new_doc(self, path,col,doc_title):
        """Uploads a new document to Google Docs
        
    
        Arguments:
        - `path`:String
        - `Col`:<collection object>
        - `doc_title`:The title of the doc
        """
       

        client=self.__create_client()

        doc = gdata.docs.data.Resource(type='document', title=doc_title)
        media = gdata.data.MediaSource()
        media.SetFileHandle(path, 'application/msword')

        #If a collection has not been defined
        
        if not col:
            
            doc = client.CreateResource(doc,media=media)
            return doc

        doc = client.CreateResource(doc,media=media, create_uri=gdata.docs.client.RESOURCE_UPLOAD_URI+'/'+col.resource_id.text+'/contents')
        
        
        return doc
Ejemplo n.º 2
0
def CreateResourceInCollectionSample():
    """Create a collection, then create a document in it."""
    client = CreateClient()
    col = gdata.docs.data.Resource(type='folder', title='My Sample Folder')
    col = client.CreateResource(col)
    print 'Created collection:', col.title.text, col.resource_id.text
    doc = gdata.docs.data.Resource(type='document', title='My Sample Doc')
    doc = client.CreateResource(doc, collection=col)
    print 'Created:', doc.title.text, doc.resource_id.text
Ejemplo n.º 3
0
def DeleteResourceSample():
    """Delete a resource (after creating it)."""
    client = CreateClient()
    doc = gdata.docs.data.Resource(type='document', title='My Sample Doc')
    doc = client.CreateResource(doc)
    # Delete the resource we just created.
    client.DeleteResource(doc)
Ejemplo n.º 4
0
def AddAclSample():
    """Create a resource and an ACL."""
    client = CreateClient()
    doc = gdata.docs.data.Resource(type='document', title='My Sample Doc')
    doc = client.CreateResource(doc)
    acl_entry = gdata.docs.data.AclEntry(
        scope=gdata.acl.data.AclScope(value='*****@*****.**', type='user'),
        role=gdata.acl.data.AclRole(value='reader'),
    )
    client.AddAclEntry(doc, acl_entry, send_notifications=False)
 def create_collection(self, name):
     """Creates a Collection in Google Docs
 
     Arguments:
     - `name`: name of the collection
     """
     client=self.__create_client()
     col = gdata.docs.data.Resource(type='folder', title=name)
     col= client.CreateResource(col)
     return col
Ejemplo n.º 6
0
def DeleteAclSample():
    """Create an ACL entry, and delete it."""
    client = CreateClient()
    doc = gdata.docs.data.Resource(type='document', title='My Sample Doc')
    doc = client.CreateResource(doc)
    acl_entry = gdata.docs.data.AclEntry(
        scope=gdata.acl.data.AclScope(value='*****@*****.**', type='user'),
        role=gdata.acl.data.AclRole(value='reader'),
    )
    acl_entry = client.AddAclEntry(doc, acl_entry)
    client.DeleteAclEntry(acl_entry)
Ejemplo n.º 7
0
def AddAclSample():
    """Delete a resource (after creating it)."""
    client = CreateClient()
    doc = gdata.docs.data.Resource(type='document', title='My11')
    doc = client.CreateResource(doc)
    acl_entry = gdata.docs.data.AclEntry(
        scope=gdata.acl.data.AclScope(value='*****@*****.**',
                                      type='user'),
        role=gdata.acl.data.AclRole(value='reader'),
    )
    client.AddAclEntry(doc, acl_entry, send_notification=False)
Ejemplo n.º 8
0
def UploadUnconvertedFileSample():
    """Upload a document, unconverted."""
    client = CreateClient()
    doc = gdata.docs.data.Resource(type='document', title='My Sample Raw Doc')
    path = _GetDataFilePath('test.0.doc')
    media = gdata.data.MediaSource()
    media.SetFileHandle(path, 'application/msword')
    # Pass the convert=false parameter
    create_uri = gdata.docs.client.RESOURCE_UPLOAD_URI + '?convert=false'
    doc = client.CreateResource(doc, create_uri=create_uri, media=media)
    print 'Created, and uploaded:', doc.title.text, doc.resource_id.text
Ejemplo n.º 9
0
def UploadResourceSample():
    """Upload a document, and convert to Google Docs."""
    client = CreateClient()
    doc = gdata.docs.data.Resource(type='document', title='My Sample Doc')
    # This is a convenient MS Word doc that we know exists
    path = _GetDataFilePath('test.0.doc')
    print 'Selected file at: %s' % path
    # Create a MediaSource, pointing to the file
    media = gdata.data.MediaSource()
    media.SetFileHandle(path, 'application/msword')
    # Pass the MediaSource when creating the new Resource
    doc = client.CreateResource(doc, media=media)
    print 'Created, and uploaded:', doc.title.text, doc.resource_id.text
Ejemplo n.º 10
0
 def gd_upload(report, title, client, filename='tmp.xls'):
     with open(filename, 'w') as f:
         f.write(report)
     # print vars(gdata.docs)
     newResource = gdata.docs.data.Resource(filename, title)
     media = gdata.data.MediaSource()
     if options.format == 'xls':
         media.SetFileHandle(filename, 'application/vnd.ms-excel')
         # media.SetFileHandle(filename, 'application/vnd.google-apps.spreadsheet')
     elif options.format == 'csv':
         media.SetFileHandle(filename, 'text/csv')
     newDocument = client.CreateResource(newResource, create_uri=gdata.docs.client.RESOURCE_UPLOAD_URI, media=media)
     return newDocument
Ejemplo n.º 11
0
def SyncGnuLinux64(languages):
  for language in languages:
    bundlename = []
    bundlenumber = []
    packagename = 'tor-browser-gnu-linux-x86_64'
    magic = []
    rootdir = './torbrowser/linux/'
    for root, subFolders, files in os.walk(rootdir):
        for file in files:
            check = file.find(language)
            if check !=-1:
                  if file.find('tor-browser-gnu-linux-x86_64') !=-1:
                    splitname = string.split(file, '-dev-')
                    bundlenumber.append(splitname[0][-1])
                    namesplit = string.split(file, '-')
                    vernum = namesplit[5]
                    # check value for archive process
                    runzip = splitname[0][-1]
                    # we use the latest version we find to make our zip file
                    magic.append(namesplit[6])


    manlang = language

    if language == 'en-US':
       manlang = 'en'
    elif language == 'es-ES':
       manlang = 'es'
    elif language == 'zh-CN':
       manlang = 'zh'

    if magic:
     zipfile = packagename + '-' + language + '.zip'
     appfile = packagename + '-' + vernum + '-' + max(magic) + '-dev-' + language + '.tar.gz'
     ascfile = packagename + '-' + vernum + '-' + max(magic) + '-dev-' + language + '.tar.gz.asc'
     manfile = 'short-user-manual_' + manlang + '.xhtml'

     subprocess.call(["7z" ,"a",'zipfiles/linux/' + zipfile,'torbrowser/linux/'+appfile,'torbrowser/linux/'+ascfile, 'manual/'+manfile])
     f = open('./zipfiles/linux/'+zipfile)
     doc = gdata.docs.data.Resource(type='zip', title=zipfile)
     ms = gdata.data.MediaSource(file_handle=f, content_type='application/zip', content_length=os.path.getsize(f.name))
     # Pass the convert=false parameter
     create_uri = gdata.docs.client.RESOURCE_UPLOAD_URI + '?convert=false'
     doc = client.CreateResource(doc, create_uri=create_uri, media=ms)
     print 'Created, and uploaded:', doc.title.text, doc.resource_id.text
     db.execute('INSERT INTO doclist(id, title) VALUES(?,?)', (doc.resource_id.text, doc.title.text))
     db.commit()
Ejemplo n.º 12
0
def AddAclBatchSample():
    """Add a list of ACLs as a batch."""
    client = CreateClient()
    doc = gdata.docs.data.Resource(type='document', title='My Sample Doc')
    doc = client.CreateResource(doc)
    acl1 = gdata.docs.data.AclEntry(
        scope=gdata.acl.data.AclScope(value='*****@*****.**', type='user'),
        role=gdata.acl.data.AclRole(value='reader'),
        batch_operation=gdata.data.BatchOperation(type='insert'),
    )
    acl2 = gdata.docs.data.AclEntry(
        scope=gdata.acl.data.AclScope(value='*****@*****.**', type='user'),
        role=gdata.acl.data.AclRole(value='reader'),
        batch_operation=gdata.data.BatchOperation(type='insert'),
    )
    # Create a list of operations to perform together.
    acl_operations = [acl1, acl2]
    # Perform the operations.
    client.BatchProcessAclEntries(doc, acl_operations)
Ejemplo n.º 13
0
def _upload_file_to_gdrive(file_path,
                           file_name='NAME NOT SET',
                           file_type=CONTENT_TYPE.TSV):
    '''

    :param file_path: Must include dot notation for root directly. For example: './cleanertest1.xlsx'
    :param file_name:
    :return:
    '''
    client = getGDriveClient()
    filePath = file_path
    newResource = gdata.docs.data.Resource(filePath, "%s" % (file_name))
    media = gdata.data.MediaSource()
    media.SetFileHandle(filePath, file_type)
    newDocument = client.CreateResource(
        newResource,
        create_uri=gdata.docs.client.RESOURCE_UPLOAD_URI,
        media=media)
    return newDocument
Ejemplo n.º 14
0
def create_google_spreadsheet(title):
    google_config = get_google_config()
    scope = [
        'https://spreadsheets.google.com/feeds',
        'https://docs.google.com/feeds'
    ]
    credentials = SignedJwtAssertionCredentials(
        google_config['client_email'], google_config['private_key'].encode(),
        scope)
    client = gdata.docs.client.DocsClient(source=google_config['project_id'])
    token = gdata.gauth.OAuth2TokenFromCredentials(credentials)
    token.authorize(client)
    spreadsheet = gdata.docs.data.Resource(gdata.docs.data.SPREADSHEET_LABEL,
                                           title)
    new_spreadsheet = client.CreateResource(spreadsheet)
    acl_entry = gdata.docs.data.AclEntry(
        scope=gdata.acl.data.AclScope(type='default'),
        role=gdata.acl.data.AclWithKey(
            key='with link', role=gdata.acl.data.AclRole(value='writer')))
    client.AddAclEntry(new_spreadsheet, acl_entry)
    return new_spreadsheet.GetAlternateLink().href
Ejemplo n.º 15
0
def CreateEmptyResourceSample():
    """Create an empty resource of type document."""
    client = CreateClient()
    document = gdata.docs.data.Resource(type='document', title='My Sample Doc')
    document = client.CreateResource(document)
    print 'Created:', document.title.text, document.resource_id.text
Ejemplo n.º 16
0

def PrintResource(resource):
  print resource.resource_id.text, resource.GetResourceType()
  

client = CreateClient()


f = open('/home/tor-browser.zip')
doc = gdata.docs.data.Resource(type='zip', title=f.name)
ms = gdata.data.MediaSource(file_handle=f, content_type='application/zip', content_length=os.path.getsize(f.name))

# Pass the convert=false parameter
create_uri = gdata.docs.client.RESOURCE_UPLOAD_URI + '?convert=false'
doc = client.CreateResource(doc, create_uri=create_uri, media=ms)

print 'Created, and uploaded:', doc.title.text, doc.resource_id.text

feed = client.GetResources()
PrintFeed(feed)

# assign 'reader' permission (share document with the given email address)
acl_entry = gdata.docs.data.AclEntry(
    scope=gdata.acl.data.AclScope(value=sys.argv[1], type='user'),
    role=gdata.acl.data.AclRole(value='reader'),
)

# calling function for permission
client.AddAclEntry(doc, acl_entry)
Ejemplo n.º 17
0
def Delete():
  client = CreateClient()
  doc = gdata.docs.data.Resource(type='document', title='My Sample Doc')
  doc = client.CreateResource(doc)
  client.DeleteResource(doc)
doclist=client.GetResources()

for row in rows:
 firstname=row.custom['firstname'].text
 lastname=row.custom['lastname'].text
 email=row.custom['email'].text
 title_doc=assignment+' - '+lastname

 found=False
 for doc in doclist.entry:
  	if doc.title.text==title_doc:
		found=True
 		print(doc.title.text + ' already exists.')
 	 	break
 if found==False:

 # CREATE A NEW DOCUMENT FOR EACH STUDENT
  new_doc = gdata.docs.data.Resource(type='document', title=title_doc)
  new_doc = client.CreateResource(new_doc)
  print 'Created:', new_doc.title.text
  scope = gdata.acl.data.AclScope(value=email, type='user')
  role = gdata.acl.data.AclRole(value='writer')
  acl_entry = gdata.docs.data.AclEntry(scope=scope, role=role)
  client.AddAclEntry(new_doc, acl_entry, send_notification=True)

#  scope = gdata.acl.data.AclScope(value=professor, type='user')
#  role = gdata.acl.data.AclRole(value='writer')
#  acl_entry = gdata.docs.data.AclEntry(scope=scope, role=role)
#  client.AddAclEntry(new_doc, acl_entry, send_notification=False)
Ejemplo n.º 19
0
        try:
            client.ClientLogin(email,
                               password,
                               source,
                               captcha_token=captcha_token,
                               captcha_response=captcha_response)
            login = True
        except gdata.client.CaptchaChallenge:
            print "Captcha check failed."
            login = False
        except gdata.client.BadAuthentication:
            print "Wrong username or password."
            exit(1)
    except gdata.client.BadAuthentication:
        print "Wrong username or password."
        exit(1)
file_resource = gdata.docs.data.Resource(type='document', title=file_on_google)
filename = file_on_disk
try:
    open(filename)
except IOError:
    print "Cannot open " + filename + "."
    exit(1)
media = gdata.data.MediaSource()
media.set_file_handle(filename, 'application/octet-stream')
feedUri = '%s?convert=false' % gdata.docs.client.RESOURCE_UPLOAD_URI
file_resource = client.CreateResource(file_resource,
                                      create_uri=feedUri,
                                      media=media)
exit(0)
Ejemplo n.º 20
0
def CreateCollectionSample():
    """Create an empty collection."""
    client = CreateClient()
    col = gdata.docs.data.Resource(type='folder', title='My Sample Folder')
    col = client.CreateResource(col)
    print 'Created collection:', col.title.text, col.resource_id.text