> == added file 'lava/device/commands.py' > -- lava/device/commands.py 1970-01-01 00:00:00 +0000 > ++ lava/device/commands.py 2013-06-12 13:21:33 +0000 > @ -0,0 +1,237 @@ [snip] > # Default lava-dispatcher paths. > DEFAULT_DISPATCHER_PATH = os.path.join("etc", "lava-dispatcher") > USER_DISPATCHER_PATH = os.path.join(os.path.expanduser("~"), ".config", > "lava-dispatcher") It would be better to from lava_dispatcher.import user_config_path, system_config_path and use those instead, so you don't need to duplicate the logic here. We don't want to make the dispatcher a hard dependency of lava-tool, but if we don't have the dispatcher available, just fail the entire thing. > # Default devices path, has to be joined with the dispatcher path. > DEFAULT_DEVICES_PATH = "devices" > DEVICE_FILE_SUFFIX = "conf" > > > class device(CommandGroup): > """LAVA devices handling.""" > > namespace = "lava.device.commands" > > > class BaseCommand(Command): > """Base command for device commands.""" > def __init__(self, parser, args): > super(BaseCommand, self).__init__(parser, args) > self.config = InteractiveConfig( > force_interactive=self.args.interactive) > > @classmethod > def register_arguments(cls, parser): > super(BaseCommand, cls).register_arguments(parser) > parser.add_argument("-i", "--interactive", > action='store_true', > help=("Forces asking for input parameters even if " > "we already have them cached.")) > > @classmethod > def _get_dispatcher_paths(cls): > """Tries to get the dispatcher from lava-dispatcher.""" > global_paths = [] > try: > from lava_dispatcher.config import search_path > > global_paths += search_path() > except ImportError: > print >> sys.stderr, "Cannot import lava_dispatcher." Right here. We should baild out if the dispatcher is not available for device management. After all without a local dispatcher there is no point in managing devices. > return global_paths > > @classmethod > def _choose_dispatcher_path(cls, paths): > """Lets the user choose the path to use. > > :param paths: A list of paths. > :return The path at the user selected index. > """ > print >> sys.stdout, ("Multiple dispatcher paths found. Please " > "select one between:\n") > out_list = [] > len_paths = range(1, len(paths) + 1) > for index, dispatcher_path in zip(len_paths, paths): > out_list.append("\t{0}. {1}\n".format(index, dispatcher_path)) > print >> sys.stdout, "".join(out_list) > while True: > try: > choice = raw_input("Dispatcher path to use: ").strip() > if choice in [str(x) for x in len_paths]: > return paths[int(choice) - 1] > else: > continue > except KeyboardInterrupt: > sys.exit(-1) I think we should not give too many options here: if the user is capable of choosing the right directory to write to, he doesn't need lava-tool to do it for him; he would just create a file with $EDITOR there. Instead of this, I think you should assume that dispatcher branch of mine, and use the following strategy: 1) finding where to create a new configurarion file: the first of [system_dispatcher_path, user_config_path] that is writable 2) finding an existing configuration file to edit: from lava_dispatcher.config import get_config_file [...] conf_file = get_config_file("devices/%s.conf", device_name) if conf_file: # edit else: print("No device %s found" % device_name) exit(-1) I think that doing this will simplify a lot things in this file. > == added file 'lava/device/templates.py' > -- lava/device/templates.py 1970-01-01 00:00:00 +0000 > ++ lava/device/templates.py 2013-06-12 13:21:33 +0000 > @ -0,0 +1,40 @@ > # Copyright (C) 2013 Linaro Limited > # > # Author: Milo Casagrande