def cli(force): """ Update AerisCloud """ if not force and config.get('github', 'enabled', default=False) == 'true': client = Github().gh repo = client.repository('aeriscloud', 'aeriscloud') latest_release = repo.iter_releases().next() latest_version = latest_release.tag_name[1:] if semver.compare(version, latest_version) != -1: click.secho('AerisCloud is already up to date!', fg='green') sys.exit(0) click.echo('A new version of AerisCloud is available: %s (%s)' % ( click.style(latest_version, fg='green', bold=True), click.style(latest_release.name, bold=True) )) # retrieve install script in a tmpfile tmp = tempfile.NamedTemporaryFile() r = requests.get('https://raw.githubusercontent.com/' + 'AerisCloud/AerisCloud/develop/scripts/install.sh') if r.status_code != 200: fatal('error: update server returned %d (%s)' % ( r.status_code, r.reason)) tmp.write(r.content) tmp.flush() os.environ['INSTALL_DIR'] = aeriscloud_path call(['bash', tmp.name]) tmp.close()
def cli(box, provision_with): """ Starts the given box and provision it """ try: return start_box(box, provision_with) except HTTPError as e: fatal(e.message)
def _deco(ctx, *args, **kwargs): if not expose.enabled(): click.secho('warning: aeris.cd is not enabled', fg='yellow') sys.exit(1) try: return ctx.invoke(func, *args, **kwargs) except HTTPError as e: fatal(e.message)
def status(): """ Check the status of the expose server """ if expose.enabled(): success('Expose is running') else: fatal('Expose is stopped')
def announce(): """ Announce all the running services """ res = expose.announce() if res: success(res) else: fatal('Expose is not available or misconfigured')
def _check_github_config(): if config.get('github', 'enabled', default='false') == 'false': if click.confirm('GitHub configuration is missing, do you want to ' 'run the config assistant?', default=True): config.set('github', 'enabled', 'true') assistant() if not config.has('github', 'token'): fatal('error: github is not configured')
def _build(project_type, platform, **kwargs): info("Building {project} project for {platform}.".format( project=bold(project_type), platform=bold(platform))) if project_type == 'Unity': _build_unity(platform, kwargs['unity']) else: fatal("Unsupported project type.")
def stop(): """ Stop the expose server """ expose.stop() if not expose.enabled(): success('Expose stopped') else: fatal('Expose could not stop')
def start(): """ Start the expose server """ expose.start() if expose.enabled(): success('Expose started') else: fatal('Expose could not start')
def _update_rsync_uri(inventory, uri): if ':' not in uri: return uri, [] hostname, path = uri.split(':') try: host = ACHost(inventory, hostname) except NameError as e: fatal(e.message) return ':'.join([host.ssh_host(), path])
def update_organization(name, dest_path): click.echo('We will update the %s organization' % name) os.chdir(dest_path) if os.path.exists(os.path.join(dest_path, '.git')): try: vgit('pull') except ErrorReturnCode: fatal("Unable to update the organization %s." % name) success("The %s organization has been updated." % name) run_galaxy_install(name)
def update_inventory(name, dest_path): if not os.path.exists(os.path.join(dest_path, '.git')): warning("The %s inventory is not a git repository and has not " "been updated." % name) return click.echo('We will update the %s inventory' % name) os.chdir(dest_path) try: vgit('pull') except ErrorReturnCode: fatal("Unable to update the inventory %s." % name) success("The %s inventory has been updated." % name)
def update(): for inventory in os.listdir(inventory_path): if not os.path.exists(os.path.join(inventory_path, inventory, '.git')): info("Skip %s" % inventory) continue info("Updating %s ..." % inventory) os.chdir(os.path.join(inventory_path, inventory)) try: vgit('pull') except ErrorReturnCode: fatal("Unable to update the inventories.") success("All the inventories have been updated.")
def _get_git_root(): """ Retrieve the git directory, or prompt to create one if not found """ git_root = None try: git_root = str(git('rev-parse', '--show-toplevel')).strip() except ErrorReturnCode as e: if e.exit_code != 128: fatal(e.message, e.exit_code) if not git_root: warning('You must be in a git repository directory to ' 'initialize a new project.') if not click.confirm('Do you want to create a new git ' 'repository here?', default=True): fatal('Please run %s' % style('git init', bold=True)) try: vgit('init') git_root = os.getcwd() except ErrorReturnCode as e: fatal('An error occurred when trying to initialize a ' 'new repo.', e.exit_code) if git_root == aeriscloud_path: fatal('You cannot init AerisCloud from the AerisCloud directory!') return git_root
def _build_unity(platform, unity_path): methods = { 'ios': 'BuildEditorScript.PerformiOSBuild', 'android': 'BuildEditorScript.PerformAndroidBuild', 'osx': 'BuildEditorScript.PerformMacOSXBuild' } if platform not in methods: fatal("Unsupported platform.") unity_path = os.path.join(unity_path, "Unity.app/Contents/MacOS/Unity") command = "{unity_path} -quit -batchmode " \ "-executeMethod {method} " \ "-logFile ./build.log " \ "-projectPath {current_dir}" \ .format(unity_path=quote(unity_path), method=methods[platform], current_dir=quote(os.getcwd())) info("""The following command will be executed: {0}.""".format(bold(command))) returncode = subprocess32.call(command, shell=True) if returncode != 0: error("An error occurred, please check the content " "of the {0} log file.".format(bold('build.log'))) sys.exit(returncode) if platform == 'ios': os.chdir(os.path.join(os.getcwd(), 'Build', 'iPhone')) command = "xcodebuild -scheme Unity-iPhone archive " \ "-archivePath Unity-iPhone.xcarchive" info("""The following command will be executed: {0}.""".format(bold(command))) subprocess32.check_call(command, shell=True) command = "xcodebuild -exportArchive " \ "-exportFormat ipa " \ "-archivePath \"Unity-iPhone.xcarchive\" " \ "-exportPath \"Unity-iPhone.ipa\" " \ "-exportProvisioningProfile \"wildcard_Development\"" info("""The following command will be executed: {0}.""".format(bold(command))) subprocess32.check_call(command, shell=True) success(""" Your project has been built. """)
def _up(box, make): click.echo('\nStarting box %s\n' % style(box.name(), bold=True)) if not box.is_running(): start_box(box) else: box.vagrant('provision') if make: click.echo('\nRunning make %s in your box\n' % style(make, bold=True)) if box.ssh_shell('make %s' % make) != 0: fatal('make command failed!') if sync(box, 'down') is False: # sync failed, message should already be displayed, exit sys.exit(1)
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 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 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 _update_rsync_uri(inventory, uri): if ':' not in uri: return uri, None hostname, path = uri.split(':') user = None if '@' in hostname: (user, hostname) = hostname.split('@', 1) try: host = ACHost(inventory, hostname) except NameError as e: fatal(e.message) new_uri = '@'.join(filter(None, [ user, ':'.join([host.ssh_host(), path]) ])) return new_uri, host.variables()
def _ask_project_details(git_root, project): if not project.initialized(): (app_name, organization, app_id) = _ask_general_info(git_root) services = _ask_services(organization) basebox, basebox_url = _ask_basebox() project.set_name(app_name) project.set_organization(organization) project.set_id(app_id) project.add_box({ 'basebox': basebox }, basebox_url) else: if not click.confirm('There is already a project configured in this ' 'folder, do you want to modify it\'s config?'): fatal('aborting') services = _ask_services(project.organization(), project.services()) project.set_services(services)
def install(name, path): """ Install inventories. """ if not name: update() return if not name.isalnum(): fatal("Your inventory name should only contains alphanumeric " "characters.") dest_path = os.path.join(inventory_path, name) if os.path.exists(dest_path): update_inventory(name, dest_path) return if not path: fatal("You must specify a path to a local directory or an URL to a " "git repository to install a new inventory.") if os.path.exists(path) and os.path.isdir(path): if not os.path.exists(os.path.dirname(dest_path)): os.mkdir(os.path.dirname(dest_path)) os.symlink(path, dest_path) else: click.echo('We will clone %s in %s\n' % (path, dest_path)) try: vgit('clone', path, dest_path) except ErrorReturnCode: fatal("Unable to install the inventory %s." % name) success("The %s inventory has been installed." % name)
def update(): for organization in get_organization_list(): if not os.path.exists(os.path.join(get_env_path(organization), '.git')): info("Skip %s" % organization) continue info("Updating %s ..." % organization) os.chdir(get_env_path(organization)) if not git('remote').strip(): info("No remotes are set for this organization, skipping") continue try: vgit('pull') except ErrorReturnCode: fatal("Unable to update the organizations.") run_galaxy_install(organization) success("All the organizations have been updated.")
def get_job_help(job): job_desc = None job_help = '' try: jobfile = get_job_file(job) except Exception as e: fatal(e.message) with open(jobfile) as f: line = f.readline() if line.startswith('# '): job_desc = line[2:].strip() while True: line = f.readline() if not line: break if line == '\n': continue if not line.startswith('#'): break job_help += line return job_desc, job_help
def cli(box, variable, unity, server, platform): """ Build your native application """ search_path, project_type = _get_search_path() if not project_type: fatal("We were not able to detect the type of your project.") info("We detected that your project is using {project}." .format(project=bold(project_type))) url = _get_url(server, box) if not url: fatal("Unable to generate the URL for this server.") info("""We will replace the value of the {variable} variable by {url} in files located in the {search_path} directory.""" .format(variable=bold(variable), url=bold(url), search_path=bold(os.path.relpath(search_path, os.getcwd())))) files = _search_variables(search_path, variable) for filename in files: _replace_variable(filename, variable, url) success(""" The {variable} variable has been changed in the following files: {files} """.format(variable=bold(variable), files='\n'.join( map(lambda x: '* ' + bold(os.path.relpath(x, os.getcwd())), files) ) )) if platform: _build(project_type, platform, unity=unity)
def remove(organization_name): """ Remove organizations. """ 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) if not click.confirm("Do you want to delete the %s organization?" % organization_name, default=False): info("Aborted. Nothing has been done.") return if os.path.isdir(dest_path) and not os.path.islink(dest_path): shutil.rmtree(dest_path) else: os.remove(dest_path) success("The %s organization has been removed." % organization_name)
def remove(inventory_name): """ Remove inventories. """ 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) if not click.confirm("Do you want to delete the %s inventory?" % inventory_name, default=False): info("Aborted. Nothing has been done.") return if os.path.isdir(dest_path) and not os.path.islink(dest_path): shutil.rmtree(dest_path) else: os.remove(dest_path) success("The %s inventory has been removed." % inventory_name)
def _update_project(project): with cd(project.folder()): info('We will update the project %s' % click.style(project.name(), bold=True)) repo = Repo(project.folder()) remotes = [remote.name for remote in repo.remotes] updated_from_upstream = False if 'upstream' not in remotes: click.secho('warning: your repository has no configured upstream, ' 'skipping update', fg='yellow') else: out = git('branch', '-a') remote_branch_name = 'remotes/upstream/' + repo.active_branch.name rebase = False for line in out.split('\n'): if remote_branch_name in line: rebase = True break if rebase: try: vgit('pull', '--rebase', 'upstream', repo.active_branch) except ErrorReturnCode_1: fatal('error: unable to update the project') updated_from_upstream = True if 'origin' in remotes: vgit('push', 'origin', repo.active_branch) if 'origin' in remotes and not updated_from_upstream: vgit('pull', 'origin', repo.active_branch) success('The project %s has been updated' % click.style(project.name(), bold=True))
def cli(timeout, inventory, host, extra): """ Connect to a remote server. """ summary(inventory) try: host = ACHost(inventory, host) except NameError as e: fatal(e.message) except IOError as e: fatal(e.message) except AnsibleYAMLValidationFailed as e: fatal(e.message) ip = host.ssh_host() services = _services(ip, timeout) args = [] if services: click.secho('\nThe following SSH forwarding have automatically ' 'been made:\n', fg='green', bold=True) for service in services: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) s.bind(('localhost', 0)) _, local_port = s.getsockname() s.close() args += ['-L', '%s:%s:%s' % ( local_port, ip, service['port']) ] click.echo('%s @ ' % click.style(service['name'], fg='cyan'), nl=False) if 'path' in service: click.secho('http://localhost:%s%s' % ( local_port, service['path'] ), fg='magenta') else: click.secho('localhost:%s' % local_port, fg='magenta') click.echo() if extra: args += ['--'] + list(extra) _ssh(ip, timeout, *args)
def install(name, path): """ Install organization. """ if not name: update() return if not name.isalnum(): fatal("Your organization name should only contains alphanumeric " "characters.") dest_path = get_env_path(name) if os.path.exists(dest_path): click.echo('We will update the %s organization' % name) os.chdir(dest_path) if os.path.exists(os.path.join(dest_path, '.git')): try: vgit('pull') except ErrorReturnCode: fatal("Unable to update the organization %s." % name) success("The %s organization has been updated." % name) run_galaxy_install(name) return if not path: fatal("You must specify a path to a local directory or an URL to a " "git repository to install a new organization.") if os.path.exists(path) and os.path.isdir(path): os.symlink(path, dest_path) else: click.echo('We will clone %s in %s\n' % (path, dest_path)) try: vgit('clone', path, dest_path) except ErrorReturnCode: fatal("Unable to install the organization %s." % name) success("The %s organization has been installed." % name) run_galaxy_install(name)