~siborgium/src-tree

41af6f110e866fa3067e7526dc7580de1b00ab5e — Sergey Smirnykh 1 year, 3 months ago cad0076
Pretty-printing, some checks
1 files changed, 20 insertions(+), 10 deletions(-)

M src-tree
M src-tree => src-tree +20 -10
@@ 8,7 8,6 @@ import shutil
import sys

def repo_name_from_url(url):
    print(url)
    lastslash = url.rfind('/')
    if lastslash < 0:
        raise Exception('Malformed url')


@@ 55,13 54,14 @@ class SrcTree(object):
    def clone(self):
        parser = argparse.ArgumentParser(
            description='Clone source tree consisting of multiple repos as described by config file')
        parser.add_argument('config')
        parser.add_argument('--root')
        parser.add_argument('config', help = 'Configuration file')
        parser.add_argument('--root', help = 'Source tree root')
        args = parser.parse_args(sys.argv[2:])

        config = parse_config_file(args.config)
      
        root = Path(args.root) if args.root is not None else Path.cwd()
        root = root.absolute()

        for repo in config['repositories']:
            url = repo['url']


@@ 69,23 69,33 @@ class SrcTree(object):
            branch = repo['branch'] if 'branch' in repo else 'trunk'

            cloneto = root / name
            print(f'Cloning \'{cloneto.relative_to(Path.cwd())}\' <- \'{url}\'')
            git.Repo.clone_from(url, cloneto, single_branch = True, branch = branch)

    def link(self):
        parser = argparse.ArgumentParser(
            description='Link build directory of multiple repos as described by config file')
        parser.add_argument('config')
        parser.add_argument('--builddir', required=True)
        parser.add_argument('--targetdir')
        parser.add_argument('--root')
        parser.add_argument('--force', default = False)
        parser.add_argument('config', help = 'Configuration file')
        parser.add_argument('--builddir', required=True, help = 'Build directory name')
        parser.add_argument('--targetdir', help = 'Target directory to which all directories will be linked. Defaults to builddir.')
        parser.add_argument('--root', help = 'Source tree root')
        parser.add_argument('--force', default = False, help = 'Remove builddir along with its contents if it exists')

        args = parser.parse_args(sys.argv[2:])

        config = parse_config_file(args.config)

        root = Path(args.root) if args.root is not None else Path.cwd()
        targetdir = root / (args.targetdir if args.targetdir is not None else args.builddir)
        root = root.absolute()

        if Path(args.builddir).is_absolute():
            raise Exception(f'builddir=\'{args.builddir}\' must be relative')

        targetdir = Path(args.targetdir if args.targetdir is not None else args.builddir)
        if not targetdir.is_absolute():
            targetdir = Path.cwd() / targetdir

        print(f'Creating targetdir=\'{targetdir}\'')
        targetdir.mkdir(parents = True, exist_ok = True)

        for repo in config['repositories']:


@@ 113,8 123,8 @@ class SrcTree(object):
                    print(f'Warning: builddir=\'{dir}\' is not a symlink, removing anyway...', file = sys.stderr)
                    shutil.rmtree(dir)

            print(dir)
            dir.parent.mkdir(parents = True, exist_ok = True)
            print(f'Linking \'{dir.relative_to(Path.cwd())}\' -> \'{targetdir}\'')
            dir.symlink_to(targetdir)