diff frontends/src/jp/common.py @ 2351:3c0a3fae1862

jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
author Goffi <goffi@goffi.org>
date Wed, 06 Sep 2017 07:39:10 +0200
parents c57bc0fe17d9
children 8b37a62336c3
line wrap: on
line diff
--- a/frontends/src/jp/common.py	Wed Sep 06 07:38:39 2017 +0200
+++ b/frontends/src/jp/common.py	Wed Sep 06 07:39:10 2017 +0200
@@ -136,6 +136,8 @@
     This class allows to edit file for PubSub or something else.
     It works with temporary files in SàT local_dir, in a "cat_dir" subdir
     """
+    # use_items(bool): True if items are used, will then add item related options
+    use_items=True
 
     def __init__(self, host, cat_dir, use_metadata=False):
         """
@@ -152,9 +154,10 @@
         self.use_metadata = use_metadata
 
     def add_parser_options(self):
-        group = self.parser.add_mutually_exclusive_group()
-        group.add_argument("--force-item", action='store_true', help=_(u"don't use magic and take item argument as an actual item"))
-        group.add_argument("--last-item", action='store_true', help=_(u"take last item instead of creating a new one if no item id is found"))
+        if self.use_items:
+            group = self.parser.add_mutually_exclusive_group()
+            group.add_argument("--force-item", action='store_true', help=_(u"don't use magic and take item argument as an actual item"))
+            group.add_argument("--last-item", action='store_true', help=_(u"take last item instead of creating a new one if no item id is found"))
 
     def secureUnlink(self, path):
         """Unlink given path after keeping it for a while
@@ -311,12 +314,13 @@
         # if metadata is needed, publish will be called with it last argument
         raise NotImplementedError
 
-    def getTmpFile(self, suff):
+    def getTmpFile(self):
         """Create a temporary file
 
         @param suff (str): suffix to use for the filename
         @return (tuple(file, str)): opened (w+b) file object and file path
         """
+        suff = '.' + self.getTmpSuff()
         cat_dir_str = self.cat_dir_str
         tmp_dir = getTmpDir(self.sat_conf, self.cat_dir_str, self.profile.encode('utf-8'))
         if not os.path.exists(tmp_dir):
@@ -443,8 +447,7 @@
 
         if not force_item and command in ('new', 'last', 'edit'):
             # we need a temporary file
-            tmp_suff = '.' + self.getTmpSuff()
-            content_file_obj, content_file_path = self.getTmpFile(tmp_suff)
+            content_file_obj, content_file_path = self.getTmpFile()
             if command == 'new':
                 self.disp(u'Editing a new item', 2)
                 if self.use_metadata:
@@ -475,8 +478,7 @@
                 content_file_obj = open(content_file_path, 'r+b')
             else:
                 # last chance, it should be an item
-                tmp_suff = '.' + self.getTmpSuff()
-                content_file_obj, content_file_path = self.getTmpFile(tmp_suff)
+                content_file_obj, content_file_path = self.getTmpFile()
                 pubsub_item = self.args.item
 
                 try: