Exemplo n.º 1
0
def cfg_path_ini_test():
    lp = PathParser()
    ini_dict = {
        "volumes": {
            "sys": "~/.vamos/sys",
            "work": "~/amiga/work",
            "home": "~"
        },
        "assigns": {
            "c": "sys:c+sc:c",
            "libs": "sys:libs",
            "devs": "sys:devs"
        },
        "path": {
            "path": "c:,work:c",
            "cwd": "~/amiga"
        }
    }
    lp.parse_config(ini_dict, 'ini')
    assert lp.get_cfg_dict() == {
        "volumes": {
            "sys": "~/.vamos/sys",
            "work": "~/amiga/work",
            "home": "~"
        },
        "assigns": {
            "c": ["sys:c", "sc:c"],
            "libs": ["sys:libs"],
            "devs": ["sys:devs"]
        },
        "path": {
            "command": ["c:", "work:c"],
            "cwd": "~/amiga"
        }
    }
Exemplo n.º 2
0
def cfg_path_ini_test():
    lp = PathParser()
    ini_dict = {
        "volumes": [["sys", "~/.vamos/sys"], ["work", "~/amiga/work"],
                    ["home", "~"]],
        "assigns": [["c", "sys:c,sc:c,home:c"], ["libs", "sys:libs"],
                    ["devs", "sys:devs"]],
        "path": {
            "path": "c:,work:c",
            "cwd": "~/amiga",
            "auto_volumes": ['a', 'b'],
            "auto_assigns": ['c', 'd']
        }
    }
    lp.parse_config(ini_dict, 'ini')
    assert lp.get_cfg_dict() == {
        "volumes": ["sys:~/.vamos/sys", "work:~/amiga/work", "home:~"],
        "assigns": ["c:sys:c+sc:c+home:c", "libs:sys:libs", "devs:sys:devs"],
        "path": {
            "command": ["c:", "work:c"],
            "cwd": "~/amiga",
            "vols_base_dir": "~/.vamos/volumes",
            "auto_volumes": ['a', 'b'],
            "auto_assigns": ['c', 'd']
        }
    }
Exemplo n.º 3
0
def cfg_path_ini_args_test():
    lp = PathParser()
    ini_dict = {
        "volumes": [
            ["sys", "~/.vamos/sys"],
        ],
        "assigns": [
            ["c", "sys:c"],
            ["libs", "sys:libs"],
        ],
        "path": {
            "path": "c:",
            "cwd": "~/amiga",
            "auto_volumes": ["a"],
            "auto_assigns": ["x"],
        },
    }
    lp.parse_config(ini_dict, "ini")
    ap = argparse.ArgumentParser()
    lp.setup_args(ap)
    args = ap.parse_args([
        "-p",
        "work:c",
        "-p",
        "sys:t",
        "--cwd",
        "~/amiga",
        "-a",
        "c:sc:c",
        "-a",
        "c:work:c",
        "-a",
        "devs:sys:devs",
        "-V",
        "work:~/amiga/work",
        "-V",
        "home:~",
        "-V",
        "local:",
        "--vols-base-dir",
        "/bla",
        "--auto-volumes",
        "b,c",
        "--auto-assigns",
        "y,z",
    ])
    lp.parse_args(args)
    assert lp.get_cfg_dict() == {
        "volumes":
        ["sys:~/.vamos/sys", "work:~/amiga/work", "home:~", "local:"],
        "assigns":
        ["c:sys:c", "libs:sys:libs", "c:sc:c", "c:work:c", "devs:sys:devs"],
        "path": {
            "command": ["c:", "work:c", "sys:t"],
            "cwd": "~/amiga",
            "vols_base_dir": "/bla",
            "auto_volumes": ["a", "b", "c"],
            "auto_assigns": ["x", "y", "z"],
        },
    }
Exemplo n.º 4
0
def cfg_path_ini_empty_test():
    lp = PathParser()
    ini_dict = {}
    lp.parse_config(ini_dict, 'ini')
    assert lp.get_cfg_dict() == {
        "volumes": None,
        "assigns": None,
        "path": {
            "command": None,
            "cwd": None,
            "vols_base_dir": "~/.vamos/volumes",
            "auto_assigns": None,
            "auto_volumes": None
        }
    }
Exemplo n.º 5
0
def cfg_path_args_test():
    lp = PathParser()
    ap = argparse.ArgumentParser()
    lp.setup_args(ap)
    args = ap.parse_args([
        '-p', 'c:,work:c', '--cwd', '~/amiga', '-a',
        'c:sys:c+sc:c,libs:sys:libs', '-a', 'devs:sys:devs', '-V',
        'sys:~/.vamos/sys', '-V', 'work:~/amiga/work,home:~'
    ])
    lp.parse_args(args)
    assert lp.get_cfg_dict() == {
        "volumes": {
            "sys": "~/.vamos/sys",
            "work": "~/amiga/work",
            "home": "~"
        },
        "assigns": {
            "c": ["sys:c", "sc:c"],
            "libs": ["sys:libs"],
            "devs": ["sys:devs"]
        },
        "path": {
            "command": ["c:", "work:c"],
            "cwd": "~/amiga"
        }
    }
Exemplo n.º 6
0
class PathTool(Tool):
  def __init__(self):
    Tool.__init__(self, "path", "path conversion utilities")
    self.path_parser = None
    self.path_mgr = None

  def add_parsers(self, main_parser):
    self.path_parser = PathParser()
    main_parser.add_parser(self.path_parser)

  def add_args(self, arg_parser):
    sub = arg_parser.add_subparsers(dest='path_cmd')
    # ami2sys
    a2s_parser = sub.add_parser('ami2sys',
                                help='convert Amiga to system path')
    a2s_parser.add_argument('input', help='input path')
    # sys2ami
    s2a_parser = sub.add_parser('sys2ami',
                                help='convert system to Amiga path')
    s2a_parser.add_argument('input', help='input path')

  def setup(self, args):
    self.path_mgr = VamosPathManager()
    cfg_dict = self.path_parser.get_cfg_dict()
    ok = self.path_mgr.parse_config(cfg_dict)
    if not ok:
      return False
    return self.path_mgr.setup()

  def shutdown(self):
    self.path_mgr.shutdown()

  def get_path_mgr(self):
    return self.path_mgr

  def run(self, args):
    cmd = args.path_cmd
    try:
      if cmd == 'ami2sys':
        res = self.path_mgr.to_sys_path(args.input)
        return self._report_path(res)
      elif cmd == 'sys2ami':
        res = self.path_mgr.from_sys_path(args.input)
        return self._report_path(res)
    except AmiPathError as e:
      print(str(e), file=sys.stderr)
      return 1

  def _report_path(self, path):
    if path is None:
      print("path not found!", file=sys.stderr)
      return 1
    else:
      print(path)
      return 0
Exemplo n.º 7
0
class PathTool(Tool):
    def __init__(self):
        Tool.__init__(self, "path", "path conversion utilities")
        self.path_parser = None
        self.path_mgr = None

    def add_parsers(self, main_parser):
        self.path_parser = PathParser()
        main_parser.add_parser(self.path_parser)

    def add_args(self, arg_parser):
        sub = arg_parser.add_subparsers(dest='path_cmd')
        # ami2sys
        a2s_parser = sub.add_parser('ami2sys',
                                    help='convert Amiga to system path')
        a2s_parser.add_argument('input', help='input path')
        # sys2ami
        s2a_parser = sub.add_parser('sys2ami',
                                    help='convert system to Amiga path')
        s2a_parser.add_argument('input', help='input path')

    def setup(self, args):
        self.path_mgr = VamosPathManager()
        cfg_dict = self.path_parser.get_cfg_dict()
        ok = self.path_mgr.parse_config(cfg_dict)
        if not ok:
            return False
        return self.path_mgr.setup()

    def shutdown(self):
        self.path_mgr.shutdown()

    def get_path_mgr(self):
        return self.path_mgr

    def run(self, args):
        cmd = args.path_cmd
        try:
            if cmd == 'ami2sys':
                res = self.path_mgr.to_sys_path(args.input)
                return self._report_path(res)
            elif cmd == 'sys2ami':
                res = self.path_mgr.from_sys_path(args.input)
                return self._report_path(res)
        except AmiPathError as e:
            print(str(e), file=sys.stderr)
            return 1

    def _report_path(self, path):
        if path is None:
            print("path not found!", file=sys.stderr)
            return 1
        else:
            print(path)
            return 0
