def run(): prototype_name = environment().prototype_name print("Adding prototype %s" % prototype_name) prototype_template_path = environment().prototype_template_path if not prototype_template_path: raise Exception("No prototype template path provided") logger.debug( "Reading prototype template from {}".format(prototype_template_path)) prototype_template = TemplateFolder(prototype_template_path) prototype_path = workspace().prototype_path(prototype_name) prototype_template.copy_to(prototype_path) prototype_data_path = os.path.join(prototype_template_path, 'gunilla-prototype.json') if not os.path.exists(prototype_data_path): raise Exception( "%s does not contain a valid prototype template, missing 'gunilla-prototype.json'" % prototype_template_path) os.remove(os.path.join(prototype_path, 'gunilla-prototype.json')) with open(prototype_data_path, 'r') as f: prototype_data = json.load(f) prototype = Prototype(prototype_data) workspace().add_prototype(prototype_name, prototype)
def workspace(): global _workspace_instance if not _workspace_instance: if environment().workspace: logger.debug("Using workspace %s" % environment().workspace) _workspace_instance = Workspace( os.path.abspath(environment().workspace)) else: logger.debug("Using default workspace (current directory)") _workspace_instance = Workspace(os.getcwd()) return _workspace_instance
def init(self): if self.is_configured() and not environment().force: raise WorkspaceException("Project seems to be already set up") print("Initializing project {}".format(self.config().project_name)) project_template_path = environment().project_template_path if project_template_path is None: self._create_default_dirs() else: logger.debug("Reading project template from {}".format( project_template_path)) project_name = self.config().project_name project_template = TemplateFolder(project_template_path) project_template.copy_to(self._dir) self._fix_project_config(project_name)
def run(): if not workspace().is_configured(): raise ActionException("Project was not already set up") infrastructure().clear() if environment().clear_volumes: infrastructure().clear_volumes()
def download_dependency(dependencies, slug, url_template, folder): dependency = dependencies[slug] version = dependency.version print("Downloading plugin '{}' at version '{}'".format(slug, version)) if version != 'latest': path_segments = [folder, slug, version, '%s-%s.zip' % (slug, version)] if repository.exists(path_segments): extract(path_segments, folder) return descriptor = json.loads(requests.get(url_template.format(slug)).text) if environment().debug: print("Downloaded descriptor: %s" % json.dumps(descriptor, indent=2)) download_extract(slug, dependency, descriptor, folder)
def main(): environment().read_args() if environment().debug: logging.basicConfig(level=logging.DEBUG) else: logging.basicConfig(level=logging.ERROR) try: action = get_action(environment().action) except ActionException as e: error("Unrecognized action: {}".format(environment().action), e) environment().print_usage() sys.exit(2) try: action() except ActionException as e: error(e.args[0], e) sys.exit(3)
def config_file_path(self): if environment().workspace: return os.path.join(environment().workspace, 'gunilla.json') else: return 'gunilla.json'
def error(msg, exception=None): print(msg) if environment().debug: print("") print(exception) traceback.print_exc()