OLD | NEW |
(Empty) | |
| 1 #!/usr/bin/env python |
| 2 |
| 3 # This Source Code Form is subject to the terms of the Mozilla Public |
| 4 # License, v. 2.0. If a copy of the MPL was not distributed with this |
| 5 # file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 6 |
| 7 import argparse |
| 8 import os |
| 9 import pkg_resources |
| 10 import sys |
| 11 |
| 12 from . import factory |
| 13 from . import scraper |
| 14 |
| 15 |
| 16 version = pkg_resources.require("mozdownload")[0].version |
| 17 |
| 18 __doc__ = """ |
| 19 Module to handle downloads for different types of archive.mozilla.org hosted |
| 20 applications. |
| 21 |
| 22 mozdownload version: %(version)s |
| 23 """ % {'version': version} |
| 24 |
| 25 |
| 26 def cli(): |
| 27 """Main function for the downloader""" |
| 28 |
| 29 parser = argparse.ArgumentParser(description=__doc__) |
| 30 parser.add_argument('--application', '-a', |
| 31 dest='application', |
| 32 choices=scraper.APPLICATIONS, |
| 33 default='firefox', |
| 34 metavar='APPLICATION', |
| 35 help='The name of the application to download, default:
"%(default)s"') |
| 36 parser.add_argument('--base_url', |
| 37 dest='base_url', |
| 38 default=scraper.BASE_URL, |
| 39 metavar='BASE_URL', |
| 40 help='The base url to be used, default: "%(default)s"') |
| 41 parser.add_argument('--build-number', |
| 42 dest='build_number', |
| 43 type=int, |
| 44 metavar='BUILD_NUMBER', |
| 45 help='Number of the build (for candidate, daily, and tin
derbox builds)') |
| 46 parser.add_argument('--destination', '-d', |
| 47 dest='destination', |
| 48 default=os.getcwd(), |
| 49 metavar='DESTINATION', |
| 50 help='Directory or file name to download the ' |
| 51 'file to, default: current working directory') |
| 52 parser.add_argument('--extension', |
| 53 dest='extension', |
| 54 metavar='EXTENSION', |
| 55 help='File extension of the build (e.g. "zip"), default:
' |
| 56 'the standard build extension on the platform.') |
| 57 parser.add_argument('--locale', '-l', |
| 58 dest='locale', |
| 59 metavar='LOCALE', |
| 60 help='Locale of the application, default: "en-US" or "mu
lti"') |
| 61 parser.add_argument('--log-level', |
| 62 action='store', |
| 63 dest='log_level', |
| 64 default='INFO', |
| 65 metavar='LOG_LEVEL', |
| 66 help='Threshold for log output (default: %(default)s)') |
| 67 parser.add_argument('--password', |
| 68 dest='password', |
| 69 metavar='PASSWORD', |
| 70 help='Password for basic HTTP authentication.') |
| 71 parser.add_argument('--platform', '-p', |
| 72 dest='platform', |
| 73 choices=scraper.PLATFORM_FRAGMENTS.keys(), |
| 74 metavar='PLATFORM', |
| 75 help='Platform of the application') |
| 76 parser.add_argument('--retry-attempts', |
| 77 dest='retry_attempts', |
| 78 default=0, |
| 79 type=int, |
| 80 metavar='RETRY_ATTEMPTS', |
| 81 help='Number of times the download will be attempted in
' |
| 82 'the event of a failure, default: %(default)s') |
| 83 parser.add_argument('--retry-delay', |
| 84 dest='retry_delay', |
| 85 default=10., |
| 86 type=float, |
| 87 metavar='RETRY_DELAY', |
| 88 help='Amount of time (in seconds) to wait between retry
' |
| 89 'attempts, default: %(default)s') |
| 90 parser.add_argument('--stub', |
| 91 dest='is_stub_installer', |
| 92 action='store_true', |
| 93 help='Stub installer (Only applicable to Windows builds)
.') |
| 94 parser.add_argument('--timeout', |
| 95 dest='timeout', |
| 96 type=float, |
| 97 metavar='TIMEOUT', |
| 98 help='Amount of time (in seconds) until a download times
out.') |
| 99 parser.add_argument('--type', '-t', |
| 100 dest='scraper_type', |
| 101 choices=factory.scraper_types.keys(), |
| 102 default='release', |
| 103 metavar='SCRAPER_TYPE', |
| 104 help='Type of build to download, default: "%(default)s"'
) |
| 105 parser.add_argument('--url', |
| 106 dest='url', |
| 107 metavar='URL', |
| 108 help='URL to download. Note: Reserved characters (such ' |
| 109 'as &) must be escaped or put in quotes otherwise ' |
| 110 'CLI output may be abnormal.') |
| 111 parser.add_argument('--username', |
| 112 dest='username', |
| 113 metavar='USERNAME', |
| 114 help='Username for basic HTTP authentication.') |
| 115 parser.add_argument('--version', '-v', |
| 116 dest='version', |
| 117 metavar='VERSION', |
| 118 help='Version of the application to be downloaded for re
lease ' |
| 119 'and candidate builds, i.e. "3.6"') |
| 120 |
| 121 # Group for daily builds |
| 122 group = parser.add_argument_group('Daily builds', 'Extra options for daily b
uilds.') |
| 123 group.add_argument('--branch', |
| 124 dest='branch', |
| 125 default='mozilla-central', |
| 126 metavar='BRANCH', |
| 127 help='Name of the branch, default: "%(default)s"') |
| 128 group.add_argument('--build-id', |
| 129 dest='build_id', |
| 130 metavar='BUILD_ID', |
| 131 help='ID of the build to download.') |
| 132 group.add_argument('--date', |
| 133 dest='date', |
| 134 metavar='DATE', |
| 135 help='Date of the build, default: latest build') |
| 136 |
| 137 # Group for tinderbox builds |
| 138 group = parser.add_argument_group('Tinderbox builds', 'Extra options for tin
derbox builds.') |
| 139 group.add_argument('--debug-build', |
| 140 dest='debug_build', |
| 141 action='store_true', |
| 142 help='Download a debug build.') |
| 143 |
| 144 # Group for try builds |
| 145 group = parser.add_argument_group('Try builds', 'Extra options for try build
s.') |
| 146 group.add_argument('--changeset', |
| 147 dest='changeset', |
| 148 help='Changeset of the try build to download') |
| 149 |
| 150 kwargs = vars(parser.parse_args()) |
| 151 |
| 152 # Gives instructions to user when no arguments were passed |
| 153 if len(sys.argv) == 1: |
| 154 print(__doc__) |
| 155 parser.format_usage() |
| 156 print('Specify --help for more information on args. ' |
| 157 'Please see the README for examples.') |
| 158 return |
| 159 |
| 160 try: |
| 161 scraper_type = kwargs.pop('scraper_type') |
| 162 |
| 163 # If a URL has been specified use the direct scraper |
| 164 if kwargs.get('url'): |
| 165 scraper_type = 'direct' |
| 166 |
| 167 build = factory.FactoryScraper(scraper_type, **kwargs) |
| 168 build.download() |
| 169 except KeyboardInterrupt: |
| 170 print('\nDownload interrupted by the user') |
| 171 |
| 172 |
| 173 if __name__ == '__main__': |
| 174 cli() |
OLD | NEW |