def create_project(ws_id: int, project_data: dict) -> dict: """ Create a new Project in this workspace :param ws_id: The workpace ID :param project_data: The project data to create :return: The new project descriptor as a dict """ project_name = shlex.quote(project_data["name"]) repo = None if "repo" in project_data: repo = project_data["repo"] if repo: return gitimpl.clone(ws_id, repo, project_name) session = db_session() # test if ws Name exists in database workspace = session.query(Workspace). \ filter(Workspace.id == ws_id).first() if workspace is None: raise NotFound("No workspace with id {} was found".format(ws_id)) existing_projects = list(session.query(Project) .filter(Project.workspace == workspace) .filter(Project.name == project_name)) if len(existing_projects) > 0: raise NameConflict("Project with name '{}' already exists in this workspace".format(project_name)) # prepare db insert try: project = Project(name=project_name, rel_path=project_name, workspace=workspace) set_data(project, project_data) session.add(project) except: session.rollback() raise # create workspace on disk proc = Popen(['son-workspace', '--workspace', workspace.path, '--project', get_project_path(workspace.path, project_name)], stdout=PIPE, stderr=PIPE) out, err = proc.communicate() exitcode = proc.returncode if err.decode().find('exists') >= 0: project_exists = True else: project_exists = False if exitcode == 0 and not project_exists: sync_project_descriptor(project) session.commit() scan_project_dir(get_project_path(workspace.path, project_name), project) return project.as_dict() else: session.rollback() if project_exists: raise NameConflict("Project with name '{}' already exists in this workspace".format(project_name)) raise Exception(err.decode(), out.decode())
def post(self, ws_id): """ Clones projects into the workspace """ json_data = get_json(request) result = clone(ws_id, shlex.quote(json_data['url'])) return prepare_response(result, 200)
def create_project(ws_id: int, project_data: dict) -> dict: """ Create a new Project in this workspace :param ws_id: :param project_data: :return: The new project descriptor as a dict """ project_name = shlex.quote(project_data["name"]) repo = None if "repo" in project_data: repo = project_data["repo"] if repo: return gitimpl.clone(ws_id, repo, project_name) session = db_session() # test if ws Name exists in database workspace = session.query(Workspace). \ filter(Workspace.id == ws_id).first() if workspace is None: raise NotFound("No workspace with id {} was found".format(ws_id)) existing_projects = list(session.query(Project) .filter(Project.workspace == workspace) .filter(Project.name == project_name)) if len(existing_projects) > 0: raise NameConflict("Project with name '{}' already exists in this workspace".format(project_name)) # prepare db insert try: project = Project(name=project_name, rel_path=project_name, workspace=workspace) set_data(project, project_data) session.add(project) except: session.rollback() raise # create workspace on disk proc = Popen(['son-workspace', '--workspace', workspace.path, '--project', get_project_path(workspace.path, project_name)], stdout=PIPE, stderr=PIPE) out, err = proc.communicate() exitcode = proc.returncode if err.decode().find('exists') >= 0: project_exists = True else: project_exists = False if exitcode == 0 and not project_exists: sync_project_descriptor(project) session.commit() scan_project_dir(get_project_path(workspace.path, project_name), project) return project.as_dict() else: session.rollback() if project_exists: raise NameConflict("Project with name '{}' already exists in this workspace".format(project_name)) raise Exception(err.decode(), out.decode())