def test(): file_id = "https://drive.google.com/open?id=0B60IjoJ-xHK6YU1wZ2hsQVQ0SzA" permission_id = "02914492818163807046i" action1 = { 'name': 'update', 'param': [ permission_id, 'user', 'writer', '*****@*****.**']} action2 = { 'name': 'update', 'param': [ permission_id, 'user', 'reader', '*****@*****.**']} for action in [action1, action2]: perm = GDPerm(file_id, action) result = perm.run() pprint(result) assert result[u"role"] == action["param"][2]
def run(self): if self.parent_folderId is None: parents = [] else: parents = [{ "kind": "drive#fileLink", "id": self.parent_folderId}] body = { 'title': self.folder_name, 'description': self.target_description, 'mimeType': self.mime_type, 'parents': parents} try: response_insert = self.service.files().insert(body=body).execute() except Exception as e: logger.error(e) raise else: if (self.permission is not None) and response_insert.get('id') != None: try: param = { 'name': 'insert', 'param': self.permission} perm = GDPerm(response_insert['id'], param) response_perm = perm.run() except Exception as e: logger.error(e) raise return response_insert
# set debug devel logger.setLevel(getattr(logging, args.debug.upper())) action = {} valid_actions = [ "list", "get", "insert", "update", "delete", "get_by_user"] for a in valid_actions: action[a] = args.__dict__[a] # check which action is given by argument for act in action: if action[act] != mutex_group.get_default(act): pass_action = {"name": act, "param": action[act]} logger.debug("pass_action=%s" % pass_action) perm = GDPerm(args.file_id, pass_action) result = perm.run() pprint(result) if result is None: sys.exit(1) else: sys.exit(0) logger.error('unexpected error') sys.exit(1)