Exemplo n.º 1
0
def logout(ctx, name, **kwargs):
    log.info(f"logout {name}")

    config = ctx.parent.config

    # build repositories list
    repositories = load_repositories(config, prefix)

    repo = None
    for repository in repositories:
        if repository.name == name:
            repo = repository

    if repo is None:
        print(f"{name}: repository not found", file=sys.stderr)
        exit(1)

    service_id = f"army.{name}"

    try:
        repo.logout()
    except Exception as e:
        print_stack()
        log.debug(e)
        print(f"{name}: {e}", file=sys.stderr)
        exit(1)

    print("logged out")
Exemplo n.º 2
0
def repos(ctx, **kwargs):
    log.info(f"repos")

    config = ctx.parent.config

    # build repositories list
    repositories = load_repositories(config, prefix)
    if len(repositories) == 0:
        print("no repository configured")
        return

    column_name = ['name']
    column_type = ['type']
    column_uri = ['uri']

    for r in repositories:
        column_name.append(r.name)
        column_type.append(r.type)
        column_uri.append(r.uri)

    max_name = len(max(column_name, key=len))
    max_type = len(max(column_type, key=len))
    max_uri = len(max(column_uri, key=len))

    if len(column_name) > 0:
        for i in range(len(column_name)):
            print(f"{column_name[i].ljust(max_name, ' ')} | ", end='')
            print(f"{column_type[i].ljust(max_type)} | ", end='')
            print(f"{column_uri[i].ljust(max_uri)}", end='')
            print()
Exemplo n.º 3
0
def publish(ctx, name, force, **kwargs):
    log.info(f"publish")

    config = ctx.parent.config
    project = None
    if os.path.exists('army.toml'):
        try:
            # load project configuration
            project = load_project()
        except Exception as e:
            print_stack()
            log.debug(e)
    if project is None:
        log.info(f"no project loaded")
        exit(1)

    # build repositories list
    repositories = load_repositories(config, prefix)

    repo = None
    for repository in repositories:
        if repository.name == name:
            repo = repository

    if repo is None:
        print(f"{name}: repository not found", file=sys.stderr)
        exit(1)

    if repo.load_credentials() == False:
        print(f"{name}: no credentials found", file=sys.stderr)
        exit(1)

    # package
    try:
        file = project.package(os.getcwd(), 'output')
        print(f"{os.path.relpath(file, os.getcwd())} generated")
    except Exception as e:
        print_stack()
        log.debug(e)
        print(f"packaging failed: {e}")
        exit(1)

    # TODO check version is tagged and files are commited and pushed

    # publish
    try:
        repo.publish(project, file, overwrite=force)
    except Exception as e:
        print_stack()
        log.debug(e)
        print(f"publishing failed: {e}")
        exit(1)

    print(f"{os.path.relpath(file, os.getcwd())} published")
Exemplo n.º 4
0
def search(ctx, name, **kwargs):
    log.info(f"search {name}")
        
    # load configuration
    config = ctx.parent.config
    
    # build repositories list
    repositories = load_repositories(config, prefix)
    packages = []
     
    for r in repositories:
        res = r.search(name)
        if len(res)>0:
            for pkg in res:
                packages.append(res[pkg])

    if len(packages)==0:
        print(f'No matches found for "{name}"', file=sys.stderr)
        return
 
    column_repo = ['repository']
    column_package = ['package']
    column_version = ['version']
    column_description = ['description']
#
    for package in packages:
        column_repo.append(package.repository.name)
        column_package.append(package.name)
        column_version.append(str(package.version))
        column_description.append(package.description)
  
    max_repo = len(max(column_repo, key=len))
    max_package = len(max(column_package, key=len))
    max_version = len(max(column_version, key=len))
    max_description = len(max(column_description, key=len))
  
    for i in range(len(column_repo)):
        print(f"{column_repo[i].ljust(max_repo, ' ')} | ", end='')
        print(f"{column_package[i].ljust(max_package)} | ", end='')
        print(f"{column_version[i].ljust(max_version)} | ", end='')
        print(f"{column_description[i].ljust(max_version)}", end='')
        print()
Exemplo n.º 5
0
def update(ctx, **kwargs):
    log.info(f"update")
    
    config = ctx.parent.config
        
    # build repositories list
    repositories = load_repositories(config, prefix)
    if len(repositories)==0:
        print("no repository configured")
        return 
    
    for r in repositories:
        print(f"update {r.name}")
        try:
            r.update()
        except Exception as e:
            print_stack()
            log.debug(f"{type(e)} {e}")
            print(f"{r.name}: {e}", file=sys.stderr)
    print("updated")
Exemplo n.º 6
0
def login(ctx, name, token, **kwargs):
    log.info(f"login {name}")

    config = ctx.parent.config

    # build repositories list
    repositories = load_repositories(config, prefix)

    repo = None
    for repository in repositories:
        if repository.name == name:
            repo = repository

    if repo is None:
        print(f"{name}: repository not found", file=sys.stderr)
        exit(1)

    if token == True:
        token = getpass.getpass(prompt='token: ', stream=None)
        try:
            repo.login(token=token)
        except Exception as e:
            print_stack()
            log.debug(e)
            print(f"{name}: {e}", file=sys.stderr)
            exit(1)
    else:
        user = input("login: "******"{name}: {e}", file=sys.stderr)
            exit(1)

    print("logged in")
Exemplo n.º 7
0
def uninstall(ctx, name, **kwargs):
    log.info(f"uninstall {name} {kwargs}")

    config = ctx.parent.config

    if len(name) == 0:
        print("nothing to uninstall", file=sys.stderr)
        exit(1)

    # build repositories list
    repositories = load_repositories(config, prefix)

    packages = []

    for package in name:
        pkg = load_installed_package(package, prefix=prefix)
        if pkg is None:
            print(f"{package}: package not installed", file=sys.stderr)
            exit(1)
        packages.append(pkg)

    for package in packages:
        package.uninstall()