Exemplo n.º 8
0
def cfg_path_ini_args_test():
    lp = PathParser()
    ini_dict = {
        "volumes": [
            ["sys", "~/.vamos/sys"],
        ],
        "assigns": [
            ["c", "sys:c"],
            ["libs", "sys:libs"],
        ],
        "path": {
            "path": "c:",
            "cwd": "~/amiga",
            "auto_volumes": ['a'],
            "auto_assigns": ['x']
        }
    }
    lp.parse_config(ini_dict, 'ini')
    ap = argparse.ArgumentParser()
    lp.setup_args(ap)
    args = ap.parse_args([
        '-p', 'work:c', '-p', 'sys:t', '--cwd', '~/amiga', '-a', 'c:sc:c',
        '-a', 'c:work:c', '-a', 'devs:sys:devs', '-V', 'work:~/amiga/work',
        '-V', 'home:~', '-V', 'local:', '--vols-base-dir', '/bla',
        '--auto-volumes', 'b,c', '--auto-assigns', 'y,z'
    ])
    lp.parse_args(args)
    assert lp.get_cfg_dict() == {
        "volumes":
        ["sys:~/.vamos/sys", "work:~/amiga/work", "home:~", "local:"],
        "assigns":
        ["c:sys:c", "libs:sys:libs", "c:sc:c", "c:work:c", "devs:sys:devs"],
        "path": {
            "command": ["c:", "work:c", "sys:t"],
            "cwd": "~/amiga",
            "vols_base_dir": "/bla",
            "auto_volumes": ['a', 'b', 'c'],
            "auto_assigns": ['x', 'y', 'z']
        }
    }
Exemplo n.º 9
0
def cfg_path_args_test():
    lp = PathParser()
    ap = argparse.ArgumentParser()
    lp.setup_args(ap)
    args = ap.parse_args([
        "-p",
        "c:,work:c",
        "--cwd",
        "~/amiga",
        "-a",
        "c:sys:c+sc:c,libs:sys:libs",
        "-a",
        "devs:sys:devs",
        "-V",
        "sys:~/.vamos/sys",
        "-V",
        "work:~/amiga/work,home:~",
        "-V",
        "local:",
        "--auto-volumes",
        "a,b",
        "--auto-assigns",
        "c,d",
        "--vols-base-dir",
        "/bla",
    ])
    lp.parse_args(args)
    assert lp.get_cfg_dict() == {
        "volumes":
        ["sys:~/.vamos/sys", "work:~/amiga/work", "home:~", "local:"],
        "assigns": ["c:sys:c+sc:c", "libs:sys:libs", "devs:sys:devs"],
        "path": {
            "command": ["c:", "work:c"],
            "cwd": "~/amiga",
            "vols_base_dir": "/bla",
            "auto_volumes": ["a", "b"],
            "auto_assigns": ["c", "d"],
        },
    }
Exemplo n.º 10
0
def cfg_path_args_test():
    lp = PathParser()
    ap = argparse.ArgumentParser()
    lp.setup_args(ap)
    args = ap.parse_args([
        '-p', 'c:,work:c', '--cwd', '~/amiga', '-a',
        'c:sys:c+sc:c,libs:sys:libs', '-a', 'devs:sys:devs', '-V',
        'sys:~/.vamos/sys', '-V', 'work:~/amiga/work,home:~', '-V', 'local:',
        '--auto-volumes', 'a,b', '--auto-assigns', 'c,d', '--vols-base-dir',
        '/bla'
    ])
    lp.parse_args(args)
    assert lp.get_cfg_dict() == {
        "volumes":
        ["sys:~/.vamos/sys", "work:~/amiga/work", "home:~", "local:"],
        "assigns": ["c:sys:c+sc:c", "libs:sys:libs", "devs:sys:devs"],
        "path": {
            "command": ["c:", "work:c"],
            "cwd": "~/amiga",
            "vols_base_dir": "/bla",
            "auto_volumes": ['a', 'b'],
            "auto_assigns": ['c', 'd']
        }
    }
Exemplo n.º 11
0
 def add_parsers(self, main_parser):
   self.path_parser = PathParser()
   main_parser.add_parser(self.path_parser)
Exemplo n.º 12
0
 def add_parsers(self, main_parser):
     self.path_parser = PathParser()
     main_parser.add_parser(self.path_parser)