def importRepoScreenshot(id): package = Package.query.get(id) if package is None or package.state == PackageState.DELETED: raise Exception("Unexpected none package") try: with clone_repo(package.repo) as repo: for ext in ["png", "jpg", "jpeg"]: sourcePath = repo.working_tree_dir + "/screenshot." + ext if os.path.isfile(sourcePath): filename = randomString(10) + "." + ext destPath = os.path.join(app.config["UPLOAD_DIR"], filename) shutil.copyfile(sourcePath, destPath) ss = PackageScreenshot() ss.approved = True ss.package = package ss.title = "screenshot.png" ss.url = "/uploads/" + filename db.session.add(ss) db.session.commit() return "/uploads/" + filename except TaskError as e: # ignore download errors print(e) pass print("screenshot.png does not exist") return None
def makeVCSRelease(self, id, branch): release = PackageRelease.query.get(id) if release is None: raise TaskError("No such release!") elif release.package is None: raise TaskError("No package attached to release") with clone_repo(release.package.repo, ref=branch, recursive=True) as repo: postReleaseCheckUpdate(self, release, repo.working_tree_dir) filename = randomString(10) + ".zip" destPath = os.path.join(app.config["UPLOAD_DIR"], filename) assert(not os.path.isfile(destPath)) archiver = GitArchiver(prefix=release.package.name, force_sub=True, main_repo_abspath=repo.working_tree_dir) archiver.create(destPath) assert(os.path.isfile(destPath)) release.url = "/uploads/" + filename release.task_id = None release.commit_hash = repo.head.object.hexsha release.approve(release.package.author) db.session.commit() return release.url
def test_git_clone_commit(): with clone_repo(test_repo, random_commit, recursive=True) as repo: assert repo.head.commit.hexsha == random_commit assert os.path.isfile(os.path.join(repo.working_tree_dir, "init.lua")) assert not os.path.isfile( os.path.join(repo.working_tree_dir, "chatcmdbuilder", "init.lua")) assert not os.path.isfile( os.path.join(repo.working_tree_dir, "test-branch.txt"))
def getMeta(urlstr, author): with clone_repo(urlstr, recursive=True) as repo: try: tree = build_tree(repo.working_tree_dir, author=author, repo=urlstr) except MinetestCheckError as err: raise TaskError(str(err)) result = {"name": tree.name, "type": tree.type.name} for key in [ "title", "repo", "issueTracker", "forumId", "description", "short_description" ]: result[key] = tree.get(key) result["forums"] = result.get("forumId") readme_path = tree.getReadMePath() if readme_path: with open(readme_path, "r") as f: result["long_description"] = f.read() try: with open(os.path.join(tree.baseDir, ".cdb.json"), "r") as f: data = json.loads(f.read()) for key, value in data.items(): result[key] = value except LogicError as e: raise TaskError(e.message) except IOError: pass for alias, to in ALIASES.items(): if alias in result: result[to] = result[alias] for key, value in result.items(): if isinstance(value, set): result[key] = list(value) return result