Example #1
0
def command(args):
    import sys

    from sr.tools.inventory import assetcode
    from sr.tools.inventory.inventory import get_inventory

    inv = get_inventory()

    parts = []
    for c in args.part_code:
        code = assetcode.normalise(c)

        try:
            assetcode.code_to_num(code)
        except:
            print("Error: %s is an invalid code." % code, file=sys.stderr)
            sys.exit(1)

        try:
            part = inv.root.parts[code]
        except KeyError:
            print("Error: There is no part with code %s." % code,
                  file=sys.stderr)
            sys.exit(1)

        parts.append(part)

    for part in parts:
        print("# item -> parent")

        if hasattr(part.parent, "code"):
            print("%s -> %s" % (part.code, part.parent.code))

        elif hasattr(part.parent, "name"):
            print("%s -> dir(%s)" % (part.code, part.parent.name))
Example #2
0
def command(args):
    import sys

    from sr.tools.inventory import assetcode
    from sr.tools.inventory.inventory import get_inventory
    from sr.tools.environment import open_editor

    inv = get_inventory()

    parts = []
    for c in args.part_code:
        code = assetcode.normalise(c)

        try:
            assetcode.code_to_num(code)
        except:
            print("Error: %s is an invalid code." % code, file=sys.stderr)
            sys.exit(1)

        try:
            part = inv.root.parts[code]
        except KeyError:
            print("Error: There is no part with code %s." %
                  code, file=sys.stderr)
            sys.exit(1)

        parts.append(part)

    for part in parts:
        open_editor(part.path)
Example #3
0
def command(args):
    import sys

    from sr.tools.inventory import assetcode
    from sr.tools.inventory.inventory import get_inventory
    from sr.tools.environment import open_editor

    inv = get_inventory()

    parts = []
    for c in args.part_code:
        code = assetcode.normalise(c)

        try:
            assetcode.code_to_num(code)
        except:
            print("Error: %s is an invalid code." % code, file=sys.stderr)
            sys.exit(1)

        try:
            part = inv.root.parts[code]
        except KeyError:
            print("Error: There is no part with code %s." % code,
                  file=sys.stderr)
            sys.exit(1)

        parts.append(part)

    for part in parts:
        open_editor(part.path)
Example #4
0
def command(args):
    import sys

    from sr.tools.inventory import assetcode
    from sr.tools.inventory.inventory import get_inventory

    inv = get_inventory()

    parts = []
    for c in args.part_code:
        code = assetcode.normalise(c)

        try:
            assetcode.code_to_num(code)
        except:
            print("Error: %s is an invalid code." % code, file=sys.stderr)
            sys.exit(1)

        try:
            part = inv.root.parts[code]
        except KeyError:
            print("Error: There is no part with code %s." %
                  code, file=sys.stderr)
            sys.exit(1)

        parts.append(part)

    for part in parts:
        print("# item -> parent")

        if hasattr(part.parent, "code"):
            print("%s -> %s" % (part.code, part.parent.code))

        elif hasattr(part.parent, "name"):
            print("%s -> dir(%s)" % (part.code, part.parent.name))
Example #5
0
def command(args):
    import os
    import subprocess
    import sys

    from sr.tools.inventory import assetcode
    from sr.tools.inventory.inventory import get_inventory

    inv = get_inventory()
    cwd = os.getcwd()

    parts = []
    for c in args.assetcodes:
        code = assetcode.normalise(c)

        try:
            assetcode.code_to_num(code)
        except:
            print("Error: {} is an invalid asset code.".format(c),
                  file=sys.stderr)
            sys.exit(1)

        try:
            part = inv.root.parts[code]
        except:
            print("Error: There is no part with code {}.".format(code),
                  file=sys.stderr)
            sys.exit(1)

        if part.parent.path == cwd:
            print("Warning: Part {} is already in {}.".format(code, cwd))
            continue

        if hasattr(part.parent, "code"):
            if args.assy:
                parts.append(part.parent)
            else:
                print("Warning: Part {} is in an assembly.".format(code),
                      "To move the assembly, use the -a switch.",
                      file=sys.stderr)
                parts.append(part)

        else:
            parts.append(part)

    if parts:
        paths = [x.path for x in parts]
        subprocess.check_call(['git', 'mv'] + paths + ['.'])
    else:
        print("Warning: No parts to move", file=sys.stderr)
