def cli(project): """ Goto a project's directory """ if not project: move_shell_to(projects_path()) return pro = get(project) if not pro: click.secho('error: project %s does not exists' % project, fg='red', err=True) sys.exit(errno.ENOENT) move_shell_to(pro.folder())
def goto(organization_name): """ Go to the organization directory. """ if organization_name is None: move_shell_to(organization_path) print(organization_path) return if not organization_name.isalnum(): fatal("Your organization name should only contains alphanumeric " "characters.") dest_path = get_env_path(organization_name) if not os.path.exists(dest_path): fatal("The %s organization doesn't exist." % organization_name) move_shell_to(dest_path) print(dest_path)
def goto(inventory_name): """ Go to the inventory directory. """ if inventory_name is None: move_shell_to(inventory_path) print(inventory_path) return if not inventory_name.isalnum(): fatal("Your inventory name should only contains alphanumeric " "characters.") dest_path = os.path.join(inventory_path, inventory_name) if not os.path.exists(dest_path): fatal("The %s inventory doesn't exist." % inventory_name) move_shell_to(dest_path) print(dest_path)
def cli(up, make_cmd, box_name, project_name): """ Allows you to fetch a project from GitHub """ _check_github_config() if not project_name: project = from_cwd() if not project: fatal("""You are not in a project directory. You need to specify what project you want to fetch.""") project_name = project.name() else: project = get(project_name) if not project: _clone_project(project_name) else: _update_project(project) # reload project if created project = get(project_name) # move the user in the project directory move_shell_to(project.folder()) if not project.initialized(): warning('warning: this is not an aeriscloud project, aborting...') sys.exit(1) # make_cmd implies up if make_cmd: up = True box = project.box(box_name) if up: info('AerisCloud will now start your box and provision it, ' 'this op might take a while.') start_box(box) if make_cmd: print(make_cmd) box.ssh_shell('make %s' % make_cmd)
def cli(up, make, box_name, folder): """ Initialize a new AerisCloud project """ if not folder: folderpath = os.getcwd() else: folderpath = os.path.join(os.curdir, folder) relpath = os.path.relpath(folderpath, projects_path()) if relpath[:2] == '..': warning("""You are trying to create a new project in %s which is outside of your projects' directory (%s).""" % (os.path.abspath(folderpath), projects_path())) folder_in_projectpath = os.path.join(projects_path(), folder) if click.confirm("Do you want to create it in %s instead?" % folder_in_projectpath, default=True): folderpath = folder_in_projectpath if not os.path.exists(folderpath): os.makedirs(folderpath) os.chdir(folderpath) git_root = _get_git_root() project = Project(git_root) _ask_project_details(git_root, project) click.echo('\nWriting .aeriscloud.yml ... ', nl=False) project.save() click.echo('done') move_shell_to(project.folder()) if up or make: # Retrieve the proper box box = project.box(box_name) _up(box, make)
def init(name, repository): """ Initialize a new organization. The following usages are supported: cloud organization init <name> <git repository url> \b It will create a new AerisCloud organization and set the origin remote to the specified url. \b If the GitHub integration is enabled, you can also use the following commands: cloud organization init <github organization name> \b It will create a new AerisCloud organization and set the origin remote to [email protected]/<organization>/aeriscloud-organization.git cloud organization init <github organization name>/<project name> \b It will create a new AerisCloud organization and set the origin remote to [email protected]/<organization>/<project>-aeriscloud-organization.git cloud organization init <org name>/<customer>/<project name> \b It will create a new AerisCloud organization and set the origin remote to [email protected]/<organization>/<customer>-<project>-aeriscloud-organization.git """ dirname = '-'.join(name.split('/')) dest_path = get_env_path(dirname) if os.path.exists(dest_path): fatal("The organization %s already exists." % dirname) # If remote is not specified if not repository: # If GH integration is enabled if has_github_integration(): gh = Github() if '/' in name: split = name.split('/') name = split[0] repo_name = '-'.join(split[1:]) + "-aeriscloud-organization" else: repo_name = "aeriscloud-organization" # If member of the organization orgs = [org for org in gh.get_organizations() if org.login.lower() == name.lower()] if orgs: # If repo exists repos = [repo.name for repo in orgs[0].iter_repos() if repo.name.lower() == repo_name.lower()] if not repos: # Give instructions to create the repo info("""The repository {repo} has not been found in the {org} organization. You can create a new repo at the following address: https://github.com/new.""" .format(repo=repo_name, org=name)) if not click.confirm("Do you want to continue?", default=False): info("Aborted. Nothing has been done.") return # If not member of the organization else: warning("We were not able to verify the existence of the " "repository as you don't belong to the {org} " "organization.".format(org=name)) if not click.confirm("Do you want to continue?", default=False): info("Aborted. Nothing has been done.") return repository = "[email protected]:{org}/{repo}.git".format( org=name, repo=repo_name ) else: fatal("You need to specify a repository URL or enable the GitHub " "integration in AerisCloud.") archive_url = "https://github.com/AerisCloud/sample-organization/" \ "archive/master.tar.gz" os.makedirs(dest_path) os.chdir(dest_path) curl(archive_url, o='%s/master.tar.gz' % dest_path, silent=True, location=True) tar = tarfile.open("%s/master.tar.gz" % dest_path, 'r:gz') members = [m for m in tar.getmembers() if '/' in m.name] for m in members: m.name = m.name[m.name.find('/') + 1:] tar.extractall(path=dest_path, members=members) tar.close() os.unlink("%s/master.tar.gz" % dest_path) vgit("init") move_shell_to(dest_path) info("You have been moved to the organization folder.") success("The %s organization has been created." % dirname) run_galaxy_install(dirname) vgit("remote", "add", "origin", repository) info("""You can now manage your organization like a standard git repository. Edit your files, do some commits and push them!""")