def run_galaxy_install(organization): roles_path = os.path.join(get_env_path(organization), 'roles') dependencies_path = os.path.join(roles_path, 'dependencies.txt') if not os.path.exists(dependencies_path): return last_mtime = None last_mtime_file = os.path.join(get_env_path(organization), '.galaxy') if os.path.exists(last_mtime_file): with open(last_mtime_file, 'r') as f: last_mtime = f.readline() mtime = str(os.stat(dependencies_path).st_mtime) if last_mtime == mtime: return info("Updating dependencies for %s ..." % organization) galaxy = shCommand(os.path.join(aeriscloud_path, 'scripts', 'wrapper.sh')) galaxy(os.path.join(aeriscloud_path, 'venv', 'bin', 'ansible-galaxy'), 'install', '-f', '-p', roles_path, '-r', dependencies_path, _out=sys.stdout, _out_bufsize=0, _err_to_out=True) with open(last_mtime_file, 'w') as f: f.write(mtime)
def run_galaxy_install(organization): roles_path = os.path.join(get_env_path(organization), 'roles') dependencies_paths = [os.path.join(roles_path, '%s.%s' % (filename, ext)) for (filename, ext) in product(['requirements', 'dependencies'], ['yml', 'txt'])] for path in dependencies_paths: if os.path.exists(path): dependencies_path = path break else: return last_mtime = None last_mtime_file = os.path.join(get_env_path(organization), '.galaxy') if os.path.exists(last_mtime_file): with open(last_mtime_file, 'r') as f: last_mtime = f.readline() mtime = str(os.stat(dependencies_path).st_mtime) if last_mtime == mtime: return info("Updating dependencies for %s ..." % organization) galaxy = shCommand(os.path.join(aeriscloud_path, 'scripts', 'wrapper.sh')) galaxy(os.path.join(aeriscloud_path, 'venv', 'bin', 'ansible-galaxy'), 'install', '-f', '-p', roles_path, '-r', dependencies_path, _out=sys.stdout, _out_bufsize=0, _err_to_out=True) with open(last_mtime_file, 'w') as f: f.write(mtime)
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 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 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(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 _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 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 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!""")