Created
November 2, 2012 15:34
-
-
Save chrox/4002028 to your computer and use it in GitHub Desktop.
build and upload customupdate of kindlepdfviewer automatically
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
import os | |
import sys | |
import time | |
from datetime import datetime,timedelta | |
import subprocess | |
from github import Github | |
PROXY = "http://192.168.1.101:7071" | |
USER_TOKEN = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" | |
REPO = "kindlepdfviewer" | |
EMAIL = "XXXXXXXXXX@gmail.com" | |
def notification(filename): | |
SENDMAIL = "/usr/sbin/sendmail" | |
p = os.popen("%s -t" % SENDMAIL, "w") | |
p.write("To: " + EMAIL + "\n") | |
p.write("Subject: kpv nightly build uploaded!\n") | |
p.write(filename + " is uploaded.\n") | |
sts = p.close() | |
if sts != 0: | |
print "Sendmail exit status", sts | |
def delete_old_downloads(repo): | |
for download in repo.get_downloads(): | |
if datetime.now() - download.created_at > timedelta(days=30): | |
download.delete() | |
def create_download(repo, filepath): | |
t = datetime.now() - timedelta(days=1) | |
date = t.strftime("%Y%m%d") | |
filename = "kindlepdfviewer-nightly-" + date + ".zip" | |
comments = "kindlepdfviewer nightly build on " + date | |
filetype = "application/zip" | |
filesize = os.path.getsize(filepath) | |
print("filename: " + filename) | |
print("comments: " + comments) | |
print("filesize: " + str(filesize)) | |
for download in repo.get_downloads(): | |
if download.name == filename: | |
print("delete previously uploaded file " + filename) | |
download.delete() | |
response = repo.create_download(filename, filesize, comments, filetype) | |
print("created download at " + response.html_url) | |
return response | |
def upload_file(response, filename): | |
arg_list = [] | |
arg_list.append("curl") | |
arg_list.extend(["-F", "key=%s" %response.path]) | |
arg_list.extend(["-F", "acl=%s" %response.acl]) | |
arg_list.extend(["-F", "success_action_status=201"]) | |
arg_list.extend(["-F", "Filename=%s" %response.name]) | |
arg_list.extend(["-F", "AWSAccessKeyId=%s" %response.accesskeyid]) | |
arg_list.extend(["-F", "Policy=%s" %response.policy]) | |
arg_list.extend(["-F", "Signature=%s" %response.signature]) | |
arg_list.extend(["-F", "Content-Type=%s" %response.mime_type]) | |
arg_list.extend(["-F", "file=@%s" %filename]) | |
arg_list.append(response.s3_url) | |
arg_list.extend(["--retry","3","--max-time","300"]) | |
arg_list.append("-v") | |
os.environ["ALL_PROXY"] = PROXY | |
return subprocess.call(arg_list) | |
if __name__ == '__main__': | |
github_instance = Github(USER_TOKEN) | |
user = github_instance.get_user() | |
repo = user.get_repo(REPO) | |
filename = sys.argv[1] | |
created = False | |
while(not created): | |
try: | |
delete_old_downloads(repo) | |
response = create_download(repo, filename) | |
created = True | |
except Exception, e: | |
print("Caught exception " + str(e)) | |
uploaded = False | |
while(not uploaded): | |
try: | |
exit_code = upload_file(response, filename) | |
except Exception, e: | |
print("Caught exception " + str(e)) | |
continue | |
else: | |
if exit_code == 0: | |
print("File uploaded successfully.") | |
notification(filename) | |
uploaded = True | |
else: | |
print("Upload file failed...%d" %exit_code) | |
print("Try again.") | |
time.sleep(5) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
echo "clone kindlepdfviewer into dev directory" | |
cd ~/dev | |
rm -rf kindlepdfviewer | |
git clone git://github.com/hwhw/kindlepdfviewer.git | |
cd kindlepdfviewer | |
echo "compile and build customupdate" | |
PATH="/opt/arm-2012.03/bin:$PATH" | |
make fetchthirdparty | |
make thirdparty kpdfview customupdate | |
kpvzip=`find kindlepdfviewer*.zip |sort -r |head -1` | |
~/bin/github-upload.py $kpvzip |
@houqp This time in every build the repo is freshly cloned from the main repo. I think the problem you mentioned is gone.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Do we need to also pull tags from upstream here? Otherwise we might get wrong output from
git describe HEAD
?