Skip to content

Commit d7beb8d

Browse files
committed
Fixed long paths with windows (finally)
1 parent d393987 commit d7beb8d

File tree

3 files changed

+58
-22
lines changed

3 files changed

+58
-22
lines changed

command_line.py

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def set_extra_attributes_from_keyword_args(self, **kwargs):
197197

198198
def extract(self, ex_path, version):
199199
if os.path.exists(ex_path):
200-
shutil.rmtree(ex_path, ignore_errors=True)
200+
utils.rmtree(ex_path, ignore_errors=True)
201201

202202
path = self.save_file_path(version)
203203

@@ -225,8 +225,8 @@ def extract(self, ex_path, version):
225225
if os.path.exists(dir_name):
226226
for p in os.listdir(dir_name):
227227
abs_file = utils.path_join(dir_name, p)
228-
shutil.move(abs_file, ex_path)
229-
shutil.rmtree(dir_name, ignore_errors=True)
228+
utils.move(abs_file, ex_path)
229+
utils.rmtree(dir_name, ignore_errors=True)
230230

231231
def get_file_bytes(self, version):
232232
fbytes = []
@@ -637,7 +637,7 @@ def create_icns_for_app(self, icns_path):
637637
if not icon_path.endswith('.icns'):
638638
save_icns(icon_path, icns_path)
639639
else:
640-
shutil.copy(icon_path, icns_path)
640+
utils.copy(icon_path, icns_path)
641641

642642
def replace_icon_in_exe(self, exe_path):
643643
icon_setting = self.get_setting('icon')
@@ -658,11 +658,11 @@ def make_output_dirs(self):
658658

659659
output_dir = utils.path_join(self.output_dir(), self.project_name())
660660
if os.path.exists(output_dir):
661-
shutil.rmtree(output_dir, ignore_errors=True)
661+
utils.rmtree(output_dir, ignore_errors=True)
662662

663663
temp_dir = utils.path_join(TEMP_DIR, 'webexectemp')
664664
if os.path.exists(temp_dir):
665-
shutil.rmtree(temp_dir, ignore_errors=True)
665+
utils.rmtree(temp_dir, ignore_errors=True)
666666

667667
self.progress_text = 'Making new directories...\n'
668668

@@ -689,8 +689,8 @@ def make_output_dirs(self):
689689

690690
app_nw_folder = utils.path_join(temp_dir, self.project_name()+'.nwf')
691691

692-
shutil.copytree(self.project_dir(), app_nw_folder,
693-
ignore=shutil.ignore_patterns(output_dir))
692+
utils.copytree(self.project_dir(), app_nw_folder,
693+
ignore=shutil.ignore_patterns(output_dir))
694694

695695
zip_files(zip_file, self.project_dir(), exclude_paths=[output_dir])
696696
for ex_setting in self.settings['export_settings'].values():
@@ -706,13 +706,13 @@ def make_output_dirs(self):
706706
export_dest = export_dest.replace('node-webkit', 'nwjs')
707707

708708
if os.path.exists(export_dest):
709-
shutil.rmtree(export_dest, ignore_errors=True)
709+
utils.rmtree(export_dest, ignore_errors=True)
710710

711711
# shutil will make the directory for us
712-
shutil.copytree(get_data_path('files/'+ex_setting.name),
713-
export_dest,
712+
utils.copytree(get_data_path('files/'+ex_setting.name),
713+
export_dest,
714714
ignore=shutil.ignore_patterns('place_holder.txt'))
715-
shutil.rmtree(get_data_path('files/'+ex_setting.name), ignore_errors=True)
715+
utils.rmtree(get_data_path('files/'+ex_setting.name), ignore_errors=True)
716716
self.progress_text += '.'
717717

718718
if 'mac' in ex_setting.name:
@@ -722,13 +722,13 @@ def make_output_dirs(self):
722722
self.project_name()+'.app')
723723

724724
try:
725-
shutil.move(utils.path_join(export_dest,
725+
utils.move(utils.path_join(export_dest,
726726
'nwjs.app'),
727-
app_path)
727+
app_path)
728728
except IOError:
729-
shutil.move(utils.path_join(export_dest,
729+
utils.move(utils.path_join(export_dest,
730730
'node-webkit.app'),
731-
app_path)
731+
app_path)
732732

733733
plist_path = utils.path_join(app_path, 'Contents', 'Info.plist')
734734

@@ -751,9 +751,9 @@ def make_output_dirs(self):
751751
'app.nw')
752752

753753
if uncompressed:
754-
shutil.copytree(app_nw_folder, app_nw_res)
754+
utils.copytree(app_nw_folder, app_nw_res)
755755
else:
756-
shutil.copy(zip_file, app_nw_res)
756+
utils.copy(zip_file, app_nw_res)
757757
self.create_icns_for_app(utils.path_join(app_path,
758758
'Contents',
759759
'Resources',
@@ -802,13 +802,13 @@ def make_output_dirs(self):
802802
self.logger.error(error)
803803
self.output_err += error
804804
finally:
805-
shutil.rmtree(temp_dir, ignore_errors=True)
805+
utils.rmtree(temp_dir, ignore_errors=True)
806806

807807
def make_desktop_file(self, nw_path, export_dest):
808808
icon_set = self.get_setting('icon')
809809
icon_path = utils.path_join(self.project_dir(), icon_set.value)
810810
if os.path.exists(icon_path) and icon_set.value:
811-
shutil.copy(icon_path, export_dest)
811+
utils.copy(icon_path, export_dest)
812812
icon_path = utils.path_join(export_dest, os.path.basename(icon_path))
813813
else:
814814
icon_path = ''
@@ -886,7 +886,7 @@ def copy_files_to_project_folder(self):
886886
f_path = setting.value.replace(self.project_dir(), '')
887887
if os.path.isabs(f_path):
888888
try:
889-
shutil.copy(setting.value, self.project_dir())
889+
utils.copy(setting.value, self.project_dir())
890890
self.logger.info(u'Copying file {} to {}'.format(setting.value, self.project_dir()))
891891
except shutil.Error as e: # same file warning
892892
self.logger.warning(u'Warning: {}'.format(e))

main.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1037,7 +1037,6 @@ def create_export_settings(self):
10371037
script_label.setMinimumWidth(150)
10381038

10391039
self.script_line = QtGui.QLineEdit()
1040-
self.script_line.setReadOnly(True)
10411040

10421041
script_setting = self.get_setting('custom_script')
10431042
self.script_line.setObjectName(script_setting.name)

utils.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import sys, tempfile
44
import subprocess
55
from appdirs import AppDirs
6+
import shutil
67

78
#try:
89
# import zlib
@@ -29,7 +30,9 @@ def path_join(base, *rest):
2930
new_rest.append(rest[i].decode('utf-8'))
3031
except UnicodeEncodeError:
3132
new_rest.append(unicode(rest[i]))
33+
3234
rpath = u'/'.join(new_rest)
35+
3336
if os.path.isabs(rpath):
3437
return rpath
3538
else:
@@ -40,6 +43,9 @@ def get_data_path(dir_path):
4043
dirs = AppDirs('Web2Executable', 'Web2Executable')
4144
data_path = path_join(dirs.user_data_dir, *parts)
4245

46+
if is_windows():
47+
data_path = data_path.replace(u'\\', u'/')
48+
4349
if not os.path.exists(data_path):
4450
os.makedirs(data_path)
4551

@@ -50,6 +56,37 @@ def get_data_file_path(file_path):
5056
data_path = get_data_path('/'.join(parts[:-1]))
5157
return path_join(data_path, parts[-1])
5258

59+
def rmtree(path, **kwargs):
60+
if is_windows():
61+
if os.path.isabs(path):
62+
path = u'//?/'+path
63+
shutil.rmtree(path, **kwargs)
64+
65+
def copy(src, dest, **kwargs):
66+
if is_windows():
67+
if os.path.isabs(src):
68+
src = u'//?/'+src
69+
if os.path.isabs(dest):
70+
dest = u'//?/'+dest
71+
shutil.copy(src, dest, **kwargs)
72+
73+
def move(src, dest, **kwargs):
74+
if is_windows():
75+
if os.path.isabs(src):
76+
src = u'//?/'+src
77+
if os.path.isabs(dest):
78+
dest = u'//?/'+dest
79+
shutil.move(src, dest, **kwargs)
80+
81+
def copytree(src, dest, **kwargs):
82+
if is_windows():
83+
if os.path.isabs(src):
84+
src = u'//?/'+src
85+
if os.path.isabs(dest):
86+
dest = u'//?/'+dest
87+
shutil.copytree(src, dest, **kwargs)
88+
89+
5390
def log(*args):
5491
if DEBUG:
5592
print(*args)

0 commit comments

Comments
 (0)