jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
This commit is contained in:
parent
2f3727b85d
commit
e9c0f5e127
1 changed files with 125 additions and 11 deletions
|
|
@ -136,6 +136,8 @@ class BaseEdit(object):
|
|||
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 @@ class BaseEdit(object):
|
|||
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 @@ class BaseEdit(object):
|
|||
# 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 @@ class BaseEdit(object):
|
|||
|
||||
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 @@ class BaseEdit(object):
|
|||
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:
|
||||
|
|
|
|||
Loading…
Reference in a new issue