def get_agent_app(self): try: agent_app = CreateApplication.create( settings.AgentName, settings.AgentVersion, settings.AgentDescription, # description [], # file_data [], # dependencies '', # support_url '', # vendor_severity '', # file_size '', # vendor_id, '', # vendor_name settings.AgentInstallDate, # install_date None, # release_date True, # installed "", # repo "no", # reboot_required "no" # uninstallable ) return agent_app except Exception as e: logger.error("Failed to create agent application instance.") logger.exception(e) return {}
def install_update(self, install_data, update_dir=None): logger.debug('Received install_update call.') success = 'false' error = '' restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] old_install_list = self.get_installed_applications() success, error, restart = self._yum_update(install_data.name) if success == 'true': new_install_list = self.get_installed_applications() app = self._get_installed_app(install_data.name, new_install_list) app_encoding = app.to_dict() apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete( old_install_list, new_install_list ) return InstallResult( success, error, restart, app_encoding, apps_to_delete, apps_to_add )
def install_update(self, install_data, update_dir=None): """ Install OS X updates. Returns: Installation result """ # Use to get the apps to be removed on the server side old_install_list = self.get_installed_applications() success = 'false' error = RvError.UpdatesNotFound restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] if not update_dir: update_dir = settings.UpdatesDirectory #update_data = self._macsqlite.get_update_data( # install_data.name #) if install_data.downloaded: success, error = self.pkg_installer.install(install_data) if success != 'true': logger.debug( "Failed to install update {0}. success:{1}, error:{2}". format(install_data.name, success, error)) # Let the OS take care of downloading and installing. success, error = \ self.pkg_installer.complete_softwareupdate(install_data) else: logger.debug( ("Downloaded = False for: {0} calling " "complete_softwareupdate.").format(install_data.name)) success, error = \ self.pkg_installer.complete_softwareupdate(install_data) if success == 'true': #restart = update_data.get(UpdateDataColumn.NeedsRestart, 'false') restart = self._get_reboot_required(install_data.name) new_install_list = self.get_installed_applications() app_encoding = self._get_app_encoding(install_data.name, new_install_list) apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete( old_install_list, new_install_list) return InstallResult(success, error, restart, app_encoding, apps_to_delete, apps_to_add)
def install_update(self, install_data, update_dir=None): logger.debug('Received install_update call.') old_install_list = self.get_installed_applications() success = 'false' error = '' restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] success, error, restart = self._yum_update(install_data.name) if success == 'true': new_install_list = self.get_installed_applications() app = self._get_installed_app(install_data.name, new_install_list) app_encoding = app.to_dict() apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete( old_install_list, new_install_list ) return InstallResult( success, error, restart, app_encoding, apps_to_delete, apps_to_add )
def _get_installed_app(self, name): installed_packages = self._get_installed_packages() pkg_dict = installed_packages.get(name, {}) if not pkg_dict: return CreateApplication.null_application() return self._create_app_from_dict(pkg_dict)
def create_apps_from_plist_dicts(self, app_dicts): applications = [] for app_dict in app_dicts: try: # Skip app, no name. if not 'name' in app_dict: continue app_name = app_dict['name'] release_date = self._get_package_release_date(app_name) file_data = self._get_file_data(app_name) dependencies = [] app_inst = CreateApplication.create( app_name, app_dict['version'], # Just in case there's HTML, strip it out MacOpHandler._strip_body_tags(app_dict['description']) # and get rid of newlines. .replace('\n', ''), file_data, # file_data dependencies, '', # support_url '', # vendor_severity '', # file_size app_dict['productKey'], # vendor_id 'Apple', # vendor_name None, # install_date release_date, # release_date False, # installed '', # repo app_dict['restartRequired'].lower(), # reboot_required 'yes' # TODO: check if app is uninstallable ) applications.append(app_inst) #self._add_update_data( # app_inst.name, # app_dict['restartRequired'] #) except Exception as e: logger.error( "Failed to create an app instance for: {0}" .format(app_dict['name']) ) logger.exception(e) return applications
def create_apps_from_plist_dicts(self, app_dicts): applications = [] for app_dict in app_dicts: try: # Skip app, no name. if not 'name' in app_dict: continue app_name = app_dict['name'] release_date = self._get_package_release_date(app_name) file_data = self._get_file_data(app_name) dependencies = [] app_inst = CreateApplication.create( app_name, app_dict['version'], # Just in case there's HTML, strip it out MacOpHandler._strip_body_tags(app_dict['description']) # and get rid of newlines. .replace('\n', ''), file_data, # file_data dependencies, '', # support_url '', # vendor_severity '', # file_size app_dict['productKey'], # vendor_id 'Apple', # vendor_name None, # install_date release_date, # release_date False, # installed '', # repo app_dict['restartRequired'].lower(), # reboot_required 'yes' # TODO: check if app is uninstallable ) applications.append(app_inst) #self._add_update_data( # app_inst.name, # app_dict['restartRequired'] #) except Exception as e: logger.error( "Failed to create an app instance for: {0}".format( app_dict['name'])) logger.exception(e) return applications
def _install_operation(self, operation): # TODO: if operation specifies update directory, change to that update_dir = settings.UpdatesDirectory failed_to_download = False urn_response = RvUrn.get_operation_urn(operation.type) try: self._download_updates(operation) except Exception as e: logger.error("Error occured while downloading updates.") logger.exception(e) failed_to_download = True if not operation.install_data_list or failed_to_download: error = RvError.UpdatesNotFound if failed_to_download: error = 'Failed to download packages.' rvsof_result = RvSofResult( operation.id, operation.type, '', # app id [], # apps_to_delete [], # apps_to_add 'false', # success 'false', # restart error, # error CreateApplication.null_application().to_dict(), # app json urn_response, RequestMethod.PUT ) self._send_results(rvsof_result) else: if operation.type == RvOperationValue.InstallAgentUpdate: self._agent_update(operation, update_dir) # TODO(urgent): remove this, only for testing #elif operation.type == RvOperationValue.InstallCustomApps: # self._agent_update(operation, update_dir) else: self._regular_update(operation, update_dir)
def install_update(self, install_data, update_dir=None): logger.debug('Received install_update call.') old_install_list = self.get_installed_applications() success = 'false' error = '' restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] if not update_dir: update_dir = settings.UpdatesDirectory if install_data.downloaded: packages_dir = os.path.join(update_dir, install_data.id) success, error, restart = self._yum_local_update( install_data.name, packages_dir, install_data.proc_niceness ) if success == 'true': new_install_list = self.get_installed_applications() app = self._get_installed_app( install_data.name, new_install_list ) app_encoding = app.to_dict() apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete( old_install_list, new_install_list ) else: logger.debug("Downloaded = False for: {0}" .format(install_data.name)) error = "Failed to download packages." return InstallResult( success, error, restart, app_encoding, apps_to_delete, apps_to_add )
def _install_operation(self, operation): # TODO: if operation specifies update directory, change to that update_dir = settings.UpdatesDirectory failed_to_download = False urn_response = RvUrn.get_operation_urn(operation.type) try: self._download_updates(operation) except Exception as e: logger.error("Error occured while downloading updates.") logger.exception(e) failed_to_download = True if not operation.install_data_list or failed_to_download: error = RvError.UpdatesNotFound if failed_to_download: error = 'Failed to download packages.' rvsof_result = RvSofResult( operation.id, operation.type, '', # app id [], # apps_to_delete [], # apps_to_add 'false', # success 'false', # restart error, # error CreateApplication.null_application().to_dict(), # app json urn_response, RequestMethod.PUT) self._send_results(rvsof_result) else: if operation.type == RvOperationValue.InstallAgentUpdate: self._agent_update(operation, update_dir) # TODO(urgent): remove this, only for testing #elif operation.type == RvOperationValue.InstallCustomApps: # self._agent_update(operation, update_dir) else: self._regular_update(operation, update_dir)
def install_update(self, install_data, update_dir=None): logger.debug('Received install_update call.') old_install_list = self.get_installed_applications() success = 'false' error = RvError.UpdatesNotFound restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] if not update_dir: update_dir = settings.UpdatesDirectory packages_dir = os.path.join(update_dir, install_data.id) moving_error = self._move_pkgs_to_apt_dir(packages_dir) if not moving_error: success, error, restart = self._apt_install( install_data.name, install_data.proc_niceness ) if success == 'true': app = self._get_installed_app(install_data.name) app_encoding = app.to_dict() apps_to_add, apps_to_delete = \ self._get_apps_to_add_and_delete(old_install_list) else: error = moving_error # TODO(urgent): should I apt-get clean here or in rv_plugin? return InstallResult( success, error, restart, app_encoding, apps_to_delete, apps_to_add )
def install_update(self, install_data, update_dir=None): logger.debug('Received install_update call.') old_install_list = self.get_installed_applications() success = 'false' error = '' restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] if not update_dir: update_dir = settings.UpdatesDirectory if install_data.downloaded: packages_dir = os.path.join(update_dir, install_data.id) success, error, restart = self._yum_local_update( install_data.name, packages_dir, install_data.proc_niceness) if success == 'true': new_install_list = self.get_installed_applications() app = self._get_installed_app(install_data.name, new_install_list) app_encoding = app.to_dict() apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete( old_install_list, new_install_list) else: logger.debug("Downloaded = False for: {0}".format( install_data.name)) error = "Failed to download packages." return InstallResult(success, error, restart, app_encoding, apps_to_delete, apps_to_add)
def install_update(self, install_data, update_dir=None): logger.debug('Received install_update call.') old_install_list = self.get_installed_applications() success = 'false' error = RvError.UpdatesNotFound restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] if not update_dir: update_dir = settings.UpdatesDirectory packages_dir = os.path.join(update_dir, install_data.id) moving_error = self._move_pkgs_to_apt_dir(packages_dir) if not moving_error: success, error, restart = self._apt_install( install_data.name, install_data.proc_niceness) if success == 'true': app = self._get_installed_app(install_data.name) app_encoding = app.to_dict() apps_to_add, apps_to_delete = \ self._get_apps_to_add_and_delete(old_install_list) else: error = moving_error # TODO(urgent): should I apt-get clean here or in rv_plugin? return InstallResult(success, error, restart, app_encoding, apps_to_delete, apps_to_add)
def get_installed_updates(self): """ Parses the /Library/Receipts/InstallHistory.plist file looking for 'Software Update' as the process name. """ logger.info("Getting installed updates.") install_history = '/Library/Receipts/InstallHistory.plist' installed_updates = [] try: if os.path.exists(install_history): app_data = self.plist.read_plist(install_history) for app in app_data: app_inst = None try: if app.get('processName') == 'Software Update': if not 'displayName' in app: continue app_name = app['displayName'] app_name = app.get('displayName', '') app_version = app.get('displayVersion', '') app_date = app.get('date', '') app_inst = CreateApplication.create( app_name, app_version, '', # description [], # file_data [], # dependencies '', # support_url '', # vendor_severity '', # file_size # vendor_id hashlib.sha256( app_name.encode('utf-8') + app_version).hexdigest(), 'Apple', # vendor_name app_date, # install_date None, # release_date True, # installed "", # repo "no", # reboot_required "yes" # TODO: check if app is uninstallable ) except Exception as e: logger.error("Error verifying installed update." "Skipping.") logger.exception(e) if app_inst: installed_updates.append(app_inst) except Exception as e: logger.error("Error verifying installed updates.") logger.exception(e) logger.info('Done.') return installed_updates
def install_update(self, install_data, update_dir=None): """ Install OS X updates. Returns: Installation result """ # Use to get the apps to be removed on the server side old_install_list = self.get_installed_applications() success = 'false' error = RvError.UpdatesNotFound restart = 'false' app_encoding = CreateApplication.null_application().to_dict() apps_to_delete = [] apps_to_add = [] if not update_dir: update_dir = settings.UpdatesDirectory #update_data = self._macsqlite.get_update_data( # install_data.name #) if install_data.downloaded: success, error = self.pkg_installer.install(install_data) if success != 'true': logger.debug( "Failed to install update {0}. success:{1}, error:{2}" .format(install_data.name, success, error) ) # Let the OS take care of downloading and installing. success, error = \ self.pkg_installer.complete_softwareupdate(install_data) else: logger.debug(("Downloaded = False for: {0} calling " "complete_softwareupdate.") .format(install_data.name)) success, error = \ self.pkg_installer.complete_softwareupdate(install_data) if success == 'true': #restart = update_data.get(UpdateDataColumn.NeedsRestart, 'false') restart = self._get_reboot_required(install_data.name) new_install_list = self.get_installed_applications() app_encoding = self._get_app_encoding( install_data.name, new_install_list ) apps_to_add, apps_to_delete = self._get_apps_to_add_and_delete( old_install_list, new_install_list ) return InstallResult( success, error, restart, app_encoding, apps_to_delete, apps_to_add )
def _get_installed_app(self, name, installed_apps): for app in installed_apps: if app.name == name: return app return CreateApplication.null_application()
def get_installed_updates(self): """ Parses the /Library/Receipts/InstallHistory.plist file looking for 'Software Update' as the process name. """ logger.info("Getting installed updates.") install_history = '/Library/Receipts/InstallHistory.plist' installed_updates = [] try: if os.path.exists(install_history): app_data = self.plist.read_plist(install_history) for app in app_data: app_inst = None try: if app.get('processName') == 'Software Update': if not 'displayName' in app: continue app_name = app['displayName'] app_name = app.get('displayName', '') app_version = app.get('displayVersion', '') app_date = app.get('date', '') app_inst = CreateApplication.create( app_name, app_version, '', # description [], # file_data [], # dependencies '', # support_url '', # vendor_severity '', # file_size # vendor_id hashlib.sha256( app_name.encode('utf-8') + app_version) .hexdigest(), 'Apple', # vendor_name app_date, # install_date None, # release_date True, # installed "", # repo "no", # reboot_required "yes" # TODO: check if app is uninstallable ) except Exception as e: logger.error("Error verifying installed update." "Skipping.") logger.exception(e) if app_inst: installed_updates.append(app_inst) except Exception as e: logger.error("Error verifying installed updates.") logger.exception(e) logger.info('Done.') return installed_updates
def get_available_updates(self): logger.debug('Getting available updates.') try: logger.debug("Renewing repo cache.") yum.renew_repo_cache() logger.debug("Done renewing repo cache.") logger.debug("Getting list of available updates.") cmd = [yum.yum_cmd, 'info', 'updates', '-v'] output, err = self.utilcmds.run_command(cmd) if err: raise Exception(err) avail_updates = self.yum_parse.parse_info_updates(output) logger.debug("Done getting list of available updates.") logger.debug("Getting severity of packages.") cmd = [yum.yum_cmd, 'list-security'] output, err = self.utilcmds.run_command(cmd) if err: logger.error("Failed to get package severities.") logger.exception(err) severity_of_pkgs = {} else: severity_of_pkgs = self.yum_parse.parse_pkg_severity(output) logger.debug("Done getting severity of packages.") # For logging i = 1 total = len(avail_updates) applications = [] for pkg in avail_updates: try: app_name = pkg.get(PkgKeys.name, '') dependencies = self._get_dependencies( app_name, pkg[PkgKeys.version], pkg[PkgKeys.release], pkg[PkgKeys.arch] ) lookup_name = pkg.get(PkgKeys.lookup_name, '') vendor_severity = \ severity_of_pkgs.get(lookup_name, '') app = CreateApplication.create( app_name, pkg[PkgKeys.full_version], pkg[PkgKeys.description], # description [], # file_data dependencies, # dependencies '', # support_url vendor_severity, # vendor_severity '', # file_size '', # vendor_id, '', # vendor_name None, # install_date pkg[PkgKeys.release_date], # release_date False, # installed "", # repo "no", # reboot_required "yes" # TODO: check if app is uninstallable ) if app: logger.debug(app) applications.append(app) logger.debug("{0} out of {1} finished.".format(i, total)) i += 1 except Exception as e: logger.error( "Failed to create app for: {0}".format(app_name) ) logger.exception(e) continue logger.debug("Done getting available updates.") return applications except Exception as e: logger.error("Failed to retrieve available updates.") logger.exception(e) return []
def get_installed_applications(self): """Parses the output from the 'system_profiler -xml SPApplicationsDataType' command. """ logger.info("Getting installed applications.") installed_apps = [] try: cmd = [ '/usr/sbin/system_profiler', '-xml', 'SPApplicationsDataType' ] output, _error = self.utilcmds.run_command(cmd) app_data = self.plist.read_plist_string(output) for apps in app_data: for app in apps['_items']: app_inst = None try: # Skip app, no name. if not '_name' in app: continue app_name = app['_name'] app_version = app.get('version', '') app_date = app.get('lastModified', '') app_inst = CreateApplication.create( app_name, app_version, '', # description [], # file_data [], # dependencies '', # support_url '', # vendor_severity '', # file_size '', # vendor_id, '', # vendor_name app_date, # install_date None, # release_date True, # installed "", # repo "no", # reboot_required "yes" # TODO: check if app is uninstallable ) except Exception as e: logger.error("Error verifying installed application." "Skipping.") logger.exception(e) if app_inst: installed_apps.append(app_inst) installed_apps.extend(ThirdPartyManager.get_supported_installs()) except Exception as e: logger.error("Error verifying installed applications.") logger.exception(e) logger.info('Done.') return installed_apps
def get_installed_applications(self): """Gets installed RPM-based applications. Returns: - A list of Applications. """ logger.info('Getting installed packages.') installed_apps = [] # Get the data in a nice, easy, parsable format. query_separator = '**!TOPPATCH!**' query_format = ( '"%{{NAME}}{0}%{{VERSION}}-%{{RELEASE}}{0}%{{INSTALLTIME}}' '{0}%{{BUILDTIME}}{0}%{{SIZE}}{0}%{{VENDOR}}{0}' '%{{URL}}{0}%{{DESCRIPTION}}"'.format(query_separator) ) try: process = subprocess.Popen( ['rpm', '-qa'], stdout=subprocess.PIPE, stderr=subprocess.PIPE ) output, _stderr = process.communicate() output = ( output .decode(settings.default_decoder) .encode(settings.default_encoder) ) installed_list = output.splitlines() for app in installed_list: try: rpm_query = \ ['rpm', '-q', app, '--queryformat', query_format] process = subprocess.Popen( rpm_query, stdout=subprocess.PIPE ) output, _stderr = process.communicate() output = ( output .decode(settings.default_decoder) .encode(settings.default_encoder) ) app_info = output.split(query_separator) # Little bit of cleanup name = app_info[RpmQueryInfo.Name] if name.startswith('"'): name = name[1:] description = app_info[RpmQueryInfo.Description] description = description.replace('\n', ' ') if description.endswith('"'): description = description[0:-1] ####################### application = CreateApplication.create( name, # app name app_info[RpmQueryInfo.Version], # app version description, # app description [], # file_data [], # dependencies app_info[RpmQueryInfo.Url], # support url '', # vendor_severity app_info[RpmQueryInfo.Size], # app size '', # vendor_id app_info[RpmQueryInfo.Vendor], # app's vendor app_info[RpmQueryInfo.InstallDate], # install_date app_info[RpmQueryInfo.ReleaseDate], # release_date True, # installed '', # repo 'no', # reboot_required 'yes' # TODO: check if app is uninstallable ) except Exception as e: logger.error( "Error while checking installed application. Skipping" ) logger.exception(e) application = None if application: installed_apps.append(application) except Exception as e: logger.error("Error while checking installed applications.") logger.exception(e) logger.info('Done.') return installed_apps
def _create_app_from_dict(self, package_dictionary, update_app=False): """Convert package dictionary into an instance of application. Arguments: update_app - Takes extra steps for update applications """ app_name = package_dictionary.get(PkgDictValues.name, '') # TODO: change installed to status according to server specs installed = 'false' install_date = '' if not update_app: status = package_dictionary.get(PkgDictValues.installed, '') installed = status == self.INSTALLED_STATUS install_date = self._get_install_date(app_name) release_date = '' file_data = [] dependencies = [] if update_app: file_data = package_dictionary.get('file_data', []) if file_data: try: release_date = \ self._get_release_date( file_data[0].get(FileDataKeys.uri, '') ) except Exception as e: logger.error('Failed to get release date for {0}' .format(app_name)) logger.exception(e) support_url = package_dictionary.get(PkgDictValues.support_url, '') repo = package_dictionary.get('repo', '') description = package_dictionary.get(PkgDictValues.description, '') if not description: # Try other possible description key description = \ package_dictionary.get(PkgDictValues.description_en, '') application = \ CreateApplication.create( app_name, package_dictionary.get(PkgDictValues.version, ''), description, file_data, dependencies, support_url, package_dictionary.get(PkgDictValues.vendor_severity, ''), package_dictionary.get(PkgDictValues.file_size, ''), "", # Vendor id "", # Vendor name install_date, release_date, installed, repo, "no", # TODO(urgent): figure out if an app requires a reboot "yes" # TODO(urgent): figure out if an app is uninstallable ) return application
def get_installed_applications(self): """Gets installed RPM-based applications. Returns: - A list of Applications. """ logger.info('Getting installed packages.') installed_apps = [] # Get the data in a nice, easy, parsable format. query_separator = '**!TOPPATCH!**' query_format = ( '"%{{NAME}}{0}%{{VERSION}}-%{{RELEASE}}{0}%{{INSTALLTIME}}' '{0}%{{BUILDTIME}}{0}%{{SIZE}}{0}%{{VENDOR}}{0}' '%{{URL}}{0}%{{DESCRIPTION}}"'.format(query_separator)) try: process = subprocess.Popen(['rpm', '-qa'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) output, _stderr = process.communicate() output = (output.decode(settings.default_decoder).encode( settings.default_encoder)) installed_list = output.splitlines() for app in installed_list: try: rpm_query = \ ['rpm', '-q', app, '--queryformat', query_format] process = subprocess.Popen(rpm_query, stdout=subprocess.PIPE) output, _stderr = process.communicate() output = (output.decode(settings.default_decoder).encode( settings.default_encoder)) app_info = output.split(query_separator) # Little bit of cleanup name = app_info[RpmQueryInfo.Name] if name.startswith('"'): name = name[1:] description = app_info[RpmQueryInfo.Description] description = description.replace('\n', ' ') if description.endswith('"'): description = description[0:-1] ####################### application = CreateApplication.create( name, # app name app_info[RpmQueryInfo.Version], # app version description, # app description [], # file_data [], # dependencies app_info[RpmQueryInfo.Url], # support url '', # vendor_severity app_info[RpmQueryInfo.Size], # app size '', # vendor_id app_info[RpmQueryInfo.Vendor], # app's vendor app_info[RpmQueryInfo.InstallDate], # install_date app_info[RpmQueryInfo.ReleaseDate], # release_date True, # installed '', # repo 'no', # reboot_required 'yes' # TODO: check if app is uninstallable ) except Exception as e: logger.error( "Error while checking installed application. Skipping") logger.exception(e) application = None if application: installed_apps.append(application) except Exception as e: logger.error("Error while checking installed applications.") logger.exception(e) logger.info('Done.') return installed_apps
def _get_installed_app(self, name, install_list): for app in install_list: if app.name == name: return app return CreateApplication.null_application()
def get_available_updates(self): """Gets available updates, as Appliation instances, through yum. Returns: - A list of Applications. """ logger.info('Getting available updates.') updates = [] try: yum.renew_repo_cache() updates_available = yum.list_updates() rd = RepoData() primary_files = {} # For logging i = 1 total = len(updates_available) for update in updates_available: application = None try: #deps = yum.get_needed_dependencies(update) repo = rd.get_repo(update.repo) if not repo.id: logger.info( "No primary.xml data for {0}. Skipping.".format( update.name)) continue if repo.id not in primary_files: primary_files[repo.id] = get_primary_file(repo.id, rd) meta_packages = (primary_files[repo.id].find_packages( update.name)) mp = None for pkg in meta_packages: if (pkg.name == update.name and pkg.version == update.version and pkg.release == update.release and pkg.arch == update.arch): mp = pkg #file_data = self._create_file_data( # mp, # deps, # repo, # primary_files, # rd #) file_data = self._create_file_data(mp, repo) dependencies = self._get_dependencies( mp.name, mp.version, mp.release, mp.arch) application = CreateApplication.create( mp.name, mp.complete_version, mp.description, # description file_data, # file_data dependencies, # dependencies mp.url, # support_url '', # vendor_severity mp.size, # file_size '', # vendor_id, mp.vendor, # vendor_name None, # install_date mp.release_date, # release_date False, # installed repo.name, # repo "no", # reboot_required "yes" # TODO: Is app uninstallable? ) break except Exception as e: logger.error("Could not get available update. Skipping.") logger.exception(e) if application: updates.append(application) logger.debug(application) logger.debug("{0} out of {1} finished.".format(i, total)) i += 1 # Append all dependencies' file_data to app's file_data. # Must be done after getting all apps. for update in updates: self._append_file_data(update, updates) except Exception as e: logger.error("Could not get available updates.") logger.exception(e) logger.info('Done.') return updates
def oracle_jre_install(): JRE7_root_path = '/Library/Internet Plug-Ins/JavaAppletPlugin.plugin/' JRE7_command = os.path.join(JRE7_root_path, 'Contents/Home/bin/java') application = CreateApplication.null_application() try: if os.path.exists(JRE7_command): # For some sane reason, '-version' spits output to the # stderr... output = subprocess.check_output([JRE7_command, '-version'], stderr=subprocess.STDOUT) # Output example: # java version "1.7.0_21" # Java(TM) SE Runtime Environment (build 1.7.0_21-b12) # Java HotSpot(TM) 64-Bit Server VM (build 23.21-b01, mixed mode) if '64-Bit' in output.splitlines()[2]: bit_type = '64' else: bit_type = '32' app_name = 'Java ' + bit_type app_vendor_name = 'Oracle' raw_ver = 'NA' try: raw_ver = output.splitlines()[0].split('"')[1] version = raw_ver.replace('_', '.') + '0' app_version = version.partition('.')[2] except Exception as e: logger.error("Unknown Java version format: %s" % raw_ver) app_version = '' try: s = os.stat(JRE7_command) #app.install_date = datetime.fromtimestamp( # s.st_ctime).strftime('%m/%d/%Y') app_install_date = s.st_ctime except Exception as e: logger.error("Could not verify install date.") logger.exception(e) app_install_date = None application = CreateApplication.create( app_name, app_version, '', # description [], # file_data [], # dependencies '', # support_url '', # vendor_severity '', # file_size '', # vendor_id, app_vendor_name, # vendor_name app_install_date, # install_date None, # release_date True, # installed "", # repo "no", # reboot_required "yes" # TODO: check if app is uninstallable ) except Exception as e: logger.error("Could not verify Oracle Java install.") logger.exception(e) return application
def get_installed_applications(self): """Parses the output from the 'system_profiler -xml SPApplicationsDataType' command. """ logger.info("Getting installed applications.") installed_apps = [] try: cmd = ['/usr/sbin/system_profiler', '-xml', 'SPApplicationsDataType'] output, _error = self.utilcmds.run_command(cmd) app_data = self.plist.read_plist_string(output) for apps in app_data: for app in apps['_items']: app_inst = None try: # Skip app, no name. if not '_name' in app: continue app_name = app['_name'] app_version = app.get('version', '') app_date = app.get('lastModified', '') app_inst = CreateApplication.create( app_name, app_version, '', # description [], # file_data [], # dependencies '', # support_url '', # vendor_severity '', # file_size '', # vendor_id, '', # vendor_name app_date, # install_date None, # release_date True, # installed "", # repo "no", # reboot_required "yes" # TODO: check if app is uninstallable ) except Exception as e: logger.error("Error verifying installed application." "Skipping.") logger.exception(e) if app_inst: installed_apps.append(app_inst) installed_apps.extend( ThirdPartyManager.get_supported_installs() ) except Exception as e: logger.error("Error verifying installed applications.") logger.exception(e) logger.info('Done.') return installed_apps
def get_available_updates(self): """Gets available updates, as Appliation instances, through yum. Returns: - A list of Applications. """ logger.info('Getting available updates.') updates = [] try: yum.renew_repo_cache() updates_available = yum.list_updates() rd = RepoData() primary_files = {} # For logging i = 1 total = len(updates_available) for update in updates_available: application = None try: #deps = yum.get_needed_dependencies(update) repo = rd.get_repo(update.repo) if not repo.id: logger.info( "No primary.xml data for {0}. Skipping." .format(update.name) ) continue if repo.id not in primary_files: primary_files[repo.id] = get_primary_file(repo.id, rd) meta_packages = ( primary_files[repo.id].find_packages(update.name) ) mp = None for pkg in meta_packages: if ( pkg.name == update.name and pkg.version == update.version and pkg.release == update.release and pkg.arch == update.arch ): mp = pkg #file_data = self._create_file_data( # mp, # deps, # repo, # primary_files, # rd #) file_data = self._create_file_data(mp, repo) dependencies = self._get_dependencies( mp.name, mp.version, mp.release, mp.arch ) application = CreateApplication.create( mp.name, mp.complete_version, mp.description, # description file_data, # file_data dependencies, # dependencies mp.url, # support_url '', # vendor_severity mp.size, # file_size '', # vendor_id, mp.vendor, # vendor_name None, # install_date mp.release_date, # release_date False, # installed repo.name, # repo "no", # reboot_required "yes" # TODO: Is app uninstallable? ) break except Exception as e: logger.error("Could not get available update. Skipping.") logger.exception(e) if application: updates.append(application) logger.debug(application) logger.debug("{0} out of {1} finished.".format(i, total)) i += 1 # Append all dependencies' file_data to app's file_data. # Must be done after getting all apps. for update in updates: self._append_file_data(update, updates) except Exception as e: logger.error("Could not get available updates.") logger.exception(e) logger.info('Done.') return updates
def _create_app_from_bundle_info(self, app_bundle_names): app_instances = [] for app_name in app_bundle_names: ## TODO: path for installing app bundles is hardcoded for now #app_path = os.path.join('/Applications', app_name + '.app') #cmd = ['mdls', app_path] #output, result = self.utilcmds.run_command(cmd) ## TODO(urgent): don't use the mdls module, it also runs on an OS X ## timer it seems. Meaning the applications meta data can't be read ## before a certain period of time. #for i in range(5): # info_dict = self._separate_important_info(output) # if info_dict: # # We're good, we got the info. Break out and let this do # # its thing. # break # # Give the OS some time to gather the data # logger.debug("Sleeping for 5.") # time.sleep(5) #if not info_dict: # logger.error( # "Could not get metadata for application: {0}" # .format(app_name) # ) # continue # TODO(urgent): stop hardcoding the path app_bundle_path = os.path.join('/Applications', app_name + '.app') info_dict = self._get_app_bundle_info(app_bundle_path) if not info_dict: logger.exception( "Failed to gather metadata for: {0}".format(app_name) ) continue app_inst = CreateApplication.create( info_dict['name'], info_dict['version'], '', # description [], # file_data [], # dependencies '', # support_url '', # vendor_severity '', # file_size '', # vendor_id, '', # vendor_name int(time.time()), # install_date None, # release_date True, # installed "", # repo "no", # reboot_required "yes" # TODO: check if app is uninstallable ) app_instances.append(app_inst) return app_instances
def _create_app_from_bundle_info(self, app_bundle_names): app_instances = [] for app_name in app_bundle_names: ## TODO: path for installing app bundles is hardcoded for now #app_path = os.path.join('/Applications', app_name + '.app') #cmd = ['mdls', app_path] #output, result = self.utilcmds.run_command(cmd) ## TODO(urgent): don't use the mdls module, it also runs on an OS X ## timer it seems. Meaning the applications meta data can't be read ## before a certain period of time. #for i in range(5): # info_dict = self._separate_important_info(output) # if info_dict: # # We're good, we got the info. Break out and let this do # # its thing. # break # # Give the OS some time to gather the data # logger.debug("Sleeping for 5.") # time.sleep(5) #if not info_dict: # logger.error( # "Could not get metadata for application: {0}" # .format(app_name) # ) # continue # TODO(urgent): stop hardcoding the path app_bundle_path = os.path.join('/Applications', app_name + '.app') info_dict = self._get_app_bundle_info(app_bundle_path) if not info_dict: logger.exception( "Failed to gather metadata for: {0}".format(app_name)) continue app_inst = CreateApplication.create( info_dict['name'], info_dict['version'], '', # description [], # file_data [], # dependencies '', # support_url '', # vendor_severity '', # file_size '', # vendor_id, '', # vendor_name int(time.time()), # install_date None, # release_date True, # installed "", # repo "no", # reboot_required "yes" # TODO: check if app is uninstallable ) app_instances.append(app_inst) return app_instances
def _create_app_from_dict(self, package_dictionary, update_app=False): """Convert package dictionary into an instance of application. Arguments: update_app - Takes extra steps for update applications """ app_name = package_dictionary.get(PkgDictValues.name, '') # TODO: change installed to status according to server specs installed = 'false' install_date = '' if not update_app: status = package_dictionary.get(PkgDictValues.installed, '') installed = status == self.INSTALLED_STATUS install_date = self._get_install_date(app_name) release_date = '' file_data = [] dependencies = [] if update_app: file_data = package_dictionary.get('file_data', []) if file_data: try: release_date = \ self._get_release_date( file_data[0].get(FileDataKeys.uri, '') ) except Exception as e: logger.error( 'Failed to get release date for {0}'.format(app_name)) logger.exception(e) support_url = package_dictionary.get(PkgDictValues.support_url, '') repo = package_dictionary.get('repo', '') description = package_dictionary.get(PkgDictValues.description, '') if not description: # Try other possible description key description = \ package_dictionary.get(PkgDictValues.description_en, '') application = \ CreateApplication.create( app_name, package_dictionary.get(PkgDictValues.version, ''), description, file_data, dependencies, support_url, package_dictionary.get(PkgDictValues.vendor_severity, ''), package_dictionary.get(PkgDictValues.file_size, ''), "", # Vendor id "", # Vendor name install_date, release_date, installed, repo, "no", # TODO(urgent): figure out if an app requires a reboot "yes" # TODO(urgent): figure out if an app is uninstallable ) return application