Esempio n. 1
0
File: cacher.py Progetto: argp/aosd
 def rebuild(cls):
     config.toggleFirstRun()
     package_cache = {}
     total_manifests = 0
     for rtype in releases.get():
         version = versions.get(rtype)
         total_manifests += len(version)
     available_package_manifests = cls.get(None, None)
     manifests_on_disk = 0
     for release_type in available_package_manifests:
         manifests_on_disk += len(available_package_manifests[release_type])
     if manifests_on_disk != total_manifests:
         logging_helper.getLogger().warn('You are rebuilding the cache without having all the release manifest files downloaded. To be able to access all information you should run "cache download_all" before running "cache rebuild" again.')
     for release_type in available_package_manifests:
         release_packages = {}
         for manifest_path in available_package_manifests[release_type]:
             manifest = plistlib.readPlist(manifest_path)
             for package_name in manifest['projects']:
                 package_name = str(package_name)
                 version_number = str(manifest['projects'][package_name]['version'])
                 if package_name in release_packages.keys():
                     if version_number not in release_packages[package_name]:
                         release_packages[package_name].append(version_number)
                 else:
                     release_packages[package_name] = [version_number]
         package_cache[str(release_type)] = release_packages
     package_cache_path = utilities.getcachefile('package_cache.plist')
     plistlib.writePlist(package_cache, package_cache_path)
Esempio n. 2
0
File: config.py Progetto: argp/aosd
 def setUpdateURL(cls, url):
     settings = cls.read()
     new_url = comp_urlparse.urlparse(url)
     if bool(new_url.scheme) == True:
         settings['core_url'] = url
         cls.write(settings)
     else:
         logging_helper.getLogger().error('The supplied URL is not valid (lacks a scheme).')
Esempio n. 3
0
File: manager.py Progetto: argp/aosd
 def ValidateAndDownload(cls, release_type, package_name, build_number):
     downloaded_directory_path = None
     has_valid_build = build_number in Builds.get(release_type, package_name)
     if has_valid_build == True:
         downloaded_directory_path = cls.DownloadPackageTarball(release_type, package_name, build_number)
     else:
         logging_helper.getLogger().error('Invalid build number! Please use the "--list" flag to see available build numbers for a package.')
     return downloaded_directory_path
Esempio n. 4
0
File: config.py Progetto: argp/aosd
 def read(cls):
     config_contents = {}
     config_plist_path = utilities.getconfigurationplistpath()
     if os.path.exists(config_plist_path) == False:
         logging_helper.getLogger().error('Fatal error, cannot locate the configuration plist. Use the "config defaults" command to restore defaults.')
     else:
         config_contents = plistlib.readPlist(config_plist_path)
     return config_contents
Esempio n. 5
0
File: config.py Progetto: lkheh/aosd
 def setDownloadDir(cls, download_dir):
     download_dir = os.path.expanduser(download_dir)
     settings = cls.read()
     if os.path.exists(download_dir) == True:
         settings['download_directory'] = download_dir
         cls.write(settings)
     else:
         logging_helper.getLogger().error('the directory specified "'+download_dir+'" does not exist, please create it first.')
Esempio n. 6
0
File: Hashes.py Progetto: argp/aosd
 def add(cls, release_type, package_name, build_number, hash_string):
     if cls.get(release_type, package_name, build_number) == '':
         hashes_manifest = cls.manifest()
         check_release = hashes_manifest.get(release_type, None)
         if check_release != None:
             check_package = check_release.get(package_name, None)
             if check_package != None:
                 check_package[build_number] = {'sha256': hash_string}
                 plistlib.writePlist(hashes_manifest, utilities.getlookupplistpath('hashes'))
                 logging_helper.getLogger().info('Added hash for "'+package_name+'-'+build_number+'"')
Esempio n. 7
0
 def process_do(cls, line_text, context):
     ret_val = None
     arguments = argument_helper.parse(line_text)
     result = cls.query(arguments)
     if result[0] == True:
         cls.action(context)
     else:
         ret_val = "Fatal error, cannot download!"
         logging_helper.getLogger().error(ret_val)
     return ret_val
Esempio n. 8
0
 def process_do(cls, line_text, context):
     ret_val = None
     arguments = argument_helper.parse(line_text)
     result = cls.query(arguments)
     if result[0] == True:
         cls.action(result[1])
     else:
         ret_val = "Invalid config command argument!"
         logging_helper.getLogger().error(ret_val)
     return ret_val
Esempio n. 9
0
File: Hashes.py Progetto: argp/aosd
 def ValidateDownloadedFileByHash(cls, output_file, release_type, package_name, build_number, remove_after=True):
     # get the file hash of what we downloaded
     file_hash = cls.calculate(output_file, remove_after)
     # look up any existing hash
     recorded_hash = cls.get(release_type, package_name, build_number)
     matching_hash = False
     if recorded_hash != '':
         matching_hash = recorded_hash == file_hash
     else:
         logging_helper.getLogger().error('There is no hash on record for "'+package_name+'-'+build_number+'". If you were able to download a tarball, then please submit a pull request to update "https://github.com/samdmarshall/AOS-Downloader/blob/master/aosd/data/hashes.plist" to reflect the correct hash.')
     return (matching_hash, file_hash, recorded_hash)
Esempio n. 10
0
File: config.py Progetto: argp/aosd
 def setUseHTTPS(cls, enable):
     settings = cls.read()
     is_enabled = settings['requests_via_https']
     if enable in ['True', 'TRUE', 'true']:
         is_enabled = True
     elif enable in ['False', 'FALSE', 'false']:
         is_enabled = False
     else:
         logging_helper.getLogger().error('the value passed "'+enable+'" must be "True" or "False".')
     settings['requests_via_https'] = is_enabled
     cls.write(settings)
Esempio n. 11
0
File: config.py Progetto: argp/aosd
 def setVerboseLogging(cls, enable):
     settings = cls.read()
     is_enabled = settings['verbose_logging']
     if enable in ['True', 'TRUE', 'true']:
         is_enabled = True
     elif enable in ['False', 'FALSE', 'false']:
         is_enabled = False
     else:
         logging_helper.getLogger().error('the value passed "'+enable+'" must be "True" or "False".')
     settings['verbose_logging'] = is_enabled
     cls.write(settings)
Esempio n. 12
0
 def process_do(cls, line_text, context):
     ret_val = None
     arguments = argument_helper.parse(line_text)
     result = cls.query(arguments)
     if result[0] == True:
         context['cache'] = result[1]
         cls.action(context)
     else:
         ret_val = 'Invalid cache command!'
         logging_helper.getLogger().error(ret_val)
     return ret_val
Esempio n. 13
0
 def get(cls, release_type, version):
     packages = []
     if version == None:
         packages = cls.list(release_type)
     else:
         release_info = releases.getInfo(release_type, version)
         cache_result = cacher.access(release_type, release_info)
         if cache_result[0] == True:
             packages = cache_result[1]
         else:
             logging_helper.getLogger().error('Could not find any packages. If you think this is an error, please run the "cache rebuild" command.')
     return sorted(packages)
Esempio n. 14
0
File: Hashes.py Progetto: argp/aosd
 def add(cls, release_type, package_name, build_number, hash_string):
     if cls.get(release_type, package_name, build_number) == '':
         hashes_manifest = cls.manifest()
         check_release = hashes_manifest.get(release_type, None)
         if check_release != None:
             check_package = check_release.get(package_name, None)
             if check_package != None:
                 check_package[build_number] = {'sha256': hash_string}
                 plistlib.writePlist(hashes_manifest,
                                     utilities.getlookupplistpath('hashes'))
                 logging_helper.getLogger().info('Added hash for "' +
                                                 package_name + '-' +
                                                 build_number + '"')
Esempio n. 15
0
 def get(cls):
     releases = []
     releases_dict_path = utilities.getreleaseplistpath()
     if os.path.exists(releases_dict_path) == True:
         releases_dict = plistlib.readPlist(releases_dict_path)
         releases_results = list(map(lambda release: release['package_name'], releases_dict))
         if len(releases_results) > 0:
             releases = releases_results
         else:
             logging_helper.getLogger().error('Could not find any release types in the releases manifest file. Please run the "update" command.')
     else:
         logging_helper.getLogger().error('Could not find the releases manifest file. Please run the "update" command.')
     return releases
Esempio n. 16
0
 def get_display_name(cls, release_type):
     release_display_name = ''
     releases_dict_path = utilities.getreleaseplistpath()
     if os.path.exists(releases_dict_path) == True:
         releases_dict = plistlib.readPlist(releases_dict_path)
         type_results = list((item for item in releases_dict if item['package_name'] == release_type))
         if len(type_results) > 0:
             release_display_name = type_results[0]['display_name']
         else:
             logging_helper.getLogger().error('Could not find a version in the releases manifest file matching type "'+release_type+'". Please run the "update" command.')
     else:
         logging_helper.getLogger().error('Could not find the releases manifest file. Please run the "update" command.')
     return release_display_name
Esempio n. 17
0
 def action(cls, args):
     """
     modify the config file
     """
     if args[0] == 'display':
         settings = config.read()
         logging_helper.getLogger().info('Current Configuration:')
         for key in settings:
             print('"' + key + '": "' + str(settings[key]) + '"')
     if args[0] == 'set':
         if len(args) == 3:
             if args[1] == 'core_url':
                 config.setUpdateURL(args[2])
             elif args[1] == 'download_directory':
                 config.setDownloadDir(args[2])
             elif args[1] == 'verbose_logging':
                 config.setVerboseLogging(args[2])
             elif args[1] == 'requests_via_https':
                 config.setUseHTTPS(args[2])
             elif args[1] == 'first_run':
                 logging_helper.getLogger().info(
                     'If you want to reset to original state, please use the "config defaults" command.'
                 )
             else:
                 logging_helper.getLogger().error(
                     'Attempting to set unrecognized key "' + args[1] +
                     '".')
     if args[0] == 'defaults':
         config.defaults()
         logging_helper.getLogger().info(
             'Default configuration has been restored.')
Esempio n. 18
0
    def action(cls, args):
        has_type = 'type' in args.keys()
        has_package = 'package' in args.keys()
        has_build = 'build' in args.keys()
        has_version = 'version' in args.keys()

        build_number = None

        if has_build == True:
            build_number = args['build']

        if has_build == False and has_version == True:
            logging_helper.getLogger().error('Could not resolve the build number from the version!')

        if has_type == True and has_package == True and has_build == True:
            release_type = args['type']
            package_name = args['package']

            if has_version == True:
                release_version = args['version']
                manager.DownloadPackageTarball(release_type, package_name, build_number, release_version)
            else:
                manager.DownloadPackageTarball(release_type, package_name, build_number)
        else:
            if has_type == False:
                logging_helper.getLogger().error('Cannot download package without a release type set. Use the "type" command.')

            if has_package == False:
                logging_helper.getLogger().error('Cannot download package without a package set. Use the "package" command.')

            if has_build == False:
                logging_helper.getLogger().error('Cannot download package without a version set. Use the "version" command or the "build" command.')
Esempio n. 19
0
 def action(cls, args):
     """
     modify the config file
     """
     if args[0] == "display":
         settings = config.read()
         logging_helper.getLogger().info("Current Configuration:")
         for key in settings:
             print('"' + key + '": "' + str(settings[key]) + '"')
     if args[0] == "set":
         if len(args) == 3:
             if args[1] == "core_url":
                 config.setUpdateURL(args[2])
             elif args[1] == "download_directory":
                 config.setDownloadDir(args[2])
             elif args[1] == "verbose_logging":
                 config.setVerboseLogging(args[2])
             elif args[1] == "requests_via_https":
                 config.setUseHTTPS(args[2])
             elif args[1] == "first_run":
                 logging_helper.getLogger().info(
                     'If you want to reset to original state, please use the "config defaults" command.'
                 )
             else:
                 logging_helper.getLogger().error('Attempting to set unrecognized key "' + args[1] + '".')
     if args[0] == "defaults":
         config.defaults()
         logging_helper.getLogger().info("Default configuration has been restored.")
Esempio n. 20
0
    def action(cls, args):
        has_type = 'type' in args.keys()
        has_package = 'package' in args.keys()
        has_build = 'build' in args.keys()
        has_version = 'version' in args.keys()

        build_number = None

        if has_build == True:
            build_number = args['build']

        if has_build == False and has_version == True:
            logging_helper.getLogger().error('Could not resolve the build number from the version!')

        if has_type == True and has_package == True and has_build == True:
            release_type = args['type']
            package_name = args['package']
            release_version = args['version']
            manager.DownloadPackageTarball(release_type, package_name, build_number, release_version)
        else:
            if has_type == False:
                logging_helper.getLogger().error('Cannot download package without a release type set. Use the "type" command.')

            if has_package == False:
                logging_helper.getLogger().error('Cannot download package without a package set. Use the "package" command.')

            if has_build == False:
                logging_helper.getLogger().error('Cannot download package without a version set. Use the "version" command or the "build" command.')
        print('====================')
Esempio n. 21
0
File: config.py Progetto: argp/aosd
    def setDownloadDir(cls, download_dir):
        download_dir = os.path.expanduser(download_dir)
        settings = cls.read()

        try:
            os.makedirs(download_dir)
        except OSError:
            pass

        if os.path.exists(download_dir) == True:
            settings['download_directory'] = download_dir
            cls.write(settings)
        else:
            logging_helper.getLogger().error(
                'the directory specified "' + download_dir +
                '" does not exist, please create it first.')
Esempio n. 22
0
 def process_do(cls, line_text, context):
     ret_val = None
     if context.has_key('type') and context.has_key('package'):
         release_type = context.get('type', None)
         package_name = context.get('package', None)
         arguments = argument_helper.parse(line_text)
         result = cls.query(release_type, package_name, arguments)
         if result[0] == True:
             context['diff'] = result[1]
             cls.action(context)
         else:
             ret_val = 'Invalid build numbers!'
             logging_helper.getLogger().error(ret_val)
     else:
         ret_val = 'Please select a release type and package before using the "diff" command.'
         logging_helper.getLogger().info(ret_val)
     return ret_val
Esempio n. 23
0
File: CmdDiff.py Progetto: argp/aosd
 def process_do(cls, line_text, context):
     ret_val = None
     if context.has_key('type') and context.has_key('package'):
         release_type = context.get('type', None)
         package_name = context.get('package', None)
         arguments = argument_helper.parse(line_text)
         result = cls.query(release_type, package_name, arguments)
         if result[0] == True:
             context['diff'] = result[1]
             cls.action(context)
         else:
             ret_val = 'Invalid build numbers!'
             logging_helper.getLogger().error(ret_val)
     else:
         ret_val = 'Please select a release type and package before using the "diff" command.'
         logging_helper.getLogger().info(ret_val)
     return ret_val
Esempio n. 24
0
File: cacher.py Progetto: argp/aosd
    def access(cls, release_type, release_info_dict):
        found_manifest = False
        packages = []
        if release_type != None and release_info_dict != None:
            cls.fetch(release_type, release_info_dict.get('name', None))
            release_plist_name = utilities.createcachefilename(release_info_dict.get('prefix', None), release_info_dict.get('version', None))
            cached_file_path = utilities.getcachefile(release_plist_name)

            if os.path.exists(cached_file_path) == True:
                found_manifest = True
                version_manifest_dict = plistlib.readPlist(cached_file_path)
                projects_list = version_manifest_dict.get('projects', None)
                if projects_list != None:
                    for key in projects_list:
                        packages.append(key)
        else:
            logging_helper.getLogger().error('Must supply a release type, set this using the "type" command.')
        return (found_manifest, packages)
Esempio n. 25
0
 def get(cls):
     releases = []
     releases_dict_path = utilities.getreleaseplistpath()
     if os.path.exists(releases_dict_path) == True:
         releases_dict = plistlib.readPlist(releases_dict_path)
         releases_results = list(
             map(lambda release: release['package_name'], releases_dict))
         if len(releases_results) > 0:
             releases = releases_results
         else:
             logging_helper.getLogger().error(
                 'Could not find any release types in the releases manifest file. Please run the "update" command.'
             )
     else:
         logging_helper.getLogger().error(
             'Could not find the releases manifest file. Please run the "update" command.'
         )
     return releases
Esempio n. 26
0
 def get_display_name(cls, release_type):
     release_display_name = ''
     releases_dict_path = utilities.getreleaseplistpath()
     if os.path.exists(releases_dict_path) == True:
         releases_dict = plistlib.readPlist(releases_dict_path)
         type_results = list((item for item in releases_dict
                              if item['package_name'] == release_type))
         if len(type_results) > 0:
             release_display_name = type_results[0]['display_name']
         else:
             logging_helper.getLogger().error(
                 'Could not find a version in the releases manifest file matching type "'
                 + release_type + '". Please run the "update" command.')
     else:
         logging_helper.getLogger().error(
             'Could not find the releases manifest file. Please run the "update" command.'
         )
     return release_display_name
Esempio n. 27
0
File: cacher.py Progetto: argp/aosd
    def fetch(cls, release_type, release_version):
        if release_type != None:
            if release_version != None:
                release_info_dict = releases.getInfo(release_type, release_version)
                release_plist_name = utilities.createcachefilename(release_info_dict['prefix'], release_info_dict['version'])
                cached_file_path = utilities.getcachefile(release_plist_name)

                if os.path.exists(cached_file_path) == False:
                    logging_helper.getLogger().info('Downloading version manifest ('+release_plist_name+')...')
                    manager.DownloadPackageManifest(cached_file_path)
            else:
                type_versions = versions.get(release_type)
                for version in type_versions:
                    release_version_info = releases.getInfo(release_type, version)
                    cls.fetch(release_type, release_version_info['name'])
        else:
            types = releases.get()
            for type_name in types:
                cls.fetch(type_name, None)
Esempio n. 28
0
File: CmdDiff.py Progetto: argp/aosd
    def action(cls, args):
        """
        download both and perform the diff
        """
        has_type = 'type' in args.keys()
        has_package = 'package' in args.keys()

        build_numbers = args['diff']

        if has_type == True and has_package == True:
            release_type = args['type']
            package_name = args['package']
            diff.perform(release_type, package_name, build_numbers)
        else:
            if has_type == False:
                logging_helper.getLogger().error('Cannot download package without a release type set. Use the "type" command.')

            if has_package == False:
                logging_helper.getLogger().error('Cannot download package without a package set. Use the "package" command.')
Esempio n. 29
0
File: Hashes.py Progetto: argp/aosd
 def ValidateDownloadedFileByHash(cls,
                                  output_file,
                                  release_type,
                                  package_name,
                                  build_number,
                                  remove_after=True):
     # get the file hash of what we downloaded
     file_hash = cls.calculate(output_file, remove_after)
     # look up any existing hash
     recorded_hash = cls.get(release_type, package_name, build_number)
     matching_hash = False
     if recorded_hash != '':
         matching_hash = recorded_hash == file_hash
     else:
         logging_helper.getLogger().error(
             'There is no hash on record for "' + package_name + '-' +
             build_number +
             '". If you were able to download a tarball, then please submit a pull request to update "https://github.com/samdmarshall/AOS-Downloader/blob/master/aosd/data/hashes.plist" to reflect the correct hash.'
         )
     return (matching_hash, file_hash, recorded_hash)
Esempio n. 30
0
 def process_do(cls, line_text, context):
     ret_val = None
     if context.has_key('type'):
         release_type = context.get('type', None)
         release_version = None
         if context.has_key('version'):
             release_version = context.get('version', None)
         arguments = argument_helper.parse(line_text)
         result = cls.query(release_type, release_version, arguments)
         if result[0] == True:
             context['package'] = result[1][0]
             if context.has_key('version'):
                 context['build'] = result[1][1]
             cls.action(context)
         else:
             ret_val = 'Invalid package name!'
             logging_helper.getLogger().error(ret_val)
     else:
         ret_val = 'Please select a release type before using the "package" command.'
         logging_helper.getLogger().info(ret_val)
     return ret_val
Esempio n. 31
0
 def perform(cls, release_type, package_name, diff_numbers):
     ancestor_build = manager.ValidateAndDownload(release_type, package_name, diff_numbers[0])
     child_build = manager.ValidateAndDownload(release_type, package_name, diff_numbers[1])
     if ancestor_build != None and child_build != None:
         if os.path.exists(ancestor_build) == True and os.path.exists(child_build) == True:
             # download was successful
             diff_path = os.path.join(config.getDownloadDir(), package_name+'.diff')
             logging_helper.getLogger().info('Creating source diff...')
             cls.make(ancestor_build, child_build, diff_path)
             logging_helper.getLogger().info('Package diff written to "'+diff_path+'"!')
         else:
             logging_helper.getLogger().error('There was an error with finding the downloaded packages!')
     else:
         logging_helper.getLogger().error('One or more of the build numbers supplied was not valid. Please use the "--list" command to see available build numebrs.')
Esempio n. 32
0
 def getInfo(cls, release_type, version):
     info_dict = {}
     if release_type != None:
         if version != None:
             type_plist_path = utilities.getlookupplistpath(release_type)
             if os.path.exists(type_plist_path) == True:
                 versions_dict = plistlib.readPlist(type_plist_path)
                 version_results = list((item for item in versions_dict
                                         if item['name'] == version))
                 if len(version_results) > 0:
                     info_dict = version_results[0]
                 else:
                     logging_helper.getLogger().error(
                         'Could not find version "' + version +
                         '" for release type "' + release_type +
                         '". If you think this is an error, run the "update" command.'
                     )
             else:
                 logging_helper.getLogger().error(
                     'Could not find a versions manifest for release type "'
                     + release_type +
                     '". If you think this is an error, run the "update" command.'
                 )
         else:
             logging_helper.getLogger().error(
                 'Must supply a version number!')
     return info_dict
Esempio n. 33
0
File: CmdList.py Progetto: argp/aosd
 def action(cls, args):
     release_type = args.get('type', None)
     package_name = args.get('package', None)
     if release_type != None:
         if package_name != None:
             package_list = Packages.list(release_type)
             has_valid_package = package_name in package_list
             if has_valid_package == True:
                 print('Builds for package ' + package_name + ':')
                 for build_number in Builds.get(release_type, package_name):
                     print(build_number)
             else:
                 if len(package_list) > 0:
                     logging_helper.getLogger().error(
                         'Invalid package name!')
                 else:
                     logging_helper.getLogger().error(
                         'The package list has not been built yet, please run "cache rebuild" to rebuild it. If that does not resolve this please run "cache setup".'
                     )
         else:
             print('Packages for ' + release_type + ':')
             for package_name in Packages.list(release_type):
                 print(package_name)
     else:
         logging_helper.getLogger().info(
             'Please select a release type before using the "list" command for packages, or please select a release type and package before using the "list" command for build numbers.'
         )
Esempio n. 34
0
File: cacher.py Progetto: argp/aosd
    def flush(cls, release_type, release_version):
        if release_type == None and release_version == None:
            settings = config.read()
            settings['first_run'] = True
            config.write(settings)
        if release_type != None:
            if release_version != None:
                release_info_dict = releases.getInfo(release_type, release_version)
                release_plist_name = utilities.createcachefilename(release_info_dict['prefix'], release_info_dict['version'])
                cached_file_path = utilities.getcachefile(release_plist_name)

                if os.path.exists(cached_file_path) == True:
                    logging_helper.getLogger().info('Removing version manifest ('+release_plist_name+')...')
                    manager.RemovePackageManifest(cached_file_path)
            else:
                type_versions = versions.get(release_type)
                for version in type_versions:
                    release_version_info = releases.getInfo(release_type, version)
                    cls.flush(release_type, release_version_info['name'])
        else:
            types = releases.get()
            for type_name in types:
                cls.flush(type_name, None)
Esempio n. 35
0
    def action(cls, args):
        """
        performs the selected cache operation
        """
        cache_action = args['cache']

        release_type = None
        if 'type' in args.keys():
            release_type = args['type']
        if cache_action == 'download_type' or cache_action == 'download_all':
            if cache_action == 'download_type':
                cacher.fetch(release_type, None)
            if cache_action == 'download_all':
                cacher.fetch(None, None)
            logging_helper.getLogger().info('Download complete, please run the "cache rebuild" command to update the index')
        if cache_action == 'clear_type':
            cacher.flush(release_type, None)
        if cache_action == 'clear_all':
            cacher.flush(None, None)
        if cache_action == 'rebuild':
            cacher.rebuild()
        if cache_action == 'setup':
            cacher.clean()
Esempio n. 36
0
File: CmdDiff.py Progetto: argp/aosd
    def action(cls, args):
        """
        download both and perform the diff
        """
        has_type = 'type' in args.keys()
        has_package = 'package' in args.keys()

        build_numbers = args['diff']

        if has_type == True and has_package == True:
            release_type = args['type']
            package_name = args['package']
            diff.perform(release_type, package_name, build_numbers)
        else:
            if has_type == False:
                logging_helper.getLogger().error(
                    'Cannot download package without a release type set. Use the "type" command.'
                )

            if has_package == False:
                logging_helper.getLogger().error(
                    'Cannot download package without a package set. Use the "package" command.'
                )
Esempio n. 37
0
    def action(cls, args):
        has_type = "type" in args.keys()
        has_package = "package" in args.keys()
        has_build = "build" in args.keys()
        has_version = "version" in args.keys()

        build_number = None

        if has_build == True:
            build_number = args["build"]

        if has_build == False and has_version == True:
            logging_helper.getLogger().error("Could not resolve the build number from the version!")

        if has_type == True and has_package == True and has_build == True:
            release_type = args["type"]
            package_name = args["package"]

            if has_version == True:
                release_version = args["version"]
                manager.DownloadPackageTarball(release_type, package_name, build_number, release_version)
            else:
                manager.DownloadPackageTarball(release_type, package_name, build_number)
        else:
            if has_type == False:
                logging_helper.getLogger().error(
                    'Cannot download package without a release type set. Use the "type" command.'
                )

            if has_package == False:
                logging_helper.getLogger().error(
                    'Cannot download package without a package set. Use the "package" command.'
                )

            if has_build == False:
                logging_helper.getLogger().error(
                    'Cannot download package without a version set. Use the "version" command or the "build" command.'
                )
Esempio n. 38
0
 def getInfo(cls, release_type, version):
     info_dict = {}
     if release_type != None:
         if version != None:
             type_plist_path = utilities.getlookupplistpath(release_type)
             if os.path.exists(type_plist_path) == True:
                 versions_dict = plistlib.readPlist(type_plist_path)
                 version_results = list((item for item in versions_dict if item['name'] == version))
                 if len(version_results) > 0:
                     info_dict = version_results[0]
                 else:
                     logging_helper.getLogger().error('Could not find version "'+version+'" for release type "'+release_type+'". If you think this is an error, run the "update" command.')
             else:
                 logging_helper.getLogger().error('Could not find a versions manifest for release type "'+release_type+'". If you think this is an error, run the "update" command.')
         else:
             logging_helper.getLogger().error('Must supply a version number!')
     return info_dict
Esempio n. 39
0
File: CmdList.py Progetto: argp/aosd
 def action(cls, args):
     release_type = args.get('type', None)
     package_name = args.get('package', None)
     if release_type != None:
         if package_name != None:
             package_list = Packages.list(release_type)
             has_valid_package = package_name in package_list
             if has_valid_package == True:
                 print('Builds for package '+package_name+':')
                 for build_number in Builds.get(release_type, package_name):
                     print(build_number)
             else:
                 if len(package_list) > 0:
                     logging_helper.getLogger().error('Invalid package name!')
                 else:
                     logging_helper.getLogger().error('The package list has not been built yet, please run "cache rebuild" to rebuild it. If that does not resolve this please run "cache setup".')
         else:
             print('Packages for '+release_type+':')
             for package_name in Packages.list(release_type):
                 print(package_name)
     else:
         logging_helper.getLogger().info('Please select a release type before using the "list" command for packages, or please select a release type and package before using the "list" command for build numbers.')
Esempio n. 40
0
File: manager.py Progetto: argp/aosd
    def DownloadPackageTarball(cls, release_type, package_name, build_number, \
            release_version = '', dest_dir = '', check_hash = True):
        
        downloaded_directory_path = ''
        tarball_address = cls.CreateTarballURL(release_type, package_name, build_number)
        package_file_name = os.path.basename(tarball_address)

        if dest_dir != '':
            output_directory = dest_dir
        else:
            output_directory = os.path.expanduser(config.getDownloadDir())

        if release_version != '':
            output_directory = output_directory + '/' + release_version
        
        try:
            os.makedirs(output_directory)
        except OSError:
            pass

        output_file = os.path.join(output_directory, package_file_name)
        download_successful = cls.DownloadFileFromURLToPath(tarball_address, output_file)
        tar_name = os.path.splitext(package_file_name)[0]
        file_name = os.path.splitext(tar_name)[0]
        if check_hash == True:
            logging_helper.getLogger().info('Downloaded "'+file_name+'" to "'+output_file+'"')
            # check the downloaded file against the stored hash
            hash_result = Hashes.ValidateDownloadedFileByHash(output_file, release_type, package_name, build_number, False)
            if hash_result[0] == True:
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Decompressing "'+output_file+'" -> "'+tar_name+'"...')
                gz_archive = gzip.open(output_file, 'rb')
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Reading file contents...')
                file_content = gz_archive.read()
                tar_path = os.path.join(output_directory, tar_name)
                dump_tar = open(tar_path, 'wb')
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Dumping tar file...')
                dump_tar.write(file_content)
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Closing files...')
                dump_tar.close()
                gz_archive.close()
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Removing archive...')
                os.remove(output_file)
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Opening tar file...')
                tar_archive = tarfile.open(tar_path)
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Decompressing tar file...')
                tar_archive.extractall(output_directory)
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Closing tar file...')
                tar_archive.close()
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Removing tar file...')
                os.remove(tar_path)
                if config.getVerboseLogging() == True:
                    logging_helper.getLogger().info('Decompression Complete!')
                logging_helper.getLogger().info('The package "'+file_name+'" has been downloaded to "'+output_directory+'".')
                downloaded_directory_path = os.path.join(output_directory, file_name)
            else:
                logging_helper.getLogger().info('The package "'+file_name+'" has hash of "'+hash_result[1]+'" which doesn\'t match the hash on record ('+hash_result[2]+')')
        else:
            if download_successful == True:
                downloaded_directory_path = output_file
        return downloaded_directory_path
Esempio n. 41
0
File: manager.py Progetto: argp/aosd
 def DownloadFileFromURLToPath(cls, url_address, file_path):
     request = comp_urlreq.Request(url_address)
     request.add_header("User-Agent", AOSD_VERSION)
     if config.getVerboseLogging() == True:
         logging_helper.getLogger().info('Starting download from  "'+url_address+'" -> "'+file_path+'"...')
     response = None
     try:
         response = comp_urlreq.urlopen(request)
     except comp_urlerr.HTTPError as e:
         logging_helper.getLogger().error('HTTPError = '+str(e.code)+' on '+url_address)
         response = None
     except comp_urlerr.URLError as e:
         logging_helper.getLogger().error('URLError = '+ str(e.reason)+' on '+url_address)
         response = None
     except compat_http.HTTPException as e:
         logging_helper.getLogger().error('HTTPException on '+url_address)
         response = None
     except Exception:
         logging_helper.getLogger().error(':Exception :( on '+url_address)
         response = None
     if response != None:
         output = open(file_path, 'wb')
         output.write(response.read())
         output.close()
         if config.getVerboseLogging() == True:
             logging_helper.getLogger().info('Download Complete!')
         return True
     else:
         return False
Esempio n. 42
0
File: main.py Progetto: argp/aosd
def main():
    parser = argparse.ArgumentParser(
        description='Apple Open Source Package Downloader')
    parser.add_argument('-t',
                        '--' + kFLAGNAME_type,
                        help='specify the release type',
                        required=False,
                        action='store')

    parser.add_argument('-r',
                        '--' + kFLAGNAME_release,
                        help='specify the OS X release number',
                        required=False,
                        action='store')

    parser.add_argument('-o',
                        '--' + kFLAGNAME_destdir,
                        help='specify the destination directory',
                        required=False,
                        action='store')

    parser.add_argument(
        '-l',
        '--' + kFLAGNAME_list,
        help=
        'list versions of a package to check out, if no package is specified it lists available packages',
        required=False,
        action='store_true')

    parser.add_argument(
        '-p',
        '--' + kFLAGNAME_package,
        help='specify the name of a package from a release',
        required=False,
        action='store',
    )

    parser.add_argument(
        '-b',
        '--' + kFLAGNAME_build,
        help="specify the build number from a package (or 'latest')",
        required=False,
        action='store')

    parser.add_argument(
        '-d',
        '--' + kFLAGNAME_diff,
        help='specify the build number of a package to create diff against',
        required=False,
        action='store',
        nargs=2)

    parser.add_argument('-s',
                        '--' + kFLAGNAME_resetcache,
                        help='removes currently cached package plist files',
                        required=False,
                        action='store_true')

    parser.add_argument(
        '-c',
        '--' + kFLAGNAME_buildcache,
        help='caches the package manifests and builds an index',
        required=False,
        action='store_true')

    parser.add_argument(
        '-f',
        '--' + kFLAGNAME_findhash,
        help=
        'gets the hash for the specified build number of a package of a release type',
        required=False,
        action='store_true')

    parser.add_argument('-v',
                        '--' + kFLAGNAME_version,
                        help='prints the version information',
                        required=False,
                        action='store_true')

    args_dict = vars(parser.parse_args())

    flag_commands = ParseFlags(args_dict)

    if config.getFirstRun() == True and 'cache setup' not in flag_commands \
            and 'info' not in flag_commands:
        logging_helper.getLogger().info(
            'This appears to be the first time this has been run, you should run the "cache setup" command or pass "--'
            + kFLAGNAME_buildcache +
            '" on the command line. This command will download several megabytes of plist files from "'
            + manager.CreateAppleURL() +
            '" so that packages can be looked up without querying the server.\n'
        )

    aosd_shell = InteractiveInput()

    if CheckPassedArgCount(args_dict) != 0:
        for command in flag_commands:
            result = aosd_shell.onecmd(command)
            if result != None:
                break
        aosd_shell.onecmd('quit')
    InteractiveInput.quitOnError = False
    aosd_shell.cmdloop()