Exemplo n.º 8
0
print(f"load test files from {path}")
config = load_configuration(prefix=os.path.join(path, "test_data"))
print("config", config.expand())

# load repository plugin
import army.plugin.repository
from army.plugin.repository.local_git_repository import LocalGitRepository

r1 = LocalGitRepository(name="project1",
                        path=os.path.join(path, "test_data/~/git/project1"))
r1.load()
assert r1.TYPE == "git-local"
assert r1.DEV == True
assert len(r1.packages()) == 1
print(r1.search("project1"))
print(r1.search("project1:1"))

# load test repositories
repositories = load_repositories(config)
print(repositories)

# load search plugin
import army.plugin.package
from army.plugin.package.search import SearchCommand

args = object()
args.NAME = "project1"
c1 = SearchCommand(None)
c1.execute(config, args)
Exemplo n.º 9
0
def install(ctx, name, link, reinstall, **kwargs):
    log.info(f"install {name} {kwargs}")
    
    _global = kwargs['global']  # not in parameters due to conflict with global keywoard
    
    # load configuration
    config = ctx.parent.config
    
    # load project
    project = ctx.parent.project
    if project is None:
        log.info(f"no project loaded")

    if len(name)==0 and project is None:
        print("nothing to install", file=sys.stderr)
        exit(1)
        
    # build repositories list
    repositories = load_repositories(config, prefix)
    
    for repository in repositories:
        if repository.load_credentials()==False:
            print(f"{repository.name}: warning: load credentials failed, update may fail due to rate limitation", file=sys.stderr)
        
    packages = []

    if len(name)==0:
        if project is None:
            log.error(f"{os.getcwd()}: army.toml not found")
            exit(1)

        # get target config
        target = ctx.parent.target
#         if target is None:
#             print(f"no target specified", file=sys.stderr)
#             exit(1)

        for package in project.dependencies:
            pkg, repo = _find_package(package, project.dependencies[package], repositories, priority_dev=link)
            packages.append(PackageDependency(package=pkg, repository=repo))

        if target is not None:
            for package in target.dependencies:
                pkg, repo = _find_package(package, target.dependencies[package], repositories, priority_dev=link)
                packages.append(PackageDependency(package=pkg, repository=repo))
            
        for plugin in project.plugins:
            pkg, repo = _find_package(plugin, project.plugins[plugin], repositories, plugin=True, priority_dev=link)
            packages.append(PackageDependency(package=pkg, repository=repo))
        
        if target is not None:
            for plugin in target.plugins:
                pkg, repo = _find_package(plugin, target.plugins[plugin], repositories, plugin=True, priority_dev=link)
                packages.append(PackageDependency(package=pkg, repository=repo))
    else:
        for package in name:
            if '@' in package:
                chunks = package.split('@')
                if len(chunks)==3:
                    package = f"{chunks[0]}@{chunks[1]}"
                    version = chunks[2]
                elif len(chunks)==2:
                    try:
                        # check if version is valid
                        test_version = VersionRange(chunks[1], ["0.0.0"])
                        package, version = chunks
                    except:
                        version = 'latest'
                else:
                    print(f"{package}: naming error", file=sys.stderr)
                    exit(1)
            else:
                version = 'latest'
            pkg, repo = _find_package(package, version, repositories, priority_dev=link)
            packages.append(PackageDependency(package=pkg, repository=repo))

    # locate install folder
    if _global:
        path = os.path.join(prefix or "", "~/.army/dist/")
    else:
        path = "dist"
    
    force = False
    if reinstall:
        force = True

    dependencies = []
    while(len(packages)>0):
        # get dependencies from top level package to end level
        package_dep = packages.pop(0)
        package = package_dep.package

        # dependency treated ok, append to list
        dependencies.append(package_dep)
        
        # append dependencies to list
        for dependency in package.dependencies:
            pkg, repo = _find_package(dependency, package.dependencies[dependency], repositories, priority_dev=link)
            dep_pkg = PackageDependency(package=pkg, repository=repo, from_package=package)
            packages.append(dep_pkg)

        # append plugins to list
        for plugin in package.plugins:
            pkg, repo = _find_package(plugin, package.plugins[plugin], repositories, priority_dev=link)
            dep_pkg = PackageDependency(package=pkg, repository=repo, from_package=package)
            packages.append(dep_pkg)

    # treat dependencies first
    dependencies.reverse()

    log.debug(f"packages: {dependencies}")
    
    # TODO checks
    _check_dependency_version_conflict(dependencies)
    _check_installed_version_conflict(dependencies)
    
    # clean dependency duplicates to avoid installing several times same package
    dependencies = _remove_duplicates(dependencies)

    # install
    for dependency in dependencies:
        install = False
        installed_package = load_installed_package(dependency.package.name, prefix=prefix)
        if installed_package:
            if force==True:
                print(f"reinstall {dependency.package}")
                install = True
            else:
                print(f"package {dependency.package} already installed", file=sys.stderr)
                install = False
        else:
            install = True
            print(f"install package {dependency.package}")
            
        if install==True:
            if link==True and dependency.repository.DEV==False:
                print(f"{dependency.package.name}: repository is not local, link not applied", file=sys.stderr)
            if dependency.repository.DEV==True:
                dependency.package.install(path=os.path.join(path, dependency.package.name), link=link)
            else:
                # link mode is only possible with repository DEV
                dependency.package.install(path=os.path.join(path, dependency.package.name), link=False)