Skip to content
Permalink
Browse files

adding option to control worksheet protection

  • Loading branch information
jonrkarr committed Oct 29, 2019
1 parent d5b9829 commit c9fafbd72e4204f854467cafd98065aae918bed7
Showing with 25 additions and 11 deletions.
  1. +13 −5 wc_kb/__main__.py
  2. +12 −6 wc_kb/io.py
@@ -136,16 +136,18 @@ class Meta:
(['--dest-seq'], dict(
default='', type=str,
help='Path to save normalized FASTA-formatted genome sequence for the knowledge base')),
(['--unprotected'], dict(action='store_true', default=False,
help='If set, do not protect the outputted workbook')),
]

@cement.ex(hide=True)
def _default(self):
args = self.app.pargs
kb = io.Reader().run(args.source_core, seq_path=args.source_seq)[core.KnowledgeBase][0]
if args.dest_core or args.dest_seq:
io.Writer().run(args.dest_core, kb, seq_path=args.dest_seq, data_repo_metadata=False)
io.Writer().run(args.dest_core, kb, seq_path=args.dest_seq, data_repo_metadata=False, protected=(not args.unprotected))
else:
io.Writer().run(args.source_core, kb, seq_path=args.source_seq, data_repo_metadata=False)
io.Writer().run(args.source_core, kb, seq_path=args.source_seq, data_repo_metadata=False, protected=(not args.unprotected))


class ConvertController(cement.Controller):
@@ -163,12 +165,14 @@ class Meta:
(['source_seq'], dict(type=str, help='Path to FASTA-formatted genome sqeuence of the knowledge base')),
(['dest_core'], dict(type=str, help='Path to save the converted core of the knowledge base')),
(['dest_seq'], dict(type=str, help='Path to save the converted FASTA-formatted genome sequence of the knowledge base')),
(['--unprotected'], dict(action='store_true', default=False,
help='If set, do not protect the outputted workbook')),
]

@cement.ex(hide=True)
def _default(self):
args = self.app.pargs
io.convert(args.source_core, args.source_seq, args.dest_core, args.dest_seq)
io.convert(args.source_core, args.source_seq, args.dest_core, args.dest_seq, protected=(not args.unprotected))


class CreateTemplateController(cement.Controller):
@@ -188,12 +192,14 @@ class Meta:
(['--ignore-repo-metadata'], dict(dest='data_repo_metadata', default=True, action='store_false',
help=('If set, do not set the Git repository metadata for the knowledge base from '
'the Git repo containing `path-core`'))),
(['--unprotected'], dict(action='store_true', default=False,
help='If set, do not protect the outputted workbook')),
]

@cement.ex(hide=True)
def _default(self):
args = self.app.pargs
io.create_template(args.path_core, args.path_seq, data_repo_metadata=args.data_repo_metadata)
io.create_template(args.path_core, args.path_seq, data_repo_metadata=args.data_repo_metadata, protected=(not args.unprotected))


class UpdateVersionMetadataController(cement.Controller):
@@ -211,14 +217,16 @@ class Meta:
(['--ignore-repo-metadata'], dict(dest='data_repo_metadata', default=True, action='store_false',
help=('If set, do not set the Git repository metadata for the knowledge base from '
'the Git repo containing `path-core`'))),
(['--unprotected'], dict(action='store_true', default=False,
help='If set, do not protect the outputted workbook')),
]

@cement.ex(hide=True)
def _default(self):
args = self.app.pargs
kb = io.Reader().run(args.path_core, seq_path=args.path_seq)[core.KnowledgeBase][0]
kb.wc_kb_version = wc_kb.__version__
io.Writer().run(args.path_core, kb, seq_path=args.path_seq, data_repo_metadata=args.data_repo_metadata)
io.Writer().run(args.path_core, kb, seq_path=args.path_seq, data_repo_metadata=args.data_repo_metadata, protected=(not args.unprotected))


class App(cement.App):
@@ -80,7 +80,7 @@ def run(self, core_path, knowledge_base,
models=None, get_related=True, include_all_attributes=False, validate=True,
title=None, description=None, keywords=None, version=None, language=None, creator=None,
write_schema=False, write_toc=True,
extra_entries=0, data_repo_metadata=False, schema_package=None):
extra_entries=0, data_repo_metadata=False, schema_package=None, protected=True):
""" Write knowledge base to file(s)
Args:
@@ -111,6 +111,7 @@ def run(self, core_path, knowledge_base,
schema_package (:obj:`str`, optional): the package which defines the `obj_tables` schema
used by the file; if not :obj:`None`, try to write metadata information about the
the schema's Git repository: the repo must be current with origin
protected (:obj:`bool`, optional): if :obj:`True`, protect the worksheet
Raises:
:obj:`ValueError`: if any of the relationships with knowledge bases and cells are not set
@@ -163,7 +164,8 @@ def run(self, core_path, knowledge_base,
title=title, description=description, version=version, language=language,
creator=creator,
write_schema=write_schema, write_toc=write_toc, extra_entries=extra_entries,
data_repo_metadata=data_repo_metadata, schema_package=schema_package)
data_repo_metadata=data_repo_metadata, schema_package=schema_package,
protected=protected)

# reset sequence paths
if seq_path and rewrite_seq_path:
@@ -391,7 +393,7 @@ def run(self, core_path,
return objects


def convert(source_core, source_seq, dest_core, dest_seq, rewrite_seq_path=True):
def convert(source_core, source_seq, dest_core, dest_seq, rewrite_seq_path=True, protected=True):
""" Convert among Excel (.xlsx), comma separated (.csv), and tab separated (.tsv) file formats
Read a knowledge base from the `source` files(s) and write it to the `destination` files(s). A path to a
@@ -405,13 +407,15 @@ def convert(source_core, source_seq, dest_core, dest_seq, rewrite_seq_path=True)
dest_seq (:obj:`str`): path to save the converted genome sequence of the knowledge base
rewrite_seq_path (:obj:`bool`, optional): if :obj:`True`, the path to genome sequence in the converted
core of the knowledge base will be updated to the path of the converted genome sequence
protected (:obj:`bool`, optional): if :obj:`True`, protect the worksheet
"""
kb = Reader().run(source_core, seq_path=source_seq)[core.KnowledgeBase][0]
Writer().run(dest_core, kb, seq_path=dest_seq, rewrite_seq_path=rewrite_seq_path, data_repo_metadata=False)
Writer().run(dest_core, kb, seq_path=dest_seq, rewrite_seq_path=rewrite_seq_path, data_repo_metadata=False,
protected=protected)


def create_template(core_path, seq_path, write_schema=False, write_toc=True,
extra_entries=10, data_repo_metadata=True):
extra_entries=10, data_repo_metadata=True, protected=True):
""" Create file with knowledge base template, including row and column headings
Args:
@@ -422,10 +426,12 @@ def create_template(core_path, seq_path, write_schema=False, write_toc=True,
extra_entries (:obj:`int`, optional): additional entries to display
data_repo_metadata (:obj:`bool`, optional): if :obj:`True`, try to write metadata information
about the file's Git repo
protected (:obj:`bool`, optional): if :obj:`True`, protect the worksheet
"""
kb = core.KnowledgeBase(
id='template', name='Template', version=wc_kb.__version__)
Writer().run(core_path, kb, seq_path=seq_path,
write_schema=write_schema, write_toc=write_toc,
extra_entries=extra_entries,
data_repo_metadata=data_repo_metadata)
data_repo_metadata=data_repo_metadata,
protected=protected)

0 comments on commit c9fafbd

Please sign in to comment.
You can’t perform that action at this time.