Exemplo n.º 1
0
Arquivo: tasks.py Projeto: velsa/mdbox
def add_dir_from_dropbox(parent_node_id, db_dir_path, use_ust=True, callback=None):
	"""
	Add new dir from dropbox to our database and sync it to server
	Arguments:
		parent_node_id: 	dir where the new dir should be created
		db_file_path:		full path to dropbox dir
		use_ust: 			if True, process remove in User Synchronous mode
	"""
	parent_node, db_sess = _get_node(parent_node_id, need_db_sess=False)

	if use_ust:
		if django_settings.ASYNC_DROPBOX:
			yield gen.Task(async_ust_start, parent_node.user)
		else:
			ust_start(parent_node.user)


	# Add new node to treebeard
	node = parent_node.add_child (
		db_path		= db_dir_path,
		is_file		= False,
		last_modified = datetime.utcnow(),
		srv_src		= get_server_dir(parent_node.user, db_dir_path),
		srv_html	= get_server_dir(parent_node.user, db_dir_path),
		user		= parent_node.user
	)

	try:
		# And dir to local storage
		create_server_dir(parent_node.user, db_dir_path)

		# Sync creates the dir on server if it does not exists
		if django_settings.ASYNC_DROPBOX:
			yield_key = object()
			sync_dir_from_dropbox(node.id, use_ust=False,
				callback=(yield gen.Callback(yield_key)))
			yield gen.Wait(yield_key)
		else:
			sync_dir_from_dropbox(node.id, use_ust=False)
	except Exception, e:
		l.error("add_DIR_FROM_dropbox: '%s':'%s' FAILED" %\
				(node.user.username, node.db_path, ))
		raise MDBException("ERROR: "+e.message)
Exemplo n.º 2
0
			l.error("cleanup_and_sync(): can't remove root dir for user '%s' (%s)" %\
					(self.username, e))

		# Cleanup in MDBTree
		try:
			nodes = MDBTree.objects.filter(user=self)
		except Exception, e:
			l.error("cleanup_and_sync(): no MDBTree nodes for user '%s' (%s)" %\
					(self.username, e))
		else:
			# Remove all MDBTree for user
			nodes.delete()

		# NOW create user directory on server
		create_server_dir(self, '')

		# Create new root node in treebeard
		root_node = MDBTree.add_root(
			db_path		= '/',
			is_file		= False,
			srv_html	= get_server_dir(self, '/'),
			srv_src		= get_server_dir(self, '/'),
			user		= self
		)

	# Next sync will update the hash for new root
	# and will create all children in treebeard
#		from main.tasks import sync_all_dirs_from_dropbox
#		sync_all_dirs_from_dropbox(self.id)
#		return "%s: cleanup_and_sync (%s)" % (TASK_SUCCESS, self.username, )