From 3b5d07cb3602c5a90f334f8a36ab7570e0740581 Mon Sep 17 00:00:00 2001 From: Joey Payne Date: Mon, 8 Feb 2016 07:27:44 -0700 Subject: [PATCH] Fixed long paths on python 2. Version bump. --- files/version.txt | 2 +- utils.py | 27 +++++++++++++++------------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/files/version.txt b/files/version.txt index ebf8e07..52a01ab 100644 --- a/files/version.txt +++ b/files/version.txt @@ -1 +1 @@ -v0.3.4b +v0.4.1b diff --git a/utils.py b/utils.py index b6fc636..681b0bf 100644 --- a/utils.py +++ b/utils.py @@ -33,10 +33,12 @@ def path_join(base, *rest): rpath = u'/'.join(new_rest) - if os.path.isabs(rpath): - return rpath - else: - return base + u'/' + rpath + if not os.path.isabs(rpath): + rpath = base + u'/' + rpath + + if is_windows(): + rpath = rpath.replace(u'/', u'\\') + return rpath def get_data_path(dir_path): parts = dir_path.split('/') @@ -59,34 +61,33 @@ def get_data_file_path(file_path): def rmtree(path, **kwargs): if is_windows(): if os.path.isabs(path): - path = u'//?/'+path + path = u'\\\\?\\'+path.replace(u'/', u'\\') shutil.rmtree(path, **kwargs) def copy(src, dest, **kwargs): if is_windows(): if os.path.isabs(src): - src = u'//?/'+src + src = u'\\\\?\\'+src.replace(u'/', u'\\') if os.path.isabs(dest): - dest = u'//?/'+dest + dest = u'\\\\?\\'+dest.replace(u'/', u'\\') shutil.copy(src, dest, **kwargs) def move(src, dest, **kwargs): if is_windows(): if os.path.isabs(src): - src = u'//?/'+src + src = u'\\\\?\\'+src.replace(u'/', u'\\') if os.path.isabs(dest): - dest = u'//?/'+dest + dest = u'\\\\?\\'+dest.replace(u'/', u'\\') shutil.move(src, dest, **kwargs) def copytree(src, dest, **kwargs): if is_windows(): if os.path.isabs(src): - src = u'//?/'+src + src = u'\\\\?\\'+src.replace(u'/', u'\\') if os.path.isabs(dest): - dest = u'//?/'+dest + dest = u'\\\\?\\'+dest.replace(u'/', u'\\') shutil.copytree(src, dest, **kwargs) - def log(*args): if DEBUG: print(*args) @@ -109,6 +110,8 @@ def zip_files(zip_file_name, *args, **kwargs): old_path = os.getcwd() for arg in args: + if is_windows(): + arg = u'\\\\?\\'+os.path.abspath(arg).replace(u'/', u'\\') if os.path.exists(arg): if os.path.isdir(arg): directory = os.path.abspath(arg)