mirror of
https://github.com/minetest/contentdb.git
synced 2025-01-10 23:17:37 +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
|
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):
|
def canMakeReleaseFromVCS(self):
|
||||||
if self.repo is None:
|
if self.repo is None:
|
||||||
return False
|
return False
|
||||||
|
@ -275,17 +275,14 @@ class PackageTreeNode:
|
|||||||
return self.meta.get(key)
|
return self.meta.get(key)
|
||||||
|
|
||||||
|
|
||||||
@celery.task()
|
def cloneRepo(urlstr):
|
||||||
def getMeta(urlstr, author):
|
|
||||||
url = urlparse(urlstr)
|
|
||||||
|
|
||||||
gitDir = tempfile.gettempdir() + "/" + randomString(10)
|
gitDir = tempfile.gettempdir() + "/" + randomString(10)
|
||||||
|
|
||||||
err = None
|
err = None
|
||||||
|
|
||||||
try:
|
try:
|
||||||
git.Repo.clone_from(urlstr, gitDir, progress=None, env=None, depth=1)
|
git.Repo.clone_from(urlstr, gitDir, progress=None, env=None, depth=1)
|
||||||
except GitCommandError as e:
|
except GitCommandError as e:
|
||||||
|
# This is needed to stop the backtrace being weird
|
||||||
err = e.stderr
|
err = e.stderr
|
||||||
|
|
||||||
if err is not None:
|
if err is not None:
|
||||||
@ -293,8 +290,12 @@ def getMeta(urlstr, author):
|
|||||||
.replace("Cloning into '" + gitDir + "'...", "") \
|
.replace("Cloning into '" + gitDir + "'...", "") \
|
||||||
.strip())
|
.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)
|
shutil.rmtree(gitDir)
|
||||||
|
|
||||||
result = {}
|
result = {}
|
||||||
@ -362,34 +363,30 @@ def importRepoScreenshot(id):
|
|||||||
raise Exception("Unexpected none package")
|
raise Exception("Unexpected none package")
|
||||||
|
|
||||||
# Get URL Maker
|
# Get URL Maker
|
||||||
url = urlparse(package.repo)
|
gitDir = cloneRepo(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")
|
|
||||||
|
|
||||||
|
# Find and import screenshot
|
||||||
try:
|
try:
|
||||||
filename = randomString(10) + ".png"
|
for ext in ["png", "jpg", "jpeg"]:
|
||||||
imagePath = os.path.join("app/public/uploads", filename)
|
sourcePath = gitDir + "/screenshot." + ext
|
||||||
print(imagePath)
|
if os.path.isfile(sourcePath):
|
||||||
urllib.request.urlretrieve(urlmaker.getScreenshotURL(), imagePath)
|
filename = randomString(10) + "." + ext
|
||||||
|
destPath = os.path.join("app/public/uploads", filename)
|
||||||
|
shutil.copyfile(sourcePath, destPath)
|
||||||
|
|
||||||
ss = PackageScreenshot()
|
ss = PackageScreenshot()
|
||||||
ss.approved = True
|
ss.approved = True
|
||||||
ss.package = package
|
ss.package = package
|
||||||
ss.title = "screenshot.png"
|
ss.title = "screenshot.png"
|
||||||
ss.url = "/uploads/" + filename
|
ss.url = "/uploads/" + filename
|
||||||
db.session.add(ss)
|
db.session.add(ss)
|
||||||
db.session.commit()
|
db.session.commit()
|
||||||
|
|
||||||
return "/uploads/" + filename
|
return "/uploads/" + filename
|
||||||
except HTTPError:
|
finally:
|
||||||
print("screenshot.png does not exist")
|
shutil.rmtree(gitDir)
|
||||||
|
|
||||||
|
print("screenshot.png does not exist")
|
||||||
return None
|
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)
|
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)])
|
harddep_str = StringField("Hard Dependencies", [Optional(), Length(0,1000)])
|
||||||
softdep_str = StringField("Soft 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()])
|
website = StringField("Website URL", [Optional(), URL()])
|
||||||
issueTracker = StringField("Issue Tracker URL", [Optional(), URL()])
|
issueTracker = StringField("Issue Tracker URL", [Optional(), URL()])
|
||||||
forums = IntegerField("Forum Topic ID", [Optional(), NumberRange(0,999999)])
|
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
|
db.session.commit() # save
|
||||||
|
|
||||||
if wasNew and package.canImportScreenshot():
|
if wasNew and package.repo is not None:
|
||||||
task = importRepoScreenshot.delay(package.id)
|
task = importRepoScreenshot.delay(package.id)
|
||||||
return redirect(url_for("check_task", id=task.id, r=package.getDetailsURL()))
|
return redirect(url_for("check_task", id=task.id, r=package.getDetailsURL()))
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user