Permalink
Browse files

[fm] delete files using a task

  • Loading branch information...
1 parent bd301e2 commit c332eebf83b33004a89a52d657cbab52d2aa6d6b @Eugeny Eugeny committed Jun 4, 2014
@@ -11,7 +11,7 @@
from ajenti.util import str_fsize
from ajenti.plugins import manager
from ajenti.plugins.tasks.manager import TaskManager
-from ajenti.plugins.tasks.tasks import CopyFilesTask, MoveFilesTask
+from ajenti.plugins.tasks.tasks import CopyFilesTask, MoveFilesTask, DeleteFilesTask
class Item (object):
@@ -121,13 +121,13 @@ def _has_dirs(self, items):
def init(self):
self.task_manager = TaskManager.get()
- def remove(self, items, cb=lambda: None):
+ def remove(self, items, cb=lambda t: None):
logging.info('[fm] removing %s' % ', '.join(x.fullpath for x in items))
if self._total_size(items) > self.FG_OPERATION_LIMIT or self._has_dirs(items):
- command = 'rm -vfr -- '
- for item in items:
- command += self._escape(item)
- self.context.launch('terminal', command=command, callback=cb)
+ paths = [x.fullpath for x in items]
+ task = DeleteFilesTask.new(source=paths)
+ task.callback = cb
+ self.task_manager.run(task=task)
else:
for i in items:
if os.path.isdir(i.fullpath):
@@ -146,7 +146,7 @@ def move(self, items, dest, cb=lambda t: None):
else:
for i in items:
shutil.move(i.fullpath, dest)
- cb()
+ cb(None)
def copy(self, items, dest, cb=lambda t: None):
logging.info('[fm] copying %s to %s' % (', '.join(x.fullpath for x in items), dest))
@@ -161,7 +161,7 @@ def copy(self, items, dest, cb=lambda t: None):
shutil.copytree(i.fullpath, os.path.join(dest, i.name))
else:
shutil.copy(i.fullpath, os.path.join(dest, i.name))
- cb()
+ cb(None)
@interface
@@ -111,8 +111,8 @@ def on_new_directory(self):
self.refresh()
def _chown_new(self, path):
- uid = self.classconfig.get('new_owner', 'root')
- gid = self.classconfig.get('new_group', 'root')
+ uid = self.classconfig.get('new_owner', 'root') or 'root'
+ gid = self.classconfig.get('new_group', 'root') or 'root'
try:
uid = int(uid)
except:
@@ -157,7 +157,10 @@ def on_copy(self):
@on('mass-delete', 'click')
def on_delete(self):
- self.backend.remove(self._get_checked(), self.refresh)
+ def callback(task):
+ self.context.notify('info', _('Files deleted'))
+ self.refresh()
+ self.backend.remove(self._get_checked(), cb=callback)
@on('paste', 'click')
def on_paste(self):
@@ -279,7 +282,7 @@ def on_bc_click(self, tab, item):
tab.navigate(item.path)
self.refresh()
- def refresh(self):
+ def refresh(self, _=None):
for tab in self.controller.tabs:
tab.refresh()
self.binder.populate()
@@ -0,0 +1,7 @@
+<bind:dict id="bind">
+ <vc>
+ <formline text="{From directory}">
+ <pathbox directory="True" bind="source" />
+ </formline>
+ </vc>
+</bind:dict>
@@ -11,7 +11,7 @@
@plugin
class CommandTask (Task):
- name = 'Execute command'
+ name = _('Execute command')
ui = 'tasks:params-execute'
default_params = {
'command': '',
@@ -61,12 +61,39 @@ def run(self, source=None, destination=None):
@plugin
class MoveFilesTask (CopyFilesTask):
- name = 'Move files'
+ name = _('Move files')
command = ['mv']
message_template = _('Moving %s')
@plugin
+class DeleteFilesTask (Task):
+ name = _('Delete files')
+ ui = 'tasks:params-deletedir'
+ command = ['rm', '-rf', '--']
+ message_template = _('Deleting %s')
+ default_params = {
+ 'source': '',
+ }
+
+ def run(self, source=None):
+ index = 0
+ if isinstance(source, basestring):
+ source = [source]
+
+ for file in source:
+ self.message = self.message_template % file
+ p = subprocess.Popen(self.command + [file])
+ while p.poll() is None:
+ gevent.sleep(1)
+ if self.aborted:
+ p.terminate()
+ return
+ index += 1
+ self.set_progress(index, len(source))
+
+
+@plugin
class RSyncTask (Task):
name = 'RSync'
ui = 'tasks:params-rsync'
View
@@ -15,7 +15,7 @@
"ajenti.plugins.tasks.manager.TaskManager": "{\"task_definitions\": []}",
"ajenti.usersync.adsync.ActiveDirectorySyncProvider": "{\"domain\": \"DOMAIN\", \"password\": \"\", \"user\": \"Administrator\", \"base\": \"cn=Users,dc=DOMAIN\", \"address\": \"localhost\"}",
"ajenti.plugins.elements.usermgr.ElementsUserManager": "{\"groups\": []}",
- "ajenti.plugins.elements.projects.main.ElementsProjectManager": "{\"projects\": \"(lp1\\n.\"}"
+ "ajenti.plugins.elements.projects.main.ElementsProjectManager": "{\"projects\": \"KGxwMQou\\n\"}"
},
"password": "sha512|$6$rounds=40000$nIVrqqz638rB8wOo$VbMv8y2lStgcsYxEuu7JfHiEd06eeiSoIbg7Hvivj9K1vPayaCbAiAqtpyOoIkNfIXFmMD0jK6Dd4WFnvywkY1",
"permissions": []

0 comments on commit c332eeb

Please sign in to comment.