mirror of
https://github.com/minetest/contentdb.git
synced 2024-12-22 22:12:24 +01:00
Add git screenshot importing
This commit is contained in:
parent
99b21f996c
commit
3d97eca387
@ -434,16 +434,6 @@ class Package(db.Model):
|
||||
|
||||
return None
|
||||
|
||||
def canImportScreenshot(self):
|
||||
if self.repo is None:
|
||||
return False
|
||||
|
||||
url = urlparse(self.repo)
|
||||
if url.netloc == "github.com":
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def canMakeReleaseFromVCS(self):
|
||||
if self.repo is None:
|
||||
return False
|
||||
|
@ -275,17 +275,14 @@ class PackageTreeNode:
|
||||
return self.meta.get(key)
|
||||
|
||||
|
||||
@celery.task()
|
||||
def getMeta(urlstr, author):
|
||||
url = urlparse(urlstr)
|
||||
|
||||
def cloneRepo(urlstr):
|
||||
gitDir = tempfile.gettempdir() + "/" + randomString(10)
|
||||
|
||||
err = None
|
||||
|
||||
try:
|
||||
git.Repo.clone_from(urlstr, gitDir, progress=None, env=None, depth=1)
|
||||
except GitCommandError as e:
|
||||
# This is needed to stop the backtrace being weird
|
||||
err = e.stderr
|
||||
|
||||
if err is not None:
|
||||
@ -293,8 +290,12 @@ def getMeta(urlstr, author):
|
||||
.replace("Cloning into '" + gitDir + "'...", "") \
|
||||
.strip())
|
||||
|
||||
tree = PackageTreeNode(gitDir, author=author, repo=urlstr)
|
||||
return gitDir
|
||||
|
||||
@celery.task()
|
||||
def getMeta(urlstr, author):
|
||||
gitDir = cloneRepo(urlstr)
|
||||
tree = PackageTreeNode(gitDir, author=author, repo=urlstr)
|
||||
shutil.rmtree(gitDir)
|
||||
|
||||
result = {}
|
||||
@ -362,34 +363,30 @@ def importRepoScreenshot(id):
|
||||
raise Exception("Unexpected none package")
|
||||
|
||||
# Get URL Maker
|
||||
url = urlparse(package.repo)
|
||||
urlmaker = None
|
||||
if url.netloc == "github.com":
|
||||
urlmaker = GithubURLMaker(url)
|
||||
else:
|
||||
raise TaskError("Unsupported repo")
|
||||
|
||||
if not urlmaker.isValid():
|
||||
raise TaskError("Error! Url maker not valid")
|
||||
gitDir = cloneRepo(package.repo)
|
||||
|
||||
# Find and import screenshot
|
||||
try:
|
||||
filename = randomString(10) + ".png"
|
||||
imagePath = os.path.join("app/public/uploads", filename)
|
||||
print(imagePath)
|
||||
urllib.request.urlretrieve(urlmaker.getScreenshotURL(), imagePath)
|
||||
for ext in ["png", "jpg", "jpeg"]:
|
||||
sourcePath = gitDir + "/screenshot." + ext
|
||||
if os.path.isfile(sourcePath):
|
||||
filename = randomString(10) + "." + ext
|
||||
destPath = os.path.join("app/public/uploads", 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()
|
||||
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 HTTPError:
|
||||
print("screenshot.png does not exist")
|
||||
return "/uploads/" + filename
|
||||
finally:
|
||||
shutil.rmtree(gitDir)
|
||||
|
||||
print("screenshot.png does not exist")
|
||||
return None
|
||||
|
||||
|
||||
|
@ -143,7 +143,7 @@ class PackageForm(FlaskForm):
|
||||
tags = QuerySelectMultipleField('Tags', query_factory=lambda: Tag.query.order_by(db.asc(Tag.name)), get_pk=lambda a: a.id, get_label=lambda a: a.title)
|
||||
harddep_str = StringField("Hard Dependencies", [Optional(), Length(0,1000)])
|
||||
softdep_str = StringField("Soft Dependencies", [Optional(), Length(0,1000)])
|
||||
repo = StringField("Repo URL", [Optional(), URL()])
|
||||
repo = StringField("VCS Repository URL", [Optional(), URL()])
|
||||
website = StringField("Website URL", [Optional(), URL()])
|
||||
issueTracker = StringField("Issue Tracker URL", [Optional(), URL()])
|
||||
forums = IntegerField("Forum Topic ID", [Optional(), NumberRange(0,999999)])
|
||||
@ -233,7 +233,7 @@ def create_edit_package_page(author=None, name=None):
|
||||
|
||||
db.session.commit() # save
|
||||
|
||||
if wasNew and package.canImportScreenshot():
|
||||
if wasNew and package.repo is not None:
|
||||
task = importRepoScreenshot.delay(package.id)
|
||||
return redirect(url_for("check_task", id=task.id, r=package.getDetailsURL()))
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user