-
Notifications
You must be signed in to change notification settings - Fork 2
/
committertask.py
46 lines (40 loc) · 1.65 KB
/
committertask.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import webapp2
from google.appengine.api import taskqueue
from committer import Committer
from models import GeneratedFiles
from secrets import secret_botpassword
from google.appengine.ext import blobstore
class CommitterTask(webapp2.RequestHandler):
"""
GET: Creates a task queue entry
POST: Runs through all GeneratedFiles entries and creates a commit
"""
def post(self):
committer = Committer("SkGithubBot", secret_botpassword, "EduExport", "master")
items = []
langcode = self.request.get('langcode')
all = GeneratedFiles.query(GeneratedFiles.LangCode == langcode).fetch()
for generated in all:
if not generated or not generated.blob:
logger.error("GeneratedFiles %s does not have a blob, or could not be found." % identifier)
return
else:
blobinfo = blobstore.BlobInfo.get(generated.blob)
reader = blobinfo.open()
content = reader.read()
path = ""
try:
path = generated.LangCode + "/" + generated.FileGenPath + "/" + generated.FileName
except TypeError:
path = generated.LangCode + "/NOPATH/" + generated.SearchName
path = path.replace("\\", "/")
items.append({
"path": path,
"mode": "100644",
"content": content,
})
committer.commit(items)
def get(self):
langcode = self.request.get('langcode')
taskqueue.add(url='/commit', params={'langcode': langcode})
self.redirect("/export")