Example #1
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)
Example #2
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
for row in rows:
 firstname=row.custom['firstname'].text
 lastname=row.custom['lastname'].text
 email=row.custom['email'].text
 title_doc=assignment+' - '+lastname

 print title_doc

 feeduri='/feeds/default/private/full?title='+title_doc+'&title-exact=true&max-results=5'
 feed2 = client.GetResources(uri=feeduri)
 if not feed2.entry:
  print 'No document of that title.\n'
 doc_id=feed2.entry[0]

 aclfeed=client.GetAcl(doc_id)
 found=False
 for aclentry in aclfeed.entry:
 	if aclentry.scope.value==email:
		found=True
 		print aclentry.scope.value + ' already has permission.'
 	 	break
 if found==False:

# CHANGE THE PERMISSIONS OF THE DOCUMENTS (THE STUDENT IS 'A READER' and a 'COMMENTER')
  scope = gdata.acl.data.AclScope(value=email, type='user')
  role = gdata.acl.data.AclRole(value='reader')
  role2 = gdata.acl.data.AclAdditionalRole(value='commenter')
  acl_entry = gdata.docs.data.AclEntry(scope=scope, role=role, additional_role=role2)
  client.AddAclEntry(doc_id, acl_entry, send_notifications=True)
  print title_doc + ' permissions restored to ' + email + '.'
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)
Example #5
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)