diff --git a/client/text_rescue.py b/client/text_rescue.py index 4e2c9f74a..a26f3b4f4 100644 --- a/client/text_rescue.py +++ b/client/text_rescue.py @@ -152,7 +152,7 @@ def _database_restore(entropy_client): mydblist = [] db_data = [] for mydb in dblist: - ts = entropy.tools.get_file_unix_mtime(mydb) + ts = os.path.getmtime(mydb) mytime = entropy.tools.convert_unix_time_to_human_time(ts) mydblist.append("[%s] %s" % (mytime, mydb,)) db_data.append(mydb) diff --git a/client/text_smart.py b/client/text_smart.py index 8262682fe..e065000db 100644 --- a/client/text_smart.py +++ b/client/text_smart.py @@ -388,7 +388,9 @@ def smartpackagegenerator(entropy_client, matched_pkgs): # merge packages for package in matched_pkgs: print_info(darkgreen(" * ")+brown(matchedAtoms[package]['atom'])+": "+red("unpacking content")) - rc = entropy.tools.uncompress_tar_bz2(etpConst['entropyworkdir']+os.path.sep+matchedAtoms[x]['download'], extractPath = unpackdir+"/content") + rc = entropy.tools.uncompress_tarball(etpConst['entropyworkdir'] + \ + os.path.sep+matchedAtoms[x]['download'], + extract_path = os.path.join(unpackdir, "content")) if rc != 0: print_error(darkred(" * ")+red("%s." % (_("Unpack failed due to unknown reasons"),))) return rc @@ -498,7 +500,7 @@ def smartgenerator(entropy_client, matched_atoms): print_info(darkgreen(" * ") + \ red("%s " % (_("Unpacking the main package"),)) + \ bold(str(pkgfilename))) - entropy.tools.uncompress_tar_bz2(main_bin_path, pkg_data_dir) # first unpack + entropy.tools.uncompress_tarball(main_bin_path, extract_path = pkg_data_dir) binary_execs = [] for item in pkgcontent: @@ -516,7 +518,8 @@ def smartgenerator(entropy_client, matched_atoms): print_info(darkgreen(" * ") + \ red("%s " % (_("Unpacking dependency package"),)) + bold(depatom)) deppath = os.path.join(etpConst['packagesbindir'], depbranch, download) - entropy.tools.uncompress_tar_bz2(deppath, pkg_data_dir) # first unpack + entropy.tools.uncompress_tarball(deppath, + extract_path = pkg_data_dir) # first unpack # now create the bash script for each binary_execs os.makedirs(pkg_data_dir+"/wrp") diff --git a/client/text_ui.py b/client/text_ui.py index 5ef51f8cd..373c09dd2 100644 --- a/client/text_ui.py +++ b/client/text_ui.py @@ -2017,7 +2017,8 @@ def libraries_test(listfiles = False, dump = False): return 0, 0 if (not brokenlibs) and (not pkgs_matched): - if not etpUi['quiet']: print_info(red(" @@ ")+blue("%s." % (_("System is healthy"),) )) + if not etpUi['quiet']: + print_info(red(" @@ ")+blue("%s." % (_("System is healthy"),) )) restore_qstats() return 0, 0 diff --git a/libraries/entropy/client/interfaces/package.py b/libraries/entropy/client/interfaces/package.py index ec26ef970..9715d09d4 100644 --- a/libraries/entropy/client/interfaces/package.py +++ b/libraries/entropy/client/interfaces/package.py @@ -391,10 +391,10 @@ class Package: unpack_tries -= 1 try: rc = entropy.tools.spawn_function( - entropy.tools.uncompress_tar_bz2, + entropy.tools.uncompress_tarball, self.pkgmeta['pkgpath'], - extractPath = self.pkgmeta['imagedir'], - catchEmpty = True + extract_path = self.pkgmeta['imagedir'], + catch_empty = True ) except EOFError: self.Entropy.clientLog.log( @@ -411,10 +411,10 @@ class Package: "Raising Unicode/Pickling Error for " + \ self.pkgmeta['pkgpath'] ) - rc = entropy.tools.uncompress_tar_bz2( + rc = entropy.tools.uncompress_tarball( self.pkgmeta['pkgpath'], - self.pkgmeta['imagedir'], - catchEmpty = True + extract_path = self.pkgmeta['imagedir'], + catch_empty = True ) if rc == 0: break diff --git a/libraries/entropy/security.py b/libraries/entropy/security.py index effceec36..cbe9944f8 100644 --- a/libraries/entropy/security.py +++ b/libraries/entropy/security.py @@ -470,10 +470,10 @@ class System: """ Unpack downloaded GLSA package containing GLSA advisories. """ - rc_unpack = entropy.tools.uncompress_tar_bz2( + rc_unpack = entropy.tools.uncompress_tarball( self.download_package, - self.unpacked_package, - catchEmpty = True + extract_path = self.unpacked_package, + catch_empty = True ) const_setup_perms(self.unpacked_package, etpConst['entropygid']) return rc_unpack diff --git a/libraries/entropy/server/interfaces/mirrors.py b/libraries/entropy/server/interfaces/mirrors.py index 81756aee1..1116d6421 100644 --- a/libraries/entropy/server/interfaces/mirrors.py +++ b/libraries/entropy/server/interfaces/mirrors.py @@ -3261,7 +3261,7 @@ class Server: return False srv_set = self.SystemSettings[self.sys_settings_plugin_id]['server'] - mtime = entropy.tools.get_file_unix_mtime(pkg_path) + mtime = os.path.getmtime(pkg_path) days = srv_set['packages_expiration_days'] delta = int(days)*24*3600 currmtime = time.time() diff --git a/libraries/entropy/spm/plugins/interfaces/portage_plugin/__init__.py b/libraries/entropy/spm/plugins/interfaces/portage_plugin/__init__.py index c291e56e5..6c7ddbe2f 100644 --- a/libraries/entropy/spm/plugins/interfaces/portage_plugin/__init__.py +++ b/libraries/entropy/spm/plugins/interfaces/portage_plugin/__init__.py @@ -762,8 +762,7 @@ class PortagePlugin(SpmPlugin): 'sha512': entropy.tools.sha512(package_file), 'gpg': None, # GPG signature will be filled later on, if enabled } - data['datecreation'] = str(entropy.tools.get_file_unix_mtime( - package_file)) + data['datecreation'] = str(os.path.getmtime(package_file)) data['size'] = str(entropy.tools.get_file_size(package_file)) tmp_dir = tempfile.mkdtemp() @@ -774,8 +773,8 @@ class PortagePlugin(SpmPlugin): # extract stuff xpaktools.extract_xpak(package_file, meta_dir) - entropy.tools.uncompress_tar_bz2(package_file, - extractPath = pkg_dir, catchEmpty = True) + entropy.tools.uncompress_tarball(package_file, + extract_path = pkg_dir, catch_empty = True) # package injection status always false by default # developer can change metadatum after this function @@ -3877,8 +3876,8 @@ class PortagePlugin(SpmPlugin): if not os.path.isdir(mytempdir): os.makedirs(mytempdir) - entropy.tools.uncompress_tar_bz2(package_path, extractPath = mytempdir, - catchEmpty = True) + entropy.tools.uncompress_tarball(package_path, + extract_path = mytempdir, catch_empty = True) tmpdir_len = len(mytempdir) for currentdir, subdirs, files in os.walk(mytempdir): pkg_content[currentdir[tmpdir_len:]] = dir_t @@ -3974,7 +3973,8 @@ class PortagePlugin(SpmPlugin): if len(foundfiles) > 1: # get the latest mtimes = [] - for item in foundfiles: mtimes.append((entropy.tools.get_file_unix_mtime(os.path.join(log_dir, item)), item)) + for item in foundfiles: mtimes.append( + (os.path.getmtime(os.path.join(log_dir, item)), item)) mtimes = sorted(mtimes) elogfile = mtimes[-1][1] messages = self._extract_elog(os.path.join(log_dir, elogfile)) diff --git a/libraries/entropy/tools.py b/libraries/entropy/tools.py index 73659b6a9..488615e38 100644 --- a/libraries/entropy/tools.py +++ b/libraries/entropy/tools.py @@ -2315,16 +2315,17 @@ def compress_tar_bz2(store_path, path_to_compress): def spawn_function(f, *args, **kwds): """ - docstring_title + Spawn given function with given arguments in a separate process and + return back its value (using pipes). - @param f: - @type f: - @param *args: - @type *args: - @param **kwds: - @type **kwds: - @return: - @rtype: + @param f: function to call + @type f: callable + @param *args: function arguments + @type *args: tuple + @param **kwds: function keyword arguments + @type **kwds: dict + @return: function result + @rtype: Python object """ uid = kwds.get('spf_uid') @@ -2374,30 +2375,30 @@ def spawn_function(f, *args, **kwds): f.close() os._exit(0) -# tar* uncompress function... -def uncompress_tar_bz2(filepath, extractPath = None, catchEmpty = False): +def uncompress_tarball(filepath, extract_path = None, catch_empty = False): """ - docstring_title - # FIXME: rename this and make bz2 independent + Unpack tarball file (supported compression algorithm is given by tarfile + module) respecting directory structure, mtime and permissions. - @param filepath: - @type filepath: - @keyword extractPath: - @type extractPath: - @keyword catchEmpty: - @type catchEmpty: - @return: - @rtype: + @param filepath: path to tarball file + @type filepath: string + @keyword extract_path: path where to extract tarball + @type extract_path: string + @keyword catch_empty: do not raise exceptions when trying to unpack empty + file + @type catch_empty: bool + @return: exit status + @rtype: int """ - if extractPath is None: - extractPath = os.path.dirname(filepath) + if extract_path is None: + extract_path = os.path.dirname(filepath) if not os.path.isfile(filepath): raise FileNotFound('FileNotFound: archive does not exist') try: tar = tarfile.open(filepath, "r") except tarfile.ReadError: - if catchEmpty: + if catch_empty: return 0 raise except EOFError: @@ -2425,7 +2426,7 @@ def uncompress_tar_bz2(filepath, extractPath = None, catchEmpty = False): try: - encoded_path = extractPath + encoded_path = extract_path if sys.hexversion < 0x3000000: encoded_path = encoded_path.encode('utf-8') entries = [] @@ -2466,18 +2467,18 @@ def uncompress_tar_bz2(filepath, extractPath = None, catchEmpty = False): finally: del tar.members[:] tar.close() - if os.listdir(extractPath): + if os.listdir(extract_path): return 0 return -1 def bytes_into_human(xbytes): """ - docstring_title + Convert byte size into human readable format. - @param xbytes: - @type xbytes: - @return: - @rtype: + @param xbytes: number of bytes + @type xbytes: int + @return: number of bytes in human readable format + @rtype: string """ size = str(round(float(xbytes)/1024, 1)) if xbytes < 1024: @@ -2489,17 +2490,6 @@ def bytes_into_human(xbytes): size += "MB" return size -def get_file_unix_mtime(path): - """ - docstring_title - - @param path: - @type path: - @return: - @rtype: - """ - return os.path.getmtime(path) - def get_random_temp_file(): """ docstring_title @@ -2613,31 +2603,6 @@ def convert_seconds_to_fancy_output(seconds): output.reverse() return ':'.join(output) -def flatten(l, ltypes = (list, tuple)): - """ - docstring_title - - @param l: - @type l: - @keyword ltypes: - @type ltypes: - @param tuple: - @type tuple: - @return: - @rtype: - """ - i = 0 - while i < len(l): - while isinstance(l[i], ltypes): - if not l[i]: - l.pop(i) - if not len(l): - break - else: - l[i:i+1] = list(l[i]) - i += 1 - return l - def read_repositories_conf(): """ docstring_title diff --git a/libraries/tests/tools.py b/libraries/tests/tools.py index 0f5d91df2..d1325f471 100644 --- a/libraries/tests/tools.py +++ b/libraries/tests/tools.py @@ -656,14 +656,14 @@ class ToolsTest(unittest.TestCase): self.assertEqual(et.create_package_atom_string(category, name, version, package_tag), result) - def test_uncompress_tar_bz2(self): + def test_uncompress_tarball(self): pkgs = [_misc.get_test_entropy_package4(), ] #_misc.get_footar_package() disabled for now for pkg in pkgs: - self._do_uncompress_tar_bz2(pkg) + self._do_uncompress_tarball(pkg) - def _do_uncompress_tar_bz2(self, pkg_path): + def _do_uncompress_tarball(self, pkg_path): tmp_dir = tempfile.mkdtemp() fd, tmp_file = tempfile.mkstemp() @@ -691,7 +691,7 @@ class ToolsTest(unittest.TestCase): os.makedirs(tmp_dir) # now try with our function - rc = et.uncompress_tar_bz2(pkg_path, tmp_dir) + rc = et.uncompress_tarball(pkg_path, extract_path = tmp_dir) self.assert_(not rc) new_path_perms = {} diff --git a/server/server_reagent.py b/server/server_reagent.py index adfd8b7db..eb49a855f 100644 --- a/server/server_reagent.py +++ b/server/server_reagent.py @@ -756,7 +756,7 @@ def database(options): mydblist = [] db_data = [] for mydb in dblist: - ts = entropy.tools.get_file_unix_mtime(mydb) + ts = os.path.getmtime(mydb) mytime = entropy.tools.convert_unix_time_to_human_time(ts) mydblist.append("[%s] %s" % (mytime, mydb,)) db_data.append(mydb) diff --git a/sulfur/src/sulfur/__init__.py b/sulfur/src/sulfur/__init__.py index 67d694891..fa875bf4d 100644 --- a/sulfur/src/sulfur/__init__.py +++ b/sulfur/src/sulfur/__init__.py @@ -854,7 +854,7 @@ class SulfurApplication(Controller, SulfurApplicationEventsMixin): self.dbBackupStore.clear() backed_up_dbs = self.Equo.list_backedup_client_databases() for mypath in backed_up_dbs: - mymtime = entropy.tools.get_file_unix_mtime(mypath) + mymtime = os.path.getmtime(mypath) mytime = entropy.tools.convert_unix_time_to_human_time(mymtime) self.dbBackupStore.append( (mypath, os.path.basename(mypath), mytime,) )