Il giorno lunedì 10 dicembre 2012 10:35:12 UTC+1, carloratm ha scritto:
>
> Hello,
> what do you think about a replace command for plugins?


I have write a small patch to add a replace command for plugins.
The replace command perform an install and a replace if the plugin already 
exists.

Let me know if this is useful to someone. 

Cheers,

 

-- 
You received this message because you are subscribed to the Google Groups 
"asciidoc" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/asciidoc/-/4mGzGx4MVPMJ.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/asciidoc?hl=en.

diff -r 1ce2d73109e2 asciidoc.py
--- a/asciidoc.py	Sun Oct 07 08:31:02 2012 +1300
+++ b/asciidoc.py	Mon Dec 10 12:32:56 2012 +0100
@@ -5742,7 +5742,7 @@
     """
     --filter and --theme option commands.
     """
-    CMDS = ('install','remove','list','build')
+    CMDS = ('install','remove','replace','list','build')
 
     type = None     # 'backend', 'filter' or 'theme'.
 
@@ -5828,6 +5828,47 @@
             die('failed to delete %s: %s' % (Plugin.type, str(e)))
 
     @staticmethod
+    def replace(args):
+        """
+        Replace plugin Zip file.
+        args[0] is plugin zip file path.
+        args[1] is optional destination plugins directory.
+        """
+        if len(args) not in (1,2):
+            die('invalid number of arguments: --%s replace %s'
+                    % (Plugin.type, ' '.join(args)))
+        zip_file = args[0]
+        if not os.path.isfile(zip_file):
+            die('file not found: %s' % zip_file)
+        reo = re.match(r'^\w+',os.path.split(zip_file)[1])
+        if not reo:
+            die('file name does not start with legal %s name: %s'
+                    % (Plugin.type, zip_file))
+        plugin_name = reo.group()
+        if len(args) == 2:
+            plugins_dir = args[1]
+            if not os.path.isdir(plugins_dir):
+                die('directory not found: %s' % plugins_dir)
+        else:
+            plugins_dir = Plugin.get_dir()
+            if not plugins_dir:
+                die('user home directory is not defined')
+        plugin_dir = os.path.join(plugins_dir, plugin_name)
+        if os.path.exists(plugin_dir):
+            args[0] = os.path.basename(plugin_dir)
+            Plugin.remove(args)
+        try:
+            os.makedirs(plugin_dir)
+        except Exception,e:
+            die('failed to create %s directory: %s' % (Plugin.type, str(e)))
+        try:
+            extract_zip(zip_file, plugin_dir)
+        except Exception,e:
+            if os.path.isdir(plugin_dir):
+                shutil.rmtree(plugin_dir)
+            die('failed to extract %s: %s' % (Plugin.type, str(e)))
+
+    @staticmethod
     def list(args):
         """
         List all plugin directories (global and local).
diff -r 1ce2d73109e2 help.conf
--- a/help.conf	Sun Oct 07 08:31:02 2012 +1300
+++ b/help.conf	Mon Dec 10 12:32:56 2012 +0100
@@ -117,6 +117,7 @@
 
           asciidoc OPTION install ZIP_FILE [PLUGINS_DIR]
           asciidoc OPTION remove PLUGIN_NAME [PLUGINS_DIR]
+          asciidoc OPTION replace ZIP_FILE [PLUGINS_DIR]
           asciidoc OPTION list
           asciidoc OPTION build ZIP_FILE PLUGIN_SOURCE
 
@@ -157,6 +158,10 @@
           Delete the PLUGIN_NAME plugin subdirectory and all its contents
           from the PLUGINS_DIR.
 
+   replace
+          Install or replace the plugin specified by ZIP_FILE in the
+          PLUGINS_DIR.
+
    list
           List the names and locations of all installed filter or theme
           plugins (including standard plugins installed in the global

Reply via email to