def ExtractArchive(self, archive, extract_dir, rename_from_dir, rename_to_dir): tar_file = None archive_path = os.path.join(self.user_data_dir, archive) extract_path = os.path.join(self.install_dir, extract_dir) rename_from_path = os.path.join(self.install_dir, rename_from_dir) rename_to_path = os.path.join(self.install_dir, rename_to_dir) # Extract to extract_dir, usually "<bundle name>_update". # This way if the extraction fails, we haven't blown away the old bundle # (if it exists). sdk_update_common.RemoveDir(extract_path) sdk_update_common.MakeDirs(extract_path) curpath = os.getcwd() tar_file = None try: try: tar_file = cygtar.CygTar(archive_path, 'r', verbose=True) except Exception as e: raise Error('Can\'t open archive "%s".\n %s' % (archive_path, e)) try: logging.info('Changing the directory to %s' % (extract_path, )) os.chdir(extract_path) except Exception as e: raise Error('Unable to chdir into "%s".\n %s' % (extract_path, e)) logging.info('Extracting to %s' % (extract_path, )) tar_file.Extract() logging.info('Changing the directory to %s' % (curpath, )) os.chdir(curpath) logging.info('Renaming %s->%s' % (rename_from_path, rename_to_path)) sdk_update_common.RenameDir(rename_from_path, rename_to_path) finally: # Change the directory back so we can remove the update directory. os.chdir(curpath) # Clean up the ..._update directory. try: sdk_update_common.RemoveDir(extract_path) except Exception as e: logging.error('Failed to remove directory \"%s\". %s' % (extract_path, e)) if tar_file: tar_file.Close() # Remove the archive. os.remove(archive_path)
def Uninstall(install_dir, local_manifest, bundle_names): valid_bundles, invalid_bundles = \ command_common.GetValidBundles(local_manifest, bundle_names) if invalid_bundles: logging.warn('Unknown bundle(s): %s\n' % (', '.join(invalid_bundles))) if not valid_bundles: logging.warn('No bundles to uninstall.') return for bundle_name in valid_bundles: logging.info('Removing %s' % (bundle_name, )) bundle_dir = os.path.join(install_dir, bundle_name) try: sdk_update_common.RemoveDir(bundle_dir) except Exception as e: logging.error('Failed to remove directory \"%s\". %s' % (bundle_dir, e)) continue local_manifest.RemoveBundle(bundle_name)
def ExtractArchives(self, archives, extract_dir, rename_from_dir, rename_to_dir): tar_file = None extract_path = os.path.join(self.install_dir, extract_dir) rename_from_path = os.path.join(self.install_dir, rename_from_dir) rename_to_path = os.path.join(self.install_dir, rename_to_dir) # Extract to extract_dir, usually "<bundle name>_update". # This way if the extraction fails, we haven't blown away the old bundle # (if it exists). sdk_update_common.RemoveDir(extract_path) sdk_update_common.MakeDirs(extract_path) curpath = os.getcwd() tar_file = None try: try: logging.info('Changing the directory to %s' % (extract_path, )) os.chdir(extract_path) except Exception as e: raise Error('Unable to chdir into "%s".\n %s' % (extract_path, e)) for i, archive in enumerate(archives): archive_path = os.path.join(self.archive_cache, archive) if len(archives) > 1: print '(file %d/%d - "%s")' % ( i + 1, len(archives), os.path.basename(archive_path)) logging.info('Extracting to %s' % (extract_path, )) if sys.platform == 'win32': try: logging.info('Opening file %s (%d/%d).' % (archive_path, i + 1, len(archives))) try: tar_file = cygtar.CygTar(archive_path, 'r', verbose=True) except Exception as e: raise Error("Can't open archive '%s'.\n %s" % (archive_path, e)) tar_file.Extract() finally: if tar_file: tar_file.Close() else: try: subprocess.check_call(['tar', 'xf', archive_path]) except subprocess.CalledProcessError: raise Error('Error extracting archive: %s' % archive_path) logging.info('Changing the directory to %s' % (curpath, )) os.chdir(curpath) logging.info('Renaming %s->%s' % (rename_from_path, rename_to_path)) sdk_update_common.RenameDir(rename_from_path, rename_to_path) finally: # Change the directory back so we can remove the update directory. os.chdir(curpath) # Clean up the ..._update directory. try: sdk_update_common.RemoveDir(extract_path) except Exception as e: logging.error('Failed to remove directory \"%s\". %s' % (extract_path, e))