Example #6
0
def command(args):
    import sys

    from sr.tools.inventory import assetcode
    from sr.tools.inventory.inventory import get_inventory

    inv = get_inventory()

    for code in args.asset:
        part = inv.root.parts[assetcode.normalise(code)]
        if part is not None:
            replace_line(part.path, args.attrname, args.attrvalue)
        else:
            print("Could not find asset:", code, file=sys.stderr)
            sys.exit(1)
Example #7
0
def command(args):
    import sys

    from sr.tools.inventory import assetcode
    from sr.tools.inventory.inventory import get_inventory

    inv = get_inventory()

    for code in args.asset:
        part = inv.root.parts[assetcode.normalise(code)]
        if part is not None:
            replace_line(part.info_path, args.attrname, args.attrvalue)
        else:
            print("Could not find asset:", code, file=sys.stderr)
            sys.exit(1)
Example #8
0
def command(args):
    import pydoc
    import subprocess

    from sr.tools.inventory import assetcode
    from sr.tools.inventory.inventory import get_inventory

    inv = get_inventory()

    partcode = assetcode.normalise(args.partcode)
    part = inv.root.parts[partcode]

    pager_text = "Full path: " + part.path + '\n'
    with open(part.info_path, 'r') as info_file:
        pager_text += info_file.read() + '\n'

    pager_text += "Log\n===\n"
    pager_text += subprocess.check_output(['git', '--no-pager', 'log',
                                           '--color', '--follow', '-C', '-M',
                                           part.path],
                                          universal_newlines=True)

    pydoc.pager(pager_text)
Example #9
0
def command(args):
    import pydoc
    import subprocess

    from sr.tools.inventory import assetcode
    from sr.tools.inventory.inventory import get_inventory

    inv = get_inventory()

    partcode = assetcode.normalise(args.partcode)
    part = inv.root.parts[partcode]

    pager_text = "Full path: " + part.path + '\n'
    with open(part.info_path, 'r') as info_file:
        pager_text += info_file.read() + '\n'

    pager_text += "Log\n===\n"
    pager_text += subprocess.check_output([
        'git', '--no-pager', 'log', '--color', '--follow', '-C', '-M',
        part.path
    ],
                                          universal_newlines=True)

    pydoc.pager(pager_text)
Example #10
0
 def test_normal(self):
     codes = [('sr43', '43'), ('SRff3', 'FF3'), ('  srabc  ', 'ABC')]
     for input_code, output_code in codes:
         self.assertEqual(assetcode.normalise(input_code), output_code)
Example #11
0
def command(args):
    import os
    import sys

    from sr.tools.inventory import assetcode
    from sr.tools.inventory.inventory import get_inventory

    ASSET_CODE = 0
    PART_TYPE = 1

    COLOUR_RESET = "\033[0m"
    COLOUR_GREEN = "\033[1;32m"
    COLOUR_RED = "\033[1;31m"
    COLOUR_YELLOW = "\033[1;33m"

    inv = get_inventory()

    parts = []
    spec_type = ASSET_CODE
    for c in args.itemspecs:
        code = assetcode.normalise(c)

        try:
            assetcode.code_to_num(code)
            spec_type = ASSET_CODE
        except:
            if c in inv.root.types:
                spec_type = PART_TYPE
            else:
                print("Error: %s is an invalid asset code or part type." %
                      c, file=sys.stderr)
                sys.exit(1)

        if spec_type == ASSET_CODE:
            try:
                part = inv.root.parts[code]
            except KeyError:
                print("Error: There is no part with code %s." %
                      code, file=sys.stderr)
                sys.exit(1)

            parts.append(part)
        else:
            try:
                parts.extend(inv.root.types[c])
            except:
                print("Error: There is no part type %s." % c, file=sys.stderr)
                sys.exit(1)

    stat_colour = ""
    path = ""
    for part in parts:
        if args.relpath:
            path = os.path.relpath(part.path)
        else:
            path = part.path

        if args.asset_stat and hasattr(part, "condition"):
            if part.condition == "broken":
                stat_colour = COLOUR_RED
            elif part.condition == "unknown":
                stat_colour = COLOUR_YELLOW
            elif part.condition == "working":
                stat_colour = COLOUR_GREEN
            print(path, stat_colour, part.condition, COLOUR_RESET)
        else:
            print(path)