diff --git a/doc/changelog.txt b/doc/changelog.txt index e6a3ecf..2fa0eb3 100644 --- a/doc/changelog.txt +++ b/doc/changelog.txt @@ -1,6 +1,7 @@ 0.4 "" (released xx.xx.2010) * Improved listing of available archive formats. + * Added support for Windows systems. 0.3 "Management" (released 23.2.2010) diff --git a/patoolib/__init__.py b/patoolib/__init__.py index 7311c3d..1f07644 100644 --- a/patoolib/__init__.py +++ b/patoolib/__init__.py @@ -352,7 +352,7 @@ def _handle_archive (archive, command, *args, **kwargs): raise util.PatoolError("archive `%s' already exists, and --force option was not given" % archive) program = config['program'] # get python module for given archive program - key = os.path.basename(program).lower() + key = util.stripext(os.path.basename(program).lower()) module = ProgramModules.get(key, key) # import archive handler (eg. patoolib.programs.star.extract_tar()) exec "from patoolib.programs.%s import %s_%s as func" % (module, command, format) diff --git a/patoolib/util.py b/patoolib/util.py index 6803c8e..6f21406 100644 --- a/patoolib/util.py +++ b/patoolib/util.py @@ -14,6 +14,7 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . """Utility functions.""" +from __future__ import with_statement import os import sys import subprocess @@ -112,6 +113,9 @@ def log_internal_error (out=sys.stderr): def p7zip_supports_rar (): """Determine if the RAR codec is installed for 7z program.""" + if os.name == 'nt': + # Assume RAR support is compiled into the binary. + return True return os.path.exists('/usr/lib/p7zip/Codecs/Rar29.so') @@ -119,9 +123,30 @@ def find_program (program): """Look for program in environment PATH variable.""" # XXX memoize result of this function path = os.environ['PATH'] + if os.name == 'nt': + path = append_to_path(path, get_nt_7z_dir()) return find_executable(program, path=path) +def append_to_path (path, directory): + """Add a directory to the PATH env variable, if it is a valid directory.""" + if not os.path.isdir(directory) or directory in path: + return path + if not path.endswith(os.pathsep): + path += os.pathsep + return path + directory + + +def get_nt_7z_dir (): + """Return 7-Zip directory from registry, or an empty string.""" + try: + import _winreg + with _winreg.OpenKey(_winreg.HKEY_LOCAL_MACHINE, r"SOFTWARE\7-Zip") as key: + return _winreg.QueryValueEx(key, "Path")[0] + except WindowsError: + return "" + + def strlist_with_or (list): """Return comma separated string, and last entry appended with ' or '.""" if len(list) > 1: