Skip to content

Commit

Permalink
Fixed long paths with windows (finally)
Browse files Browse the repository at this point in the history
  • Loading branch information
jyapayne committed Jan 14, 2016
1 parent d393987 commit d7beb8d
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 22 deletions.
42 changes: 21 additions & 21 deletions command_line.py
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def set_extra_attributes_from_keyword_args(self, **kwargs):

def extract(self, ex_path, version):
if os.path.exists(ex_path):
shutil.rmtree(ex_path, ignore_errors=True)
utils.rmtree(ex_path, ignore_errors=True)

path = self.save_file_path(version)

Expand Down Expand Up @@ -225,8 +225,8 @@ def extract(self, ex_path, version):
if os.path.exists(dir_name):
for p in os.listdir(dir_name):
abs_file = utils.path_join(dir_name, p)
shutil.move(abs_file, ex_path)
shutil.rmtree(dir_name, ignore_errors=True)
utils.move(abs_file, ex_path)
utils.rmtree(dir_name, ignore_errors=True)

def get_file_bytes(self, version):
fbytes = []
Expand Down Expand Up @@ -637,7 +637,7 @@ def create_icns_for_app(self, icns_path):
if not icon_path.endswith('.icns'):
save_icns(icon_path, icns_path)
else:
shutil.copy(icon_path, icns_path)
utils.copy(icon_path, icns_path)

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

output_dir = utils.path_join(self.output_dir(), self.project_name())
if os.path.exists(output_dir):
shutil.rmtree(output_dir, ignore_errors=True)
utils.rmtree(output_dir, ignore_errors=True)

temp_dir = utils.path_join(TEMP_DIR, 'webexectemp')
if os.path.exists(temp_dir):
shutil.rmtree(temp_dir, ignore_errors=True)
utils.rmtree(temp_dir, ignore_errors=True)

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

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

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

shutil.copytree(self.project_dir(), app_nw_folder,
ignore=shutil.ignore_patterns(output_dir))
utils.copytree(self.project_dir(), app_nw_folder,
ignore=shutil.ignore_patterns(output_dir))

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

if os.path.exists(export_dest):
shutil.rmtree(export_dest, ignore_errors=True)
utils.rmtree(export_dest, ignore_errors=True)

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

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

try:
shutil.move(utils.path_join(export_dest,
utils.move(utils.path_join(export_dest,
'nwjs.app'),
app_path)
app_path)
except IOError:
shutil.move(utils.path_join(export_dest,
utils.move(utils.path_join(export_dest,
'node-webkit.app'),
app_path)
app_path)

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

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

if uncompressed:
shutil.copytree(app_nw_folder, app_nw_res)
utils.copytree(app_nw_folder, app_nw_res)
else:
shutil.copy(zip_file, app_nw_res)
utils.copy(zip_file, app_nw_res)
self.create_icns_for_app(utils.path_join(app_path,
'Contents',
'Resources',
Expand Down Expand Up @@ -802,13 +802,13 @@ def make_output_dirs(self):
self.logger.error(error)
self.output_err += error
finally:
shutil.rmtree(temp_dir, ignore_errors=True)
utils.rmtree(temp_dir, ignore_errors=True)

def make_desktop_file(self, nw_path, export_dest):
icon_set = self.get_setting('icon')
icon_path = utils.path_join(self.project_dir(), icon_set.value)
if os.path.exists(icon_path) and icon_set.value:
shutil.copy(icon_path, export_dest)
utils.copy(icon_path, export_dest)
icon_path = utils.path_join(export_dest, os.path.basename(icon_path))
else:
icon_path = ''
Expand Down Expand Up @@ -886,7 +886,7 @@ def copy_files_to_project_folder(self):
f_path = setting.value.replace(self.project_dir(), '')
if os.path.isabs(f_path):
try:
shutil.copy(setting.value, self.project_dir())
utils.copy(setting.value, self.project_dir())
self.logger.info(u'Copying file {} to {}'.format(setting.value, self.project_dir()))
except shutil.Error as e: # same file warning
self.logger.warning(u'Warning: {}'.format(e))
Expand Down
1 change: 0 additions & 1 deletion main.py
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,6 @@ def create_export_settings(self):
script_label.setMinimumWidth(150)

self.script_line = QtGui.QLineEdit()
self.script_line.setReadOnly(True)

script_setting = self.get_setting('custom_script')
self.script_line.setObjectName(script_setting.name)
Expand Down
37 changes: 37 additions & 0 deletions utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import sys, tempfile
import subprocess
from appdirs import AppDirs
import shutil

#try:
# import zlib
Expand All @@ -29,7 +30,9 @@ def path_join(base, *rest):
new_rest.append(rest[i].decode('utf-8'))
except UnicodeEncodeError:
new_rest.append(unicode(rest[i]))

rpath = u'/'.join(new_rest)

if os.path.isabs(rpath):
return rpath
else:
Expand All @@ -40,6 +43,9 @@ def get_data_path(dir_path):
dirs = AppDirs('Web2Executable', 'Web2Executable')
data_path = path_join(dirs.user_data_dir, *parts)

if is_windows():
data_path = data_path.replace(u'\\', u'/')

if not os.path.exists(data_path):
os.makedirs(data_path)

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

def rmtree(path, **kwargs):
if is_windows():
if os.path.isabs(path):
path = u'//?/'+path
shutil.rmtree(path, **kwargs)

def copy(src, dest, **kwargs):
if is_windows():
if os.path.isabs(src):
src = u'//?/'+src
if os.path.isabs(dest):
dest = u'//?/'+dest
shutil.copy(src, dest, **kwargs)

def move(src, dest, **kwargs):
if is_windows():
if os.path.isabs(src):
src = u'//?/'+src
if os.path.isabs(dest):
dest = u'//?/'+dest
shutil.move(src, dest, **kwargs)

def copytree(src, dest, **kwargs):
if is_windows():
if os.path.isabs(src):
src = u'//?/'+src
if os.path.isabs(dest):
dest = u'//?/'+dest
shutil.copytree(src, dest, **kwargs)


def log(*args):
if DEBUG:
print(*args)
Expand Down

0 comments on commit d7beb8d

Please sign in to comment.