Esempio n. 1
0
	def dispatch_create_item(self, path):
		responseData = {}
		if not os.path.isfile(path):
			responseData['response'] = 1
		else:
			responseData['response'] = 0

			uid = ndutil.getUid(path)
			if self.dbManager.exists(uid):
				responseData['uid'] = uid
				if self.fileMode == 'move':
					os.remove(path)
			else:
				size = ndutil.getSize(path) / 1024
				createTime = ndutil.getCreated()
						
				fileExt = os.path.basename(path).split('.', 1)
				dirPath = self.enable_storage_dir(self.storageDir, uid)
				newPath = '%s/%s.%s' % (dirPath, uid, fileExt[1])
				if self.fileMode == 'move':
					shutil.move(path, newPath)
				elif self.fileMode == 'copy':
					shutil.copyfile(path, newPath)
				path = ndutil.getAbstractPath(newPath)

				self.dbManager.create_item(uid, path, createTime, size)
				responseData['uid'] = uid
		return responseData
Esempio n. 2
0
	def dispatch_delete_item(self, uid):
		responseData = {}
		if not self.dbManager.exists(uid):
			responseData['response'] = 1
		else:
			responseData['response'] = 0
			path = ndutil.getAbstractPath(self.dbManager.get_path(uid))
			self.dbManager.delete_item(uid)
			os.remove(path)
		return responseData