def setPublicLink(self, filename, create=True): resp = None content = None data = XMLElement('file') data.setHead(self.xmlHead) elm = XMLElement('publicLink') if create: elm.setAttribute('enabled', 'true') else: elm.setAttribute('enabled', 'false') data.addChild(elm) resp, content = self.sendRequestPut('/file/%s' % filename, data.toString()) if resp is not None: if int(resp['status']) == 200: content = XMLElement.parse(content) if create: print('Created public link: %s' % content.publicLink) else: print('Public link destroyed successful.') else: print('Could not create/destroy public link (Code: %s).' % resp['status']) else: print('Could not create/destroy public link (request failed).')
def getFileHistory(filename): from SugarSyncFile import SugarSyncFile sync = SugarSyncInstance.instance response = sync.sendRequest('/file/%s/version' % filename, {}, True, False) files = None if response is not False and response is not None: info = response.info() code = response.getcode() data = XMLElement.parse(response.read().decode('utf8')) # We will parse into SugarSyncFile and then return an dict maybe sorted after # lastModified if code == 200 and data is not None: files = [] for fv in data.childs: version = SugarSyncFile(fv.ref) version.setSize(fv.size) version.setMediaType(str(fv.mediaType)) version.setPresentOnServer(str(fv.presentOnServer)) version.setLastModified(str(fv.lastModified)) files.append(version) if code == 200: print('Got file history successfully.') else: print('Error on getting history (Code: %s)!' % (code)) else: print('Request failed.') return files
def updateFile(self, filename, name = '', mediaType = '', parent = ''): resp = None content = None if parent != '': parent = self.apiURL + '/folder/%s' % parent if parent != '' or name != '' or mediaType != '': data = XMLElement('file') data.setHead(self.xmlHead) if name != '': data.addChild(XMLElement('displayName').addChild(XMLTextNode(name))) if mediaType != '': data.addChild(XMLElement('mediaType').addChild(XMLTextNode(mediaType))) if parent != '': data.addChild(XMLElement('parent').addChild(XMLTextNode(parent))) resp, content = self.sendRequestPut('/file/%s' % filename, data.toString()) if resp is not None: if int(resp['status']) == 200: content = XMLElement.parse(content) # here are the file infos ;-) print('File Information updated') else: print('File information could not be updated (Code: %s)!' % (resp['status'])) else: print('There is nothing to change O_o')
def getUser(self): response = self.sendRequest('/user', {}, True, False) if response is not None: resp = XMLElement.parse(response.read().decode('utf8')) self.username = str(resp.username) self.nickname = str(resp.nickname) self.quotaLimit = resp.quota.limit self.quotaUsage = resp.quota.usage print("Username:\t", self.username) print("Nickname:\t", self.nickname) print("Space Limit:\t", self.quotaLimit, "Bytes") print("Space Used:\t", self.quotaUsage, "Bytes\n")
def auth(self): data = XMLElement('authRequest') data.setHead(self.xmlHead) data.addChild(XMLElement('username').addChild(XMLTextNode(self.username))) data.addChild(XMLElement('password').addChild(XMLTextNode(self.password))) data.addChild(XMLElement('accessKeyId').addChild(XMLTextNode(self.accessKeyId))) data.addChild(XMLElement('privateAccessKey').addChild(XMLTextNode(self.privateAccessKey))) response = self.sendRequest('/authorization', data.toString(), False) if response is not None: info = response.info() self.token = info['Location'] resp = XMLElement.parse(response.read().decode('utf8')) self.tokenExpire = resp.expiration # get the user info self.getUser()
def getAllFilesCollection(self): response = self.sendRequest('/user', {}, True, False) if response is not None: data = XMLElement.parse(response.read().decode('utf8')) self.quotaLimit = data.quota.limit self.quotaUsage = data.quota.usage self.folder['workspaces'] = data.workspaces self.folder['syncfolders'] = data.syncfolders self.folder['deleted'] = data.deleted self.folder['magicBriefcase'] = data.magicBriefcase self.folder['webArchive'] = data.webArchive self.folder['mobilePhotos'] = data.mobilePhotos self.folder['albums'] = data.albums self.folder['recentactivities'] = data.recentActivities self.folder['receivedshares'] = data.receivedShares self.folder['publiclinks'] = data.publicLinks print("Data loaded! \n\n")
def getFolderInfo(foldername): # foldername is the id sync = SugarSyncInstance.instance resp = sync.sendRequest('/folder/'+foldername, post=False) respData = None if resp is not None: if int(resp.status) == 200: print('Received successful.') # data.. but in which method? data = resp.read().decode('utf8') respData = XMLElement.parse(data) else: print('Folder Informations could not be retrieved. (Code: %s)' % resp.status) else: print('Could not retrieve folder informations.') return respData
def getFolderInfo(foldername): # foldername is the id sync = SugarSyncInstance.instance resp = sync.sendRequest('/folder/' + foldername, post=False) respData = None if resp is not None: if int(resp.status) == 200: print('Received successful.') # data.. but in which method? data = resp.read().decode('utf8') respData = XMLElement.parse(data) else: print( 'Folder Informations could not be retrieved. (Code: %s)' % resp.status) else: print('Could not retrieve folder informations.') return respData
def auth(self): data = XMLElement('authRequest') data.setHead(self.xmlHead) data.addChild( XMLElement('username').addChild(XMLTextNode(self.username))) data.addChild( XMLElement('password').addChild(XMLTextNode(self.password))) data.addChild( XMLElement('accessKeyId').addChild(XMLTextNode(self.accessKeyId))) data.addChild( XMLElement('privateAccessKey').addChild( XMLTextNode(self.privateAccessKey))) response = self.sendRequest('/authorization', data.toString(), False) if response is not None: info = response.info() self.token = info['Location'] resp = XMLElement.parse(response.read().decode('utf8')) self.tokenExpire = resp.expiration # get the user info self.getUser()
def getFileInfo(filename, absolut=False): # filename => file id sync = SugarSyncInstance.instance if absolut is False: filename = '/file/' + filename resp = sync.sendRequest(filename, post=False) respData = None if resp is not None: if int(resp.status) == 200: print('Received successful.') # data.. but in which method? data = resp.read().decode('utf8') respData = XMLElement.parse(data) else: print('File informations could not be retrieved. (Code: %s)' % resp.status) else: print('Could not retrieve file informations.') return respData
def updateFile(self, filename, name='', mediaType='', parent=''): resp = None content = None if parent != '': parent = self.apiURL + '/folder/%s' % parent if parent != '' or name != '' or mediaType != '': data = XMLElement('file') data.setHead(self.xmlHead) if name != '': data.addChild( XMLElement('displayName').addChild(XMLTextNode(name))) if mediaType != '': data.addChild( XMLElement('mediaType').addChild(XMLTextNode(mediaType))) if parent != '': data.addChild( XMLElement('parent').addChild(XMLTextNode(parent))) resp, content = self.sendRequestPut('/file/%s' % filename, data.toString()) if resp is not None: if int(resp['status']) == 200: content = XMLElement.parse( content) # here are the file infos ;-) print('File Information updated') else: print('File information could not be updated (Code: %s)!' % (resp['status'])) else: print('There is nothing to change O_o')