From: Donghoon Shin Date: Fri, 9 Sep 2016 16:31:49 +0000 (+0000) Subject: Add projects and topology param X-Git-Tag: 0.3.3~22^2 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=f0e4f437f725da18aec25fe7cc93dd8d76d198cb;p=tools%2Flitmus.git Add projects and topology param --- diff --git a/litmus/cmds/__init__.py b/litmus/cmds/__init__.py index e155ab2..4852a96 100644 --- a/litmus/cmds/__init__.py +++ b/litmus/cmds/__init__.py @@ -14,13 +14,12 @@ # limitations under the License. from configparser import RawConfigParser -from litmus import _projects_ -def load_project_list(): +def load_project_list(projects): """docstring for load_project_list""" configparser = RawConfigParser() - configparser.read(_projects_) + configparser.read(projects) project_list = [] for section in configparser.sections(): diff --git a/litmus/cmds/cmd_cp.py b/litmus/cmds/cmd_cp.py index 9ad676c..efbe848 100755 --- a/litmus/cmds/cmd_cp.py +++ b/litmus/cmds/cmd_cp.py @@ -17,12 +17,11 @@ import os import logging from litmus.core.util import copy, call from litmus.cmds import load_project_list -from litmus import _projects_ def main(args): """docstring for main""" - prj_list = load_project_list() + prj_list = load_project_list(args.projects) orig = next((prj for prj in prj_list if prj['name'] == args.orig), None) @@ -45,7 +44,7 @@ def main(args): copy(orig['path'], path) call(['chmod', '-R', '775', path]) - with open(_projects_, 'a') as f: + with open(args.projects, 'a') as f: f.write('[{0}]\n'.format(args.new)) f.write('path={0}\n'.format(path)) f.write('description={0}\n\n'.format(description)) diff --git a/litmus/cmds/cmd_dev.py b/litmus/cmds/cmd_dev.py index 2f6940d..fecc4d5 100755 --- a/litmus/cmds/cmd_dev.py +++ b/litmus/cmds/cmd_dev.py @@ -15,7 +15,6 @@ import os import logging -from litmus import _duts_ def load_device_list(topology): @@ -27,4 +26,4 @@ def load_device_list(topology): def main(args): """docstring for main""" logging.debug('=====list of all devices in topology=====\n') - load_device_list(_duts_) + load_device_list(args.topology) diff --git a/litmus/cmds/cmd_gt.py b/litmus/cmds/cmd_gt.py index b0ed8da..b89cbe8 100755 --- a/litmus/cmds/cmd_gt.py +++ b/litmus/cmds/cmd_gt.py @@ -18,4 +18,4 @@ from litmus.helper.gt import main as gt_main def main(args): """docstring for main""" - gt_main() + gt_main(topology=args.topology) diff --git a/litmus/cmds/cmd_imp.py b/litmus/cmds/cmd_imp.py index 91de1b8..ff59589 100755 --- a/litmus/cmds/cmd_imp.py +++ b/litmus/cmds/cmd_imp.py @@ -14,14 +14,13 @@ # limitations under the License. import os -from litmus import _projects_ from litmus.cmds import load_project_list from litmus.core.util import call def main(args): """docstring for main""" - prj_list = load_project_list() + prj_list = load_project_list(args.projects) project = next((prj for prj in prj_list if prj['name'] == args.project), @@ -60,7 +59,7 @@ def main(args): call(['chmod', '-R', '775', prj_path]) - with open(_projects_, 'a') as f: + with open(args.projects, 'a') as f: f.write('[{0}]\n'.format(args.project)) f.write('path={0}\n'.format(os.path.abspath(prj_path))) f.write('description={0}\n\n'.format(prj_description)) diff --git a/litmus/cmds/cmd_ls.py b/litmus/cmds/cmd_ls.py index 4a3b235..4e96b2c 100755 --- a/litmus/cmds/cmd_ls.py +++ b/litmus/cmds/cmd_ls.py @@ -19,7 +19,7 @@ from litmus.cmds import load_project_list def main(args): """docstring for main""" - prj_list = load_project_list() + prj_list = load_project_list(args.projects) logging.debug('=====list of all litmus projects=====') for loop in prj_list: logging.debug('{0:10s} ({1} : {2})'.format(loop['name'], diff --git a/litmus/cmds/cmd_mk.py b/litmus/cmds/cmd_mk.py index beda788..40fa12c 100755 --- a/litmus/cmds/cmd_mk.py +++ b/litmus/cmds/cmd_mk.py @@ -17,13 +17,13 @@ import os import litmus import logging from litmus.core.util import copy, call -from litmus import _projects_, _dev_types_ +from litmus import _dev_types_ from litmus.cmds import load_project_list def main(args): """docstring for main""" - prj_list = load_project_list() + prj_list = load_project_list(args.projects) project = next((prj for prj in prj_list if prj['name'] == args.project), None) @@ -53,7 +53,7 @@ def main(args): copy(src, path) call(['chmod', '-R', '775', path]) - with open(_projects_, 'a') as f: + with open(args.projects, 'a') as f: f.write('[{0}]\n'.format(args.project)) f.write('path={0}\n'.format(path)) f.write('description={0}\n\n'.format(description)) diff --git a/litmus/cmds/cmd_rm.py b/litmus/cmds/cmd_rm.py index 020adaf..1321f9d 100755 --- a/litmus/cmds/cmd_rm.py +++ b/litmus/cmds/cmd_rm.py @@ -16,20 +16,19 @@ import shutil import logging from configparser import RawConfigParser -from litmus import _projects_ def main(args): """docstring for main""" configparser = RawConfigParser() - configparser.read(_projects_) + configparser.read(args.projects) if args.project in configparser.sections(): path = configparser.get(args.project, 'path') shutil.rmtree(path) configparser.remove_section(args.project) - with open(_projects_, 'w') as f: + with open(args.projects, 'w') as f: configparser.write(f) logging.debug('Project {0} is removed'.format(args.project)) else: diff --git a/litmus/cmds/cmd_run.py b/litmus/cmds/cmd_run.py index 74d1930..6332d6f 100755 --- a/litmus/cmds/cmd_run.py +++ b/litmus/cmds/cmd_run.py @@ -19,7 +19,7 @@ from litmus.cmds import load_project_list def main(args): """docstring for main""" - prj_list = load_project_list() + prj_list = load_project_list(args.projects) project = next((prj for prj in prj_list if prj['name'] == args.project), None) if not project: @@ -30,4 +30,5 @@ def main(args): userscript.main(project_name=args.project, project_path=project['path'], param=args.param, - workingdir=args.workingdir) + workingdir=args.workingdir, + topology=args.topology) diff --git a/litmus/core/manager.py b/litmus/core/manager.py index 8c71909..332b8bc 100644 --- a/litmus/core/manager.py +++ b/litmus/core/manager.py @@ -63,7 +63,12 @@ Lightweight test manager for tizen automated testing self.kwargs = kwargs logging.debug(self._comment) - self._load_configs(_duts_) + if 'topology' in self.kwargs and self.kwargs['topology']: + tp = self.kwargs['topology'] + else: + tp = _duts_ + self._load_configs(tp) + if 'project_name' in self.kwargs: self._project_name = self.kwargs['project_name'] if 'project_path' in self.kwargs: diff --git a/litmus/helper/gt.py b/litmus/helper/gt.py index fd2dc4e..a51a13f 100644 --- a/litmus/helper/gt.py +++ b/litmus/helper/gt.py @@ -50,6 +50,8 @@ class generate_topology_sdb_device(object): super(generate_topology_sdb_device, self).__init__() if 'append' in kwargs and kwargs['append']: self.open_mode = 'a+' + if 'topology' in kwargs and kwargs['topology']: + self.topology_path = kwargs['topology'] def init_smartpowers(self): """docstring for init_smartpowers""" @@ -309,12 +311,12 @@ class generate_topology_sdb_device(object): self.close_uarts() -def main(): +def main(topology): """docstring for main""" try: logging.debug('# phase 1 : detect all devices which use sdb') - phase_sdb = generate_topology_sdb_device() + phase_sdb = generate_topology_sdb_device(topology=topology) phase_sdb.run() except KeyboardInterrupt: diff --git a/tools/litmus b/tools/litmus index 709faf5..ef8483b 100644 --- a/tools/litmus +++ b/tools/litmus @@ -175,7 +175,7 @@ def init_confdir(): if not os.path.exists(_projects_): open(_projects_, 'a').close() try: - os.chmod(_duts_, 0o664) + os.chmod(_projects_, 0o664) except PermissionError: logging.debug('Can\'t change projects file permission') @@ -188,6 +188,12 @@ def main(argv=None): parser.add_argument('-V', '--version', action='version', version='%(prog)s ' + __version__) + parser.add_argument('-t', '--topology', + type=str, + help='topology file path') + parser.add_argument('-p', '--projects', + type=str, + help='projects file path') parser.format_usage = parser.format_help subparsers = parser.add_subparsers(title='subcommands', dest='subcommands') @@ -198,6 +204,16 @@ def main(argv=None): obj(subparsers) args = parser.parse_args(argv[1:]) + + if not args.projects: + args.projects = _projects_ + else: + args.projects = os.path.expanduser(args.projects) + if not args.topology: + args.topology = _duts_ + else: + args.topology = os.path.expanduser(args.topology) + module = __import__('litmus.cmds.{0}'.format(args.module), fromlist=[args.module]) return module.main(args)