From 152f56945596bc1065bb3c685e6c5eb3c5cd1a83 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Sat, 19 Feb 2011 15:06:58 -0700 Subject: [PATCH] Add a reupload command to make uploading fixed builds easier --- setup/commands.py | 5 +-- setup/upload.py | 83 +++++++++++++++++++++++++++++++++++------------ 2 files changed, 66 insertions(+), 22 deletions(-) diff --git a/setup/commands.py b/setup/commands.py index 12fb5fe0af..7e22ff14f3 100644 --- a/setup/commands.py +++ b/setup/commands.py @@ -17,7 +17,7 @@ __all__ = [ 'manual', 'tag_release', 'pypi_register', 'pypi_upload', 'upload_to_server', 'upload_user_manual', 'upload_to_mobileread', 'upload_demo', - 'upload_to_sourceforge', 'upload_to_google_code', + 'upload_to_sourceforge', 'upload_to_google_code', 'reupload', 'linux32', 'linux64', 'linux', 'linux_freeze', 'osx32_freeze', 'osx', 'rsync', 'push', 'win32_freeze', 'win32', 'win', @@ -63,13 +63,14 @@ stage4 = Stage4() publish = Publish() from setup.upload import UploadUserManual, UploadInstallers, UploadDemo, \ - UploadToServer, UploadToSourceForge, UploadToGoogleCode + UploadToServer, UploadToSourceForge, UploadToGoogleCode, ReUpload upload_user_manual = UploadUserManual() upload_to_mobileread = UploadInstallers() upload_demo = UploadDemo() upload_to_server = UploadToServer() upload_to_sourceforge = UploadToSourceForge() upload_to_google_code = UploadToGoogleCode() +reupload = ReUpload() from setup.installer import Rsync, Push rsync = Rsync() diff --git a/setup/upload.py b/setup/upload.py index 1917e0ab1f..cb363be5d7 100644 --- a/setup/upload.py +++ b/setup/upload.py @@ -39,8 +39,22 @@ def installer_description(fname): return 'OS X dmg' return 'Unknown file' +class ReUpload(Command): # {{{ -class UploadToGoogleCode(Command): + description = 'Re-uplaod any installers present in dist/' + + sub_commands = ['upload_to_google_code', 'upload_to_sourceforge'] + + def pre_sub_commands(self, opts): + opts.re_upload = True + + def run(self, opts): + for x in installers(): + if os.path.exists(x): + os.remove(x) +# }}} + +class UploadToGoogleCode(Command): # {{{ USERNAME = 'kovidgoyal' # Password can be gotten by going to @@ -52,21 +66,49 @@ class UploadToGoogleCode(Command): UPLOAD_HOST = 'calibre-ebook.googlecode.com' FILES_LIST = 'http://code.google.com/p/calibre-ebook/downloads/list' + def add_options(self, parser): + parser.add_option('--re-upload', default=False, action='store_true', + help='Re-upload all installers currently in dist/') + + def re_upload(self): + fnames = set([os.path.basename(x) for x in installers() if not + x.endswith('.tar.gz') and os.path.exists(x)]) + existing = set(self.old_files.keys()).intersection(fnames) + br = self.login_to_gmail() + for x in fnames: + src = os.path.join('dist', x) + if not os.access(src, os.R_OK): + continue + if x in existing: + self.info('Deleting', x) + br.open('http://code.google.com/p/calibre-ebook/downloads/delete?name=%s'%x) + br.select_form(predicate=lambda y: 'delete.do' in y.action) + br.form.find_control(name='delete') + br.submit(name='delete') + self.upload_one(src) + + def upload_one(self, fname): + self.info('Uploading', fname) + typ = 'Type-Source' if fname.endswith('.gz') else 'Type-Installer' + ext = os.path.splitext(fname)[1][1:] + op = 'OpSys-'+{'msi':'Windows','dmg':'OSX','bz2':'Linux','gz':'All'}[ext] + desc = installer_description(fname) + path = self.upload(os.path.abspath(fname), desc, + labels=[typ, op, 'Featured']) + self.info('\tUploaded to:', path) + return path + def run(self, opts): self.opts = opts self.password = open(self.PASSWORD_FILE).read().strip() self.paths = {} self.old_files = self.get_files_hosted_by_google_code() + if opts.re_upload: + return self.re_upload() + for fname in installers(): - self.info('Uploading', fname) - typ = 'Type-Source' if fname.endswith('.gz') else 'Type-Installer' - ext = os.path.splitext(fname)[1][1:] - op = 'OpSys-'+{'msi':'Windows','dmg':'OSX','bz2':'Linux','gz':'All'}[ext] - desc = installer_description(fname) - path = self.upload(os.path.abspath(fname), desc, - labels=[typ, op, 'Featured']) - self.info('\tUploaded to:', path) + path = self.upload_one(fname) self.paths[os.path.basename(fname)] = path self.info('Updating path map') self.info(repr(self.paths)) @@ -189,11 +231,9 @@ class UploadToGoogleCode(Command): return self.upload(fname, desc, labels=labels, retry=retry+1) raise Exception('Failed to upload '+fname) +# }}} - - - -class UploadToSourceForge(Command): +class UploadToSourceForge(Command): # {{{ description = 'Upload release files to sourceforge' @@ -217,9 +257,10 @@ class UploadToSourceForge(Command): self.opts = opts self.upload_installers() +# }}} -class UploadInstallers(Command): - description = 'Upload any installers present in dist/' +class UploadInstallers(Command): # {{{ + description = 'Upload any installers present in dist/ to mobileread' def curl_list_dir(self, url=MOBILEREAD, listonly=1): import pycurl c = pycurl.Curl() @@ -289,17 +330,18 @@ class UploadInstallers(Command): installers = list(map(installer_name, ('dmg', 'msi', 'tar.bz2'))) installers.append(installer_name('tar.bz2', is64bit=True)) map(self.upload_installer, installers) +# }}} -class UploadUserManual(Command): +class UploadUserManual(Command): # {{{ description = 'Build and upload the User Manual' sub_commands = ['manual'] def run(self, opts): check_call(' '.join(['scp', '-r', 'src/calibre/manual/.build/html/*', 'divok:%s'%USER_MANUAL]), shell=True) +# }}} - -class UploadDemo(Command): +class UploadDemo(Command): # {{{ description = 'Rebuild and upload various demos' @@ -317,8 +359,9 @@ class UploadDemo(Command): 'zip -j /tmp/html-demo.zip * /tmp/html2lrf.lrf', shell=True) check_call('scp /tmp/html-demo.zip divok:%s/'%(DOWNLOADS,), shell=True) +# }}} -class UploadToServer(Command): +class UploadToServer(Command): # {{{ description = 'Upload miscellaneous data to calibre server' @@ -348,6 +391,6 @@ class UploadToServer(Command): check_call('scp %s/*.sha512 divok:%s/signatures/' % (tdir, DOWNLOADS), shell=True) shutil.rmtree(tdir) - +# }}}