def _mandatory_install_size_hr(self): """Returns the downlod size in human readable format for all mandatorypackages not installed.""" result = None result = misc.bytes2hr(byte=self.mandatory_install_size) return result
def _optional_install_size_hr(self): """Returns the downlod size in human readable format for all optionalpackages not installed.""" result = None result = misc.bytes2hr(byte=self.optional_install_size) return result
def _all_install_size_hr(self): """Returns the install size in human readable format for all packages not installed.""" result = None result = misc.bytes2hr(byte=self.all_install_size) return result
def _all_download_size_hr(self): """Returns the download size in human readable format for all packages not installed.""" result = None result = misc.bytes2hr(byte=self._all_download_size()) return result
def _get_has_space(self, space_used): """Returns a True/False if there is enough free space.""" result = None _freespace = self._get_disk_stats()['FreeSpace'] if all([isinstance(value, int) for value in [space_used, _freespace]]): result = space_used < _freespace _space_used_hr = misc.bytes2hr(byte=space_used) _freespace_hr = misc.bytes2hr(byte=_freespace) LOG.debug('Disk: {}'.format(self._disk)) LOG.debug('Space used: {} ({})'.format(space_used, _space_used_hr)) LOG.debug('Freespace: {} ({})'.format(_freespace, _freespace_hr)) LOG.debug('Has enough space: {}'.format(result)) return result
def __init__(self, apps=None, plists=None): self._apps = None self._plists = None if apps: if isinstance(apps, list): self._apps = [ _app for _app in apps if _app is not None and isinstance( _app, applications.Application) and _app.is_installed ] _apps_info = [ '{} ({})'.format(_a.app_name, _a.version) for _a in self._apps ] _apps_info = ', '.join(_apps_info).strip(' ') _apps_discovered_msg = 'Installed apps found: {}'.format( _apps_info) if not config.SILENT and _apps_info: print(_apps_discovered_msg) LOG.info(_apps_discovered_msg) else: self._apps = None if plists: if isinstance(plists, list): self._plists = list() for _plist in plists: _pl = remote_plist.RemotePlist(obj=_plist) self._plists.append(_pl) else: self._plists = None self._valid_pkg_types = ['mandatory', 'optional'] self._valid_sze_types = ['DownloadSize', 'InstalledSize'] # NOTE: Some of the loops in these sets do actually # overlap each other, so there might be 700 when # combining the 'mandatory' and 'optional' sets in a pure # 1:1 combination, but when a 'set().union()' is done # this number could reduce down, to say, 682. Or other # such numbers depending on how packages are configured by # Apple. # So, leave these two sets as they are. if config.MANDATORY: self.mandatory = self._get_pkgs(pkg_type='mandatory') if self.mandatory: self.mandatory = sorted(self.mandatory, key=lambda pkg: pkg.DownloadName) else: self.mandatory = set() else: self.mandatory = set() if config.OPTIONAL: self.optional = self._get_pkgs(pkg_type='optional') if self.optional: self.optional = sorted(self.optional, key=lambda pkg: pkg.DownloadName) else: self.optional = set() else: self.optional = set() # Clean up any optional packages that are also in 'self.mandatory' self._clean_optionals_in_mandatory() # De duplicate _everything_ and create a set of all packages to wrangle.. if self.mandatory and self.optional: self.all = set(self.mandatory).union(self.optional) elif self.mandatory and not self.optional: self.all = set(self.mandatory) elif not self.mandatory and self.optional: self.all = set(self.optional) else: self.all = None if not self.all: if not config.SILENT: print('Nothing to process. Exiting.') now = datetime.now().strftime('%Y-%m-%d %H:%M:%S') # Quick redefine 'LOG' to use 'root' namespace for neatness in log. _log = logging.getLogger() _log.info('------------------ Log closed on {} ------------------'. format(now)) sys.exit(0) else: self.all = sorted(self.all, key=lambda pkg: pkg.DownloadName) for _pkg in self.all: _mand_or_opt = 'Mandatory' if _pkg.IsMandatory else 'Optional' LOG.debug('Package to process: {} ({})'.format( _pkg.PackageName, _mand_or_opt)) # Quantities of each self.all_qty = len(self.all) self.mandatory_qty = len(self.mandatory) self.optional_qty = len(self.optional) self.mandatory_download_size = self._mandatory_download_size() self.optional_download_size = self._optional_download_size() self.mandatory_download_size_hr = self._mandatory_download_size_hr() self.optional_download_size_hr = self._optional_download_size_hr() self.mandatory_install_size = self._mandatory_install_size() self.optional_install_size = self._optional_install_size() self.mandatory_install_size_hr = self._mandatory_install_size_hr() self.optional_install_size_hr = self._optional_install_size_hr() self.all_download_size = self._all_download_size() self.all_install_size = self._all_install_size() if config.DMG_DEPLOY_FILE: self.total_size_req = self.all_install_size else: self.total_size_req = self.all_download_size + self.all_install_size self.total_size_req_hr = misc.bytes2hr(byte=self.total_size_req) self.all_download_size_hr = self._all_download_size_hr() self.all_install_size_hr = self._all_install_size_hr() # Messages self.mandatory_download_msg = 'Mandatory packages download size: {} ({} packages)'.format( self.mandatory_download_size_hr, self.mandatory_qty) self.optional_download_msg = 'Optional packages download size: {} ({} packages)'.format( self.optional_download_size_hr, self.optional_qty) self.mandatory_install_msg = 'Mandatory packages installation size: {}'.format( self.mandatory_install_size_hr) self.optional_install_msg = 'Optional packages installation size: {}'.format( self.optional_install_size_hr) self.all_download_msg = 'All packages download size: {} ({}) packages'.format( self.all_download_size_hr, self.all_qty) LOG.debug(self.all_download_msg) self.all_install_msg = 'All packages installation size: {}'.format( self.all_install_size_hr) self.mandatory_dld_ins_msg = 'Mandatory packages download/install size: {}/{} ({} packages)'.format( self.mandatory_download_size_hr, self.mandatory_install_size_hr, self.mandatory_qty) self.optional_dld_ins_msg = 'Optional packages download/install size: {}/{} ({} packages)'.format( self.optional_download_size_hr, self.optional_install_size_hr, self.optional_qty) self.all_dld_ins_msg = 'All packages download/install size: {}/{} ({}) packages'.format( self.all_download_size_hr, self.all_install_size_hr, self.all_qty) if config.DMG_DEPLOY_FILE: self.mandatory_dld_ins_msg = self.mandatory_dld_ins_msg.replace( 'download/install', 'install') self.mandatory_dld_ins_msg = self.mandatory_dld_ins_msg.replace( '{}/'.format(self.mandatory_download_size_hr), '') self.optional_dld_ins_msg = self.optional_dld_ins_msg.replace( 'download/install', 'install') self.optional_dld_ins_msg = self.optional_dld_ins_msg.replace( '{}/'.format(self.optional_download_size_hr), '') self.all_dld_ins_msg = self.all_dld_ins_msg.replace( 'download/install', 'install') self.all_dld_ins_msg = self.all_dld_ins_msg.replace( '{}/'.format(self.all_download_size_hr), '') LOG.debug(self.mandatory_dld_ins_msg) LOG.debug(self.optional_dld_ins_msg) LOG.debug(self.all_dld_ins_msg) self.stats_message = '{}'.format(self.all_dld_ins_msg) if config.OPTIONAL: self.stats_message = '{}\n{}'.format(self.optional_dld_ins_msg, self.stats_message) if config.MANDATORY: self.stats_message = '{}\n{}'.format(self.mandatory_dld_ins_msg, self.stats_message)
def __init__(self, **kwargs): # Set attributes based on 'VALID_KWARGS' for kwarg, value in self.VALID_KWARGS.items(): if kwarg in kwargs.keys(): setattr(self, kwarg, kwargs.get(kwarg, None)) else: setattr(self, kwarg, value) # pylint: disable=access-member-before-definition # Fix any instances where the 'PackageID' contains spaces. if hasattr(self, 'PackageID'): self.PackageID = self.PackageID.replace('. ', '.') # Fix the Apple 'PackageVersion' attribute to a 'LooseVersion' type. if hasattr(self, 'PackageVersion'): if isinstance(self.PackageVersion, (float, int)): self.PackageVersion = u'{}'.format(self.PackageVersion) self.PackageVersion = LooseVersion(self.PackageVersion) # Convert 'DownloadSize' and 'InstalledSize' to int if hasattr(self, 'DownloadSize'): # if self.DownloadSize: self.DownloadSize = int(self.DownloadSize) self.HumanDownloadSize = misc.bytes2hr(byte=self.DownloadSize) if hasattr(self, 'InstalledSize'): # if self.InstalledSize: self.InstalledSize = int(self.InstalledSize) self.HumanInstalledSize = misc.bytes2hr(byte=self.InstalledSize) # Now handle some of the appleloops specific attributes. if hasattr(self, 'DownloadName'): basename = path.basename(self.DownloadName) self.DownloadURL = '{}/{}/{}'.format(config.AUDIOCONTENT_URL, config.LP10_MS3_CONTENT, basename) lp10_str = 'lp10_ms3_content_2016' if '../lp10_ms3_content_2013/' in self.DownloadName: lp10_str = 'lp10_ms3_content_2013' self.DownloadURL = self.DownloadURL.replace( 'lp10_ms3_content_2016', lp10_str) # Can probably get away with removing the '2013' path from the 'DownloadName' attr. self.DownloadName = self.DownloadName.replace( '../{}/'.format(lp10_str), '') # Handle if there's a DMG to build/deploy from if config.DMG_FILE or config.HTTP_DMG: _dest_path = config.DMG_VOLUME_MOUNTPATH else: _dest_path = config.DESTINATION_PATH if config.DESTINATION_PATH else config.DEFAULT_DEST self.DownloadPath = path.join(_dest_path, lp10_str, self.DownloadName) if hasattr(self, 'DownloadURL'): if config.LOCAL_HTTP_SERVER: # If this isn't a HTTP DMG being mounted, set the download url if not config.HTTP_DMG: self.LocalDownloadURL = self.DownloadURL.replace( config.AUDIOCONTENT_URL, config.LOCAL_HTTP_SERVER) if config.CACHING_SERVER: parsed_url = urlparse(self.DownloadURL) self.CacheDownloadURL = '{}{}?source={}'.format( config.CACHING_SERVER, parsed_url.path, parsed_url.netloc) # pylint: enable=access-member-before-definition # CURL requests for actual download sizes but only if specified. if config.REAL_DOWNLOAD_SIZE: if self.LocalDownloadURL: req = curl_requests.CURL(url=self.LocalDownloadURL) elif not self.LocalDownloadURL: req = curl_requests.CURL(url=self.DownloadURL) if req.status == 200: try: self.RealDownloadSize = req.headers['Content-Length'] except KeyError: try: self.RealDownloadSize = req.headers['content-length'] except KeyError: pass if self.RealDownloadSize: self.HumanRealDownloadSize = misc.bytes2hr( byte=self.RealDownloadSize)