[kupfer] archivemanager: Split out file-roller actions from fileactions
- From: Ulrik Sverdrup <usverdrup src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [kupfer] archivemanager: Split out file-roller actions from fileactions
- Date: Tue, 22 Mar 2011 23:47:25 +0000 (UTC)
commit a06e1f2b10d68418053ef44119af6b341ad66fc1
Author: Ulrik Sverdrup <ulrik sverdrup gmail com>
Date: Wed Mar 23 00:45:22 2011 +0100
archivemanager: Split out file-roller actions from fileactions
kupfer/plugin/archivemanager.py | 124 +++++++++++++++++++++++++++++++++++++++
kupfer/plugin/fileactions.py | 122 +-------------------------------------
2 files changed, 126 insertions(+), 120 deletions(-)
---
diff --git a/kupfer/plugin/archivemanager.py b/kupfer/plugin/archivemanager.py
new file mode 100644
index 0000000..363f7cb
--- /dev/null
+++ b/kupfer/plugin/archivemanager.py
@@ -0,0 +1,124 @@
+__kupfer_name__ = _("Archive Manager")
+__kupfer_sources__ = ()
+__kupfer_text_sources__ = ()
+__kupfer_actions__ = (
+ "UnpackHere",
+ "CreateArchive",
+ "CreateArchiveIn",
+ )
+__description__ = _("Use Archive Manager actions")
+__version__ = ""
+__author__ = "Ulrik"
+
+import os
+import re
+# since "path" is a very generic name, you often forget..
+from os import path as os_path
+
+from kupfer.objects import Action, FileLeaf
+from kupfer import utils
+from kupfer import plugin_support
+from kupfer import runtimehelper
+
+
+__kupfer_settings__ = plugin_support.PluginSettings(
+ {
+ "key" : "archive_type",
+ "label": _("Compressed archive type for 'Create Archive In'"),
+ "type": str,
+ "value": ".tar.gz",
+ "alternatives": (
+ ".7z",
+ ".rar",
+ ".tar",
+ ".tar.gz",
+ ".tar.bz2",
+ ".tar.xz",
+ ".zip",
+ )
+ },
+)
+
+class UnpackHere (Action):
+ def __init__(self):
+ Action.__init__(self, _("Extract Here"))
+ self.extensions_set = set((
+ ".rar", ".7z", ".zip", ".gz", ".tgz", ".tar", ".lzma", ".bz2",
+ ".tbz2", ".tzo", ".lzo", ".xz", ".ar", ".cbz", ".Z", ".taz",
+ ".lz", ".bz", ".tbz", ".lzh",
+ ))
+ def activate(self, leaf):
+ utils.spawn_async_notify_as("file-roller.desktop",
+ ["file-roller", "--extract-here", leaf.object])
+
+ def valid_for_item(self, item):
+ tail, ext = os.path.splitext(item.object)
+ # FIXME: Make this detection smarter
+ # check for standard extension or a multi-part rar extension
+ return (ext.lower() in self.extensions_set or
+ re.search(r".r\d+$", ext.lower()) is not None)
+
+ def item_types(self):
+ yield FileLeaf
+ def get_description(self):
+ return _("Extract compressed archive")
+
+class CreateArchive (Action):
+ def __init__(self):
+ Action.__init__(self, _("Create Archive"))
+
+ @classmethod
+ def _make_archive(cls, filepaths):
+ cmd = ["file-roller", "--add"]
+ cmd.extend(filepaths)
+ utils.spawn_async_notify_as("file-roller.desktop", cmd)
+
+ def activate(self, leaf):
+ self._make_archive((leaf.object, ))
+ def activate_multiple(self, objs):
+ self._make_archive([L.object for L in objs])
+
+ def item_types(self):
+ yield FileLeaf
+ def get_description(self):
+ return _("Create a compressed archive from folder")
+
+class CreateArchiveIn (Action):
+ def __init__(self):
+ Action.__init__(self, _("Create Archive In..."))
+
+ @classmethod
+ def _make_archive(cls, basename, dirpath, filepaths):
+ archive_type = __kupfer_settings__["archive_type"]
+ archive_path = \
+ utils.get_destpath_in_directory(dirpath, basename, archive_type)
+ cmd = ["file-roller", "--add-to=%s" % (archive_path, )]
+ cmd.extend(filepaths)
+ runtimehelper.register_async_file_result(archive_path)
+ utils.spawn_async_notify_as("file-roller.desktop", cmd)
+ return archive_path
+
+ def activate(self, leaf, iobj):
+ archive_type = __kupfer_settings__["archive_type"]
+ dirpath = iobj.object
+ basename = os_path.basename(leaf.object)
+ self._make_archive(basename, dirpath, (leaf.object, ))
+
+ def activate_multiple(self, objs, iobjs):
+ archive_type = __kupfer_settings__["archive_type"]
+ # TRANS: Default filename (no extension) for 'Create Archive In...'
+ basename = _("Archive")
+ for iobj in iobjs:
+ self._make_archive(basename, iobj.object, [L.object for L in objs])
+
+ def item_types(self):
+ yield FileLeaf
+ def requires_object(self):
+ return True
+ def object_types(self):
+ yield FileLeaf
+ def valid_object(self, obj, for_item=None):
+ return utils.is_directory_writable(obj.object)
+ def get_description(self):
+ return _("Create a compressed archive from folder")
+
diff --git a/kupfer/plugin/fileactions.py b/kupfer/plugin/fileactions.py
index acf0a9f..2e88e9f 100644
--- a/kupfer/plugin/fileactions.py
+++ b/kupfer/plugin/fileactions.py
@@ -5,49 +5,24 @@ __kupfer_actions__ = (
"MoveTo",
"Rename",
"CopyTo",
- "UnpackHere",
- "CreateArchive",
- "CreateArchiveIn",
)
__description__ = _("More file actions")
__version__ = ""
-__author__ = "Ulrik Sverdrup <ulrik sverdrup gmail com>"
+__author__ = "Ulrik"
import gio
import os
-import re
# since "path" is a very generic name, you often forget..
from os import path as os_path
from kupfer.objects import Action, FileLeaf, TextLeaf, TextSource
from kupfer import utils, pretty
-from kupfer import plugin_support
from kupfer import commandexec
-from kupfer import runtimehelper
-__kupfer_settings__ = plugin_support.PluginSettings(
- {
- "key" : "archive_type",
- "label": _("Compressed archive type for 'Create Archive In'"),
- "type": str,
- "value": ".tar.gz",
- "alternatives": (
- ".7z",
- ".rar",
- ".tar",
- ".tar.gz",
- ".tar.bz2",
- ".tar.xz",
- ".zip",
- )
- },
-)
-
def _good_destination(dpath, spath):
"""If directory path @dpath is a valid destination for file @spath
- to be copied or moved to. Additional checking is done in
- good_destination_final
+ to be copied or moved to.
"""
if not os_path.isdir(dpath):
return False
@@ -60,16 +35,6 @@ def _good_destination(dpath, spath):
return False
return True
-def _good_destination_final(dpath, spath):
- """Perform a final check that the file @spath can
- be copied or moved to @dpath
- """
- dest_filename = os_path.join(dpath, os_path.basename(spath))
- if os_path.exists(dest_filename):
- return False
- parent_spath = os_path.dirname(spath)
- return not (dpath == parent_spath)
-
class MoveTo (Action, pretty.OutputMixin):
def __init__(self):
Action.__init__(self, _("Move To..."))
@@ -218,86 +183,3 @@ class CopyTo (Action, pretty.OutputMixin):
return _good_destination(obj.object, for_item.object)
def get_description(self):
return _("Copy file to a chosen location")
-
-class UnpackHere (Action):
- def __init__(self):
- Action.__init__(self, _("Extract Here"))
- self.extensions_set = set((
- ".rar", ".7z", ".zip", ".gz", ".tgz", ".tar", ".lzma", ".bz2",
- ".tbz2", ".tzo", ".lzo", ".xz", ".ar", ".cbz", ".Z", ".taz",
- ".lz", ".bz", ".tbz", ".lzh",
- ))
- def activate(self, leaf):
- utils.spawn_async_notify_as("file-roller.desktop",
- ["file-roller", "--extract-here", leaf.object])
-
- def valid_for_item(self, item):
- tail, ext = os.path.splitext(item.object)
- # FIXME: Make this detection smarter
- # check for standard extension or a multi-part rar extension
- return (ext.lower() in self.extensions_set or
- re.search(r".r\d+$", ext.lower()) is not None)
-
- def item_types(self):
- yield FileLeaf
- def get_description(self):
- return _("Extract compressed archive")
-
-class CreateArchive (Action):
- def __init__(self):
- Action.__init__(self, _("Create Archive"))
-
- @classmethod
- def _make_archive(cls, filepaths):
- cmd = ["file-roller", "--add"]
- cmd.extend(filepaths)
- utils.spawn_async_notify_as("file-roller.desktop", cmd)
-
- def activate(self, leaf):
- self._make_archive((leaf.object, ))
- def activate_multiple(self, objs):
- self._make_archive([L.object for L in objs])
-
- def item_types(self):
- yield FileLeaf
- def get_description(self):
- return _("Create a compressed archive from folder")
-
-class CreateArchiveIn (Action):
- def __init__(self):
- Action.__init__(self, _("Create Archive In..."))
-
- @classmethod
- def _make_archive(cls, basename, dirpath, filepaths):
- archive_type = __kupfer_settings__["archive_type"]
- archive_path = \
- utils.get_destpath_in_directory(dirpath, basename, archive_type)
- cmd = ["file-roller", "--add-to=%s" % (archive_path, )]
- cmd.extend(filepaths)
- runtimehelper.register_async_file_result(archive_path)
- utils.spawn_async_notify_as("file-roller.desktop", cmd)
- return archive_path
-
- def activate(self, leaf, iobj):
- archive_type = __kupfer_settings__["archive_type"]
- dirpath = iobj.object
- basename = os_path.basename(leaf.object)
- self._make_archive(basename, dirpath, (leaf.object, ))
-
- def activate_multiple(self, objs, iobjs):
- archive_type = __kupfer_settings__["archive_type"]
- # TRANS: Default filename (no extension) for 'Create Archive In...'
- basename = _("Archive")
- for iobj in iobjs:
- self._make_archive(basename, iobj.object, [L.object for L in objs])
-
- def item_types(self):
- yield FileLeaf
- def requires_object(self):
- return True
- def object_types(self):
- yield FileLeaf
- def valid_object(self, obj, for_item=None):
- return utils.is_directory_writable(obj.object)
- def get_description(self):
- return _("Create a compressed archive from folder")
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]