Skip to content

Instantly share code, notes, and snippets.

@chrox
Created January 22, 2013 14:50
Show Gist options
  • Save chrox/4595193 to your computer and use it in GitHub Desktop.
Save chrox/4595193 to your computer and use it in GitHub Desktop.
migrate github downloads to google code downloads
#!/usr/bin/python
import os
import time
import subprocess
from github import Github
GITHUB_USER_TOKEN = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
GITHUB_REPO = "xxxx"
GOOGLE_CODE_USER = "xxxxxxxx@gmail.com"
GOOGLE_CODE_PASSWORD = "xxxxxxxxxxxxx"
GOOGLE_CODE_PROJECT = "xxxxxxxxxxxxxxxxxxxxxx"
def download_from_github(html_url):
downloaded = False
count = 5
while(not downloaded and count >= 0):
try:
exit_code = subprocess.call(["wget", "--no-check-certificate", "--read-timeout=60", html_url])
except Exception, e:
print("Caught exception " + str(e))
else:
if exit_code == 0:
print("File downloaded successfully.")
downloaded = True
else:
count = count -1
print("Download file failed...%d" %exit_code)
print("Try again.")
time.sleep(3)
return downloaded
def upload_to_googlecode(filename, summary):
arg_list = []
arg_list.append("googlecode_upload.py")
arg_list.extend(["-s", summary])
arg_list.extend(["-p", GOOGLE_CODE_PROJECT])
arg_list.extend(["-u", GOOGLE_CODE_USER])
arg_list.extend(["-w", GOOGLE_CODE_PASSWORD])
arg_list.append(filename)
uploaded = False
count = 5
while(not uploaded and count >= 0):
try:
print("Call script: " + str(arg_list))
exit_code = subprocess.call(arg_list)
except Exception, e:
print("Caught exception " + str(e))
time.sleep(3)
else:
if exit_code == 0:
print("File uploaded successfully.")
uploaded = True
else:
count = count - 1
print("Upload file failed...%d" %exit_code)
print("Try again.")
time.sleep(3)
return uploaded
def migrate(repo):
downloads = None
while not downloads:
try:
print("Trying to get downloads from repo.")
downloads = reversed(list(repo.get_downloads()))
break
except Exception, e:
print("Caught exception " + str(e))
time.sleep(1)
for download in downloads:
download_name = None
download_html_url = None
download_description = None
while not download_name:
try:
print("Trying to get download name.")
download_name = (download.name).encode()
print("Filename is " + download_name)
break
except Exception, e:
print("Caught exception " + str(e))
time.sleep(1)
while not download_html_url:
try:
print("Trying to get download url.")
download_html_url = download.html_url
print("File url is " + download_html_url)
break
except Exception, e:
print("Caught exception " + str(e))
time.sleep(1)
while not download_description:
try:
print("Trying to get download url.")
download_description = (download.description).encode()
print("File description is " + download_description)
break
except Exception, e:
print("Caught exception " + str(e))
time.sleep(1)
downloaded = False
while not downloaded:
print("Downloading " + download_name + " from Github.")
downloaded = download_from_github(download_html_url)
print("Uploading " + download_name + " to Google Code.")
upload_to_googlecode(download_name, download_description)
if __name__ == '__main__':
github_instance = Github(GITHUB_USER_TOKEN)
github_user = github_instance.get_user()
github_repo = None
while not github_repo:
try:
print("Trying to get repo from Github.")
github_repo = github_user.get_repo(GITHUB_REPO)
break
except Exception, e:
print("Caught exception " + str(e))
time.sleep(1)
migrate(github_repo)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment