Added unicode support for projects.
This commit is contained in:
parent
3bf1d82ec7
commit
1b68592120
2 changed files with 93 additions and 88 deletions
121
command_line.py
121
command_line.py
|
|
@ -21,6 +21,7 @@ import subprocess
|
||||||
import logging
|
import logging
|
||||||
import logging.handlers as lh
|
import logging.handlers as lh
|
||||||
import plistlib
|
import plistlib
|
||||||
|
import codecs
|
||||||
|
|
||||||
from semantic_version import Version
|
from semantic_version import Version
|
||||||
|
|
||||||
|
|
@ -63,8 +64,8 @@ handler = lh.RotatingFileHandler(LOG_FILENAME, maxBytes=100000, backupCount=2)
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
|
||||||
def my_excepthook(type_, value, tback):
|
def my_excepthook(type_, value, tback):
|
||||||
output_err = ''.join(traceback.format_exception(type_, value, tback))
|
output_err = u''.join(traceback.format_exception(type_, value, tback))
|
||||||
logger.error('{}'.format(output_err))
|
logger.error(u'{}'.format(output_err))
|
||||||
sys.__excepthook__(type_, value, tback)
|
sys.__excepthook__(type_, value, tback)
|
||||||
|
|
||||||
sys.excepthook = my_excepthook
|
sys.excepthook = my_excepthook
|
||||||
|
|
@ -79,7 +80,7 @@ except:
|
||||||
def get_base_url():
|
def get_base_url():
|
||||||
url = None
|
url = None
|
||||||
try:
|
try:
|
||||||
url = open(os.path.join(CWD, 'files', 'base_url.txt')).read().strip()
|
url = codecs.open(os.path.join(CWD, 'files', 'base_url.txt'), encoding='utf-8').read().strip()
|
||||||
except (OSError, IOError):
|
except (OSError, IOError):
|
||||||
url = 'http://dl.node-webkit.org/v{}/'
|
url = 'http://dl.node-webkit.org/v{}/'
|
||||||
return url
|
return url
|
||||||
|
|
@ -101,7 +102,7 @@ class Setting(object):
|
||||||
self.default_value = kwargs.pop('default_value', None)
|
self.default_value = kwargs.pop('default_value', None)
|
||||||
self.button = kwargs.pop('button', None)
|
self.button = kwargs.pop('button', None)
|
||||||
self.button_callback = kwargs.pop('button_callback', None)
|
self.button_callback = kwargs.pop('button_callback', None)
|
||||||
self.description = kwargs.pop('description', '')
|
self.description = kwargs.pop('description', u'')
|
||||||
self.values = kwargs.pop('values', [])
|
self.values = kwargs.pop('values', [])
|
||||||
self.filter = kwargs.pop('filter', '.*')
|
self.filter = kwargs.pop('filter', '.*')
|
||||||
self.filter_action = kwargs.pop('filter_action', 'None')
|
self.filter_action = kwargs.pop('filter_action', 'None')
|
||||||
|
|
@ -113,7 +114,7 @@ class Setting(object):
|
||||||
if self.value is None:
|
if self.value is None:
|
||||||
self.value = self.default_value
|
self.value = self.default_value
|
||||||
|
|
||||||
self.save_path = kwargs.pop('save_path', '')
|
self.save_path = kwargs.pop('save_path', u'')
|
||||||
|
|
||||||
self.get_file_information_from_url()
|
self.get_file_information_from_url()
|
||||||
|
|
||||||
|
|
@ -125,7 +126,7 @@ class Setting(object):
|
||||||
|
|
||||||
def get_file_information_from_url(self):
|
def get_file_information_from_url(self):
|
||||||
if hasattr(self, 'url'):
|
if hasattr(self, 'url'):
|
||||||
self.file_name = self.url.split('/')[-1]
|
self.file_name = self.url.split(u'/')[-1]
|
||||||
self.full_file_path = os.path.join(self.save_path, self.file_name)
|
self.full_file_path = os.path.join(self.save_path, self.file_name)
|
||||||
self.file_ext = os.path.splitext(self.file_name)[1]
|
self.file_ext = os.path.splitext(self.file_name)[1]
|
||||||
if self.file_ext == '.zip':
|
if self.file_ext == '.zip':
|
||||||
|
|
@ -161,7 +162,7 @@ class Setting(object):
|
||||||
def extract_file_path(self, version):
|
def extract_file_path(self, version):
|
||||||
if self.extract_file:
|
if self.extract_file:
|
||||||
return self.extract_file.format(version)
|
return self.extract_file.format(version)
|
||||||
return ''
|
return u''
|
||||||
|
|
||||||
def set_extra_attributes_from_keyword_args(self, **kwargs):
|
def set_extra_attributes_from_keyword_args(self, **kwargs):
|
||||||
for undefined_key, undefined_value in kwargs.items():
|
for undefined_key, undefined_value in kwargs.items():
|
||||||
|
|
@ -224,9 +225,9 @@ class Setting(object):
|
||||||
elif self.file_ext == '.zip':
|
elif self.file_ext == '.zip':
|
||||||
new_bytes = file.read(extract_p)
|
new_bytes = file.read(extract_p)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
logger.error(str(e))
|
logger.error(unicode(e))
|
||||||
# dirty hack to support old versions of nw
|
# dirty hack to support old versions of nw
|
||||||
if 'no item named' in str(e):
|
if 'no item named' in unicode(e):
|
||||||
extract_path = '/'.join(extract_path.split('/')[1:])
|
extract_path = '/'.join(extract_path.split('/')[1:])
|
||||||
try:
|
try:
|
||||||
if self.file_ext == '.gz':
|
if self.file_ext == '.gz':
|
||||||
|
|
@ -234,7 +235,7 @@ class Setting(object):
|
||||||
elif self.file_ext == '.zip':
|
elif self.file_ext == '.zip':
|
||||||
new_bytes = file.read(extract_path)
|
new_bytes = file.read(extract_path)
|
||||||
except KeyError as e:
|
except KeyError as e:
|
||||||
logger.error(str(e))
|
logger.error(unicode(e))
|
||||||
|
|
||||||
if new_bytes is not None:
|
if new_bytes is not None:
|
||||||
fbytes.append((dest_path, new_bytes))
|
fbytes.append((dest_path, new_bytes))
|
||||||
|
|
@ -245,10 +246,10 @@ class Setting(object):
|
||||||
url = ''
|
url = ''
|
||||||
if hasattr(self, 'url'):
|
if hasattr(self, 'url'):
|
||||||
url = self.url
|
url = self.url
|
||||||
return ('Setting: (name={}, '
|
return (u'Setting: (name={}, '
|
||||||
'display_name={}, '
|
u'display_name={}, '
|
||||||
'value={}, required={}, '
|
u'value={}, required={}, '
|
||||||
'type={}, url={})').format(self.name,
|
u'type={}, url={})').format(self.name,
|
||||||
self.display_name,
|
self.display_name,
|
||||||
self.value,
|
self.value,
|
||||||
self.required,
|
self.required,
|
||||||
|
|
@ -283,9 +284,10 @@ class CommandBase(object):
|
||||||
def setup_nw_versions(self):
|
def setup_nw_versions(self):
|
||||||
nw_version = self.get_setting('nw_version')
|
nw_version = self.get_setting('nw_version')
|
||||||
try:
|
try:
|
||||||
f = open(os.path.join(CWD, 'files', 'nw-versions.txt'))
|
f = codecs.open(os.path.join(CWD, 'files', 'nw-versions.txt'), encoding='utf-8')
|
||||||
for line in f:
|
for line in f:
|
||||||
nw_version.values.append(line.strip())
|
nw_version.values.append(line.strip())
|
||||||
|
f.close()
|
||||||
except IOError:
|
except IOError:
|
||||||
nw_version.values.append(nw_version.default_value)
|
nw_version.values.append(nw_version.default_value)
|
||||||
|
|
||||||
|
|
@ -295,8 +297,8 @@ class CommandBase(object):
|
||||||
|
|
||||||
def get_settings(self):
|
def get_settings(self):
|
||||||
config_file = os.path.join(CWD, 'files', 'settings.cfg')
|
config_file = os.path.join(CWD, 'files', 'settings.cfg')
|
||||||
contents = open(config_file).read()
|
contents = codecs.open(config_file, encoding='utf-8').read()
|
||||||
contents = contents.replace('{DEFAULT_DOWNLOAD_PATH}',
|
contents = contents.replace(u'{DEFAULT_DOWNLOAD_PATH}',
|
||||||
DEFAULT_DOWNLOAD_PATH)
|
DEFAULT_DOWNLOAD_PATH)
|
||||||
config_io = StringIO(contents)
|
config_io = StringIO(contents)
|
||||||
config = ConfigObj(config_io, unrepr=True).dict()
|
config = ConfigObj(config_io, unrepr=True).dict()
|
||||||
|
|
@ -373,11 +375,12 @@ class CommandBase(object):
|
||||||
nw_version.values = versions
|
nw_version.values = versions
|
||||||
f = None
|
f = None
|
||||||
try:
|
try:
|
||||||
f = open(os.path.join(CWD, 'files', 'nw-versions.txt'), 'w')
|
f = codecs.open(os.path.join(CWD, 'files', 'nw-versions.txt'), 'w', encoding='utf-8')
|
||||||
for v in nw_version.values:
|
for v in nw_version.values:
|
||||||
f.write(v+os.linesep)
|
f.write(v+os.linesep)
|
||||||
|
f.close()
|
||||||
except IOError:
|
except IOError:
|
||||||
error = ''.join(traceback.format_exception(sys.exc_info()[0],
|
error = u''.join(traceback.format_exception(sys.exc_info()[0],
|
||||||
sys.exc_info()[1],
|
sys.exc_info()[1],
|
||||||
sys.exc_info()[2]))
|
sys.exc_info()[2]))
|
||||||
self.show_error(error)
|
self.show_error(error)
|
||||||
|
|
@ -404,7 +407,7 @@ class CommandBase(object):
|
||||||
if os.path.exists(setting.save_file_path(version, location)):
|
if os.path.exists(setting.save_file_path(version, location)):
|
||||||
os.remove(setting.save_file_path(version, location))
|
os.remove(setting.save_file_path(version, location))
|
||||||
|
|
||||||
error = ''.join(traceback.format_exception(sys.exc_info()[0],
|
error = u''.join(traceback.format_exception(sys.exc_info()[0],
|
||||||
sys.exc_info()[1],
|
sys.exc_info()[1],
|
||||||
sys.exc_info()[2]))
|
sys.exc_info()[2]))
|
||||||
self.show_error(error)
|
self.show_error(error)
|
||||||
|
|
@ -420,13 +423,13 @@ class CommandBase(object):
|
||||||
setting_list = []
|
setting_list = []
|
||||||
if p_json:
|
if p_json:
|
||||||
json_str = ''
|
json_str = ''
|
||||||
with open(p_json[0], 'r') as f:
|
with codecs.open(p_json[0], 'r', encoding='utf-8') as f:
|
||||||
json_str = f.read()
|
json_str = f.read()
|
||||||
try:
|
try:
|
||||||
setting_list = self.load_from_json(json_str)
|
setting_list = self.load_from_json(json_str)
|
||||||
except ValueError as e: # Json file is invalid
|
except ValueError as e: # Json file is invalid
|
||||||
self.logger.warning('Warning: Json file invalid.')
|
self.logger.warning('Warning: Json file invalid.')
|
||||||
self.progress_text = '{}\n'.format(e)
|
self.progress_text = u'{}\n'.format(e)
|
||||||
return setting_list
|
return setting_list
|
||||||
|
|
||||||
def generate_json(self):
|
def generate_json(self):
|
||||||
|
|
@ -479,8 +482,8 @@ class CommandBase(object):
|
||||||
@extract_error.setter
|
@extract_error.setter
|
||||||
def extract_error(self, value):
|
def extract_error(self, value):
|
||||||
if value is not None and not self.quiet and not inside_packed_exe:
|
if value is not None and not self.quiet and not inside_packed_exe:
|
||||||
self._extract_error = str(value)
|
self._extract_error = unicode(value)
|
||||||
sys.stderr.write('\r{}'.format(self._extract_error))
|
sys.stderr.write(u'\r{}'.format(self._extract_error))
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
@ -490,8 +493,8 @@ class CommandBase(object):
|
||||||
@output_err.setter
|
@output_err.setter
|
||||||
def output_err(self, value):
|
def output_err(self, value):
|
||||||
if value is not None and not self.quiet and not inside_packed_exe:
|
if value is not None and not self.quiet and not inside_packed_exe:
|
||||||
self._output_err = str(value)
|
self._output_err = unicode(value)
|
||||||
sys.stderr.write('\r{}'.format(self._output_err))
|
sys.stderr.write(u'\r{}'.format(self._output_err))
|
||||||
sys.stderr.flush()
|
sys.stderr.flush()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
|
|
@ -501,8 +504,8 @@ class CommandBase(object):
|
||||||
@progress_text.setter
|
@progress_text.setter
|
||||||
def progress_text(self, value):
|
def progress_text(self, value):
|
||||||
if value is not None and not self.quiet and not inside_packed_exe:
|
if value is not None and not self.quiet and not inside_packed_exe:
|
||||||
self._progress_text = str(value)
|
self._progress_text = unicode(value)
|
||||||
sys.stdout.write('\r{}'.format(self._progress_text))
|
sys.stdout.write(u'\r{}'.format(self._progress_text))
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
def load_from_json(self, json_str):
|
def load_from_json(self, json_str):
|
||||||
|
|
@ -561,7 +564,7 @@ class CommandBase(object):
|
||||||
if os.path.exists(save_file_path):
|
if os.path.exists(save_file_path):
|
||||||
os.remove(save_file_path)
|
os.remove(save_file_path)
|
||||||
self.extract_error = e
|
self.extract_error = e
|
||||||
self.logger.error(str(self.extract_error))
|
self.logger.error(unicode(self.extract_error))
|
||||||
# cannot use GUI in thread to notify user. Save it for later
|
# cannot use GUI in thread to notify user. Save it for later
|
||||||
self.progress_text = '\nDone.\n'
|
self.progress_text = '\nDone.\n'
|
||||||
return True
|
return True
|
||||||
|
|
@ -614,7 +617,7 @@ class CommandBase(object):
|
||||||
json_file = os.path.join(self.project_dir(), 'package.json')
|
json_file = os.path.join(self.project_dir(), 'package.json')
|
||||||
|
|
||||||
if self.output_package_json:
|
if self.output_package_json:
|
||||||
with open(json_file, 'w+') as f:
|
with codecs.open(json_file, 'w+', encoding='utf-8') as f:
|
||||||
f.write(self.generate_json())
|
f.write(self.generate_json())
|
||||||
|
|
||||||
zip_file = os.path.join(temp_dir, self.project_name()+'.nw')
|
zip_file = os.path.join(temp_dir, self.project_name()+'.nw')
|
||||||
|
|
@ -624,7 +627,7 @@ class CommandBase(object):
|
||||||
if ex_setting.value:
|
if ex_setting.value:
|
||||||
self.progress_text = '\n'
|
self.progress_text = '\n'
|
||||||
name = ex_setting.display_name
|
name = ex_setting.display_name
|
||||||
self.progress_text = 'Making files for {}...'.format(name)
|
self.progress_text = u'Making files for {}...'.format(name)
|
||||||
export_dest = os.path.join(output_dir, ex_setting.name)
|
export_dest = os.path.join(output_dir, ex_setting.name)
|
||||||
versions = re.findall('(\d+)\.(\d+)\.(\d+)', self.selected_version())[0]
|
versions = re.findall('(\d+)\.(\d+)\.(\d+)', self.selected_version())[0]
|
||||||
|
|
||||||
|
|
@ -719,7 +722,7 @@ class CommandBase(object):
|
||||||
exc = traceback.format_exception(sys.exc_info()[0],
|
exc = traceback.format_exception(sys.exc_info()[0],
|
||||||
sys.exc_info()[1],
|
sys.exc_info()[1],
|
||||||
sys.exc_info()[2])
|
sys.exc_info()[2])
|
||||||
self.output_err += ''.join(exc)
|
self.output_err += u''.join(exc)
|
||||||
self.logger.error(exc)
|
self.logger.error(exc)
|
||||||
finally:
|
finally:
|
||||||
shutil.rmtree(temp_dir)
|
shutil.rmtree(temp_dir)
|
||||||
|
|
@ -736,24 +739,24 @@ class CommandBase(object):
|
||||||
pdir = self.project_dir()
|
pdir = self.project_dir()
|
||||||
version = self.get_setting('version')
|
version = self.get_setting('version')
|
||||||
desc = self.get_setting('description')
|
desc = self.get_setting('description')
|
||||||
dfile_path = os.path.join(export_dest, name+'.desktop')
|
dfile_path = os.path.join(export_dest, u'{}.desktop'.format(name))
|
||||||
file_str = (
|
file_str = (
|
||||||
'[Desktop Entry]\n'
|
u'[Desktop Entry]\n'
|
||||||
'Version={}\n'
|
u'Version={}\n'
|
||||||
'Name={}\n'
|
u'Name={}\n'
|
||||||
'Comment={}\n'
|
u'Comment={}\n'
|
||||||
'Exec={}\n'
|
u'Exec={}\n'
|
||||||
'Icon={}\n'
|
u'Icon={}\n'
|
||||||
'Terminal=false\n'
|
u'Terminal=false\n'
|
||||||
'Type=Application\n'
|
u'Type=Application\n'
|
||||||
'Categories=Utility;Application;\n'
|
u'Categories=Utility;Application;\n'
|
||||||
)
|
)
|
||||||
file_str = file_str.format(version.value,
|
file_str = file_str.format(version.value,
|
||||||
name,
|
name,
|
||||||
desc.value,
|
desc.value,
|
||||||
nw_path,
|
nw_path,
|
||||||
icon_path)
|
icon_path)
|
||||||
with open(dfile_path, 'w+') as f:
|
with codecs.open(dfile_path, 'w+', encoding='utf-8') as f:
|
||||||
f.write(file_str)
|
f.write(file_str)
|
||||||
|
|
||||||
os.chmod(dfile_path, 0755)
|
os.chmod(dfile_path, 0755)
|
||||||
|
|
@ -776,7 +779,7 @@ class CommandBase(object):
|
||||||
if upx_version is not None:
|
if upx_version is not None:
|
||||||
upx_bin = os.path.join('files', 'compressors', upx_version)
|
upx_bin = os.path.join('files', 'compressors', upx_version)
|
||||||
os.chmod(upx_bin, 0755)
|
os.chmod(upx_bin, 0755)
|
||||||
cmd = [upx_bin, '--lzma', '-{}'.format(compression.value), str(nw_path)]
|
cmd = [upx_bin, '--lzma', u'-{}'.format(compression.value), unicode(nw_path)]
|
||||||
if platform.system() == 'Windows':
|
if platform.system() == 'Windows':
|
||||||
startupinfo = subprocess.STARTUPINFO()
|
startupinfo = subprocess.STARTUPINFO()
|
||||||
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
|
||||||
|
|
@ -799,7 +802,7 @@ class CommandBase(object):
|
||||||
def copy_files_to_project_folder(self):
|
def copy_files_to_project_folder(self):
|
||||||
old_dir = CWD
|
old_dir = CWD
|
||||||
os.chdir(self.project_dir())
|
os.chdir(self.project_dir())
|
||||||
self.logger.info('Copying files to {}'.format(self.project_dir()))
|
self.logger.info(u'Copying files to {}'.format(self.project_dir()))
|
||||||
for sgroup in self.settings['setting_groups']:
|
for sgroup in self.settings['setting_groups']:
|
||||||
for setting in sgroup.values():
|
for setting in sgroup.values():
|
||||||
if setting.type == 'file' and setting.value:
|
if setting.type == 'file' and setting.value:
|
||||||
|
|
@ -807,9 +810,9 @@ class CommandBase(object):
|
||||||
if os.path.isabs(f_path):
|
if os.path.isabs(f_path):
|
||||||
try:
|
try:
|
||||||
shutil.copy(setting.value, self.project_dir())
|
shutil.copy(setting.value, self.project_dir())
|
||||||
self.logger.info('Copying file {} to {}'.format(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
|
except shutil.Error as e: # same file warning
|
||||||
self.logger.warning('Warning: {}'.format(e))
|
self.logger.warning(u'Warning: {}'.format(e))
|
||||||
finally:
|
finally:
|
||||||
setting.value = os.path.basename(setting.value)
|
setting.value = os.path.basename(setting.value)
|
||||||
|
|
||||||
|
|
@ -818,7 +821,7 @@ class CommandBase(object):
|
||||||
def convert_val_to_str(self, val):
|
def convert_val_to_str(self, val):
|
||||||
if isinstance(val, (list, tuple)):
|
if isinstance(val, (list, tuple)):
|
||||||
return ', '.join(val)
|
return ', '.join(val)
|
||||||
return str(val).replace(self.project_dir()+os.path.sep, '')
|
return unicode(val).replace(self.project_dir()+os.path.sep, '')
|
||||||
|
|
||||||
def export(self):
|
def export(self):
|
||||||
self.get_files_to_download()
|
self.get_files_to_download()
|
||||||
|
|
@ -826,7 +829,7 @@ class CommandBase(object):
|
||||||
if res:
|
if res:
|
||||||
self.make_output_dirs()
|
self.make_output_dirs()
|
||||||
self.progress_text = '\nDone!\n'
|
self.progress_text = '\nDone!\n'
|
||||||
self.progress_text = 'Output directory is {}/{}.\n'.format(self.output_dir(),
|
self.progress_text = u'Output directory is {}/{}.\n'.format(self.output_dir(),
|
||||||
self.project_name())
|
self.project_name())
|
||||||
self.delete_files()
|
self.delete_files()
|
||||||
|
|
||||||
|
|
@ -849,7 +852,7 @@ class CommandBase(object):
|
||||||
return self.extract_files()
|
return self.extract_files()
|
||||||
|
|
||||||
def download_file(self, path, setting):
|
def download_file(self, path, setting):
|
||||||
self.logger.info('Downloading file {}.'.format(path))
|
self.logger.info(u'Downloading file {}.'.format(path))
|
||||||
|
|
||||||
location = self.get_setting('download_dir').value
|
location = self.get_setting('download_dir').value
|
||||||
|
|
||||||
|
|
@ -874,7 +877,7 @@ class CommandBase(object):
|
||||||
forced = self.get_setting('force_download').value
|
forced = self.get_setting('force_download').value
|
||||||
|
|
||||||
if (archive_exists or dest_files_exist) and not forced:
|
if (archive_exists or dest_files_exist) and not forced:
|
||||||
self.logger.info('File {} already downloaded. Continuing...'.format(path))
|
self.logger.info(u'File {} already downloaded. Continuing...'.format(path))
|
||||||
return self.continue_downloading_or_extract()
|
return self.continue_downloading_or_extract()
|
||||||
elif tmp_exists and (os.stat(tmp_file).st_size > 0):
|
elif tmp_exists and (os.stat(tmp_file).st_size > 0):
|
||||||
tmp_size = os.stat(tmp_file).st_size
|
tmp_size = os.stat(tmp_file).st_size
|
||||||
|
|
@ -893,9 +896,9 @@ class CommandBase(object):
|
||||||
downloaded = ''
|
downloaded = ''
|
||||||
if tmp_size:
|
if tmp_size:
|
||||||
self.progress_text = 'Resuming previous download...\n'
|
self.progress_text = 'Resuming previous download...\n'
|
||||||
self.progress_text = 'Already downloaded {:.2f} MB\n'.format(tmp_size/1000000.0)
|
self.progress_text = u'Already downloaded {:.2f} MB\n'.format(tmp_size/1000000.0)
|
||||||
self.progress_text = ('Downloading: {}, '
|
self.progress_text = (u'Downloading: {}, '
|
||||||
'Size: {:.2f} MB {}\n'.format(short_name,
|
u'Size: {:.2f} MB {}\n'.format(short_name,
|
||||||
MB,
|
MB,
|
||||||
downloaded))
|
downloaded))
|
||||||
|
|
||||||
|
|
@ -978,16 +981,16 @@ if __name__ == '__main__':
|
||||||
else 'store_false')
|
else 'store_false')
|
||||||
kwargs.update({'action': action})
|
kwargs.update({'action': action})
|
||||||
if setting.default_value is True:
|
if setting.default_value is True:
|
||||||
option_name = 'disable-{}'.format(option_name)
|
option_name = u'disable-{}'.format(option_name)
|
||||||
else:
|
else:
|
||||||
if setting.values:
|
if setting.values:
|
||||||
kwargs.update({'choices': setting.values})
|
kwargs.update({'choices': setting.values})
|
||||||
setting.description += ' Possible values: {{{}}}'.format(', '.join([str(x) for x in setting.values]))
|
setting.description += u' Possible values: {{{}}}'.format(', '.join([unicode(x) for x in setting.values]))
|
||||||
kwargs.update({'metavar': ''})
|
kwargs.update({'metavar': ''})
|
||||||
else:
|
else:
|
||||||
kwargs.update({'metavar': '<{}>'.format(setting.display_name)})
|
kwargs.update({'metavar': '<{}>'.format(setting.display_name)})
|
||||||
|
|
||||||
parser.add_argument('--{}'.format(option_name),
|
parser.add_argument(u'--{}'.format(option_name),
|
||||||
dest=setting_name,
|
dest=setting_name,
|
||||||
help=setting.description,
|
help=setting.description,
|
||||||
**kwargs
|
**kwargs
|
||||||
|
|
@ -1022,8 +1025,8 @@ if __name__ == '__main__':
|
||||||
logger.addHandler(handler)
|
logger.addHandler(handler)
|
||||||
|
|
||||||
def my_excepthook(type_, value, tback):
|
def my_excepthook(type_, value, tback):
|
||||||
output_err = ''.join(traceback.format_exception(type_, value, tback))
|
output_err = u''.join(traceback.format_exception(type_, value, tback))
|
||||||
logger.error('{}'.format(output_err))
|
logger.error(u'{}'.format(output_err))
|
||||||
sys.__excepthook__(type_, value, tback)
|
sys.__excepthook__(type_, value, tback)
|
||||||
|
|
||||||
sys.excepthook = my_excepthook
|
sys.excepthook = my_excepthook
|
||||||
|
|
|
||||||
60
main.py
60
main.py
|
|
@ -6,6 +6,7 @@ import os
|
||||||
import re
|
import re
|
||||||
import glob
|
import glob
|
||||||
import sys
|
import sys
|
||||||
|
import codecs
|
||||||
|
|
||||||
from PySide import QtGui, QtCore
|
from PySide import QtGui, QtCore
|
||||||
from PySide.QtGui import QApplication, QHBoxLayout, QVBoxLayout
|
from PySide.QtGui import QApplication, QHBoxLayout, QVBoxLayout
|
||||||
|
|
@ -56,7 +57,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
files = []
|
files = []
|
||||||
history_file = get_file('files/recent_files.txt')
|
history_file = get_file('files/recent_files.txt')
|
||||||
|
|
||||||
with open(history_file, 'a+') as f:
|
with codecs.open(history_file, 'a+', 'utf-8') as f:
|
||||||
for line in f:
|
for line in f:
|
||||||
line = line.strip()
|
line = line.strip()
|
||||||
if line and os.path.exists(line):
|
if line and os.path.exists(line):
|
||||||
|
|
@ -67,7 +68,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
def load_last_project_path(self):
|
def load_last_project_path(self):
|
||||||
proj_path = ''
|
proj_path = ''
|
||||||
proj_file = get_file('files/last_project_path.txt')
|
proj_file = get_file('files/last_project_path.txt')
|
||||||
with open(proj_file, 'a+') as f:
|
with codecs.open(proj_file, 'a+', encoding='utf-8') as f:
|
||||||
proj_path = f.read().strip()
|
proj_path = f.read().strip()
|
||||||
|
|
||||||
if not proj_path:
|
if not proj_path:
|
||||||
|
|
@ -77,28 +78,28 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
|
|
||||||
def save_project_path(self, path):
|
def save_project_path(self, path):
|
||||||
proj_file = get_file('files/last_project_path.txt')
|
proj_file = get_file('files/last_project_path.txt')
|
||||||
with open(proj_file, 'w+') as f:
|
with codecs.open(proj_file, 'w+', encoding='utf-8') as f:
|
||||||
f.write(path)
|
f.write(path)
|
||||||
|
|
||||||
def save_recent_project(self, proj):
|
def save_recent_project(self, proj):
|
||||||
recent_file_path = get_file('files/recent_files.txt')
|
recent_file_path = get_file('files/recent_files.txt')
|
||||||
max_length = MAX_RECENT
|
max_length = MAX_RECENT
|
||||||
recent_files = open(recent_file_path, 'a+').read().split('\n')
|
recent_files = codecs.open(recent_file_path, 'a+', encoding='utf-8').read().split(u'\n')
|
||||||
try:
|
try:
|
||||||
recent_files.remove(proj)
|
recent_files.remove(proj)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
pass
|
pass
|
||||||
recent_files.append(proj)
|
recent_files.append(proj)
|
||||||
with open(recent_file_path, 'w+') as f:
|
with codecs.open(recent_file_path, 'w+', encoding='utf-8') as f:
|
||||||
for recent_file in recent_files[-max_length:]:
|
for recent_file in recent_files[-max_length:]:
|
||||||
if recent_file and os.path.exists(recent_file):
|
if recent_file and os.path.exists(recent_file):
|
||||||
f.write(recent_file+'\n')
|
f.write(u'{}\n'.format(recent_file))
|
||||||
|
|
||||||
def update_recent_files(self):
|
def update_recent_files(self):
|
||||||
previous_files = self.load_recent_projects()
|
previous_files = self.load_recent_projects()
|
||||||
self.recent_separator.setVisible(len(previous_files) > 0)
|
self.recent_separator.setVisible(len(previous_files) > 0)
|
||||||
for i in xrange(len(previous_files)):
|
for i in xrange(len(previous_files)):
|
||||||
text = '{} - {}'.format(i+1, os.path.basename(previous_files[i]))
|
text = u'{} - {}'.format(i+1, os.path.basename(previous_files[i]))
|
||||||
action = self.recent_file_actions[i]
|
action = self.recent_file_actions[i]
|
||||||
action.setText(text)
|
action.setText(text)
|
||||||
action.setData(previous_files[i])
|
action.setData(previous_files[i])
|
||||||
|
|
@ -169,7 +170,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
|
|
||||||
self.option_settings_enabled(False)
|
self.option_settings_enabled(False)
|
||||||
|
|
||||||
self.setWindowTitle("Web2Executable {}".format(__gui_version__))
|
self.setWindowTitle(u"Web2Executable {}".format(__gui_version__))
|
||||||
self.update_nw_versions(None)
|
self.update_nw_versions(None)
|
||||||
|
|
||||||
def open_recent_file(self):
|
def open_recent_file(self):
|
||||||
|
|
@ -180,9 +181,10 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
def setup_nw_versions(self):
|
def setup_nw_versions(self):
|
||||||
nw_version = self.get_setting('nw_version')
|
nw_version = self.get_setting('nw_version')
|
||||||
try:
|
try:
|
||||||
f = open(get_file('files/nw-versions.txt'))
|
f = codecs.open(get_file('files/nw-versions.txt'), encoding='utf-8')
|
||||||
for line in f:
|
for line in f:
|
||||||
nw_version.values.append(line.strip())
|
nw_version.values.append(line.strip())
|
||||||
|
f.close()
|
||||||
except IOError:
|
except IOError:
|
||||||
nw_version.values.append(nw_version.default_value)
|
nw_version.values.append(nw_version.default_value)
|
||||||
|
|
||||||
|
|
@ -284,7 +286,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
self.cancel_button.setEnabled(False)
|
self.cancel_button.setEnabled(False)
|
||||||
|
|
||||||
def show_error(self, exception):
|
def show_error(self, exception):
|
||||||
QtGui.QMessageBox.information(self, 'Error!', str(exception))
|
QtGui.QMessageBox.information(self, 'Error!', unicode(exception))
|
||||||
|
|
||||||
def disable_ui_while_working(self):
|
def disable_ui_while_working(self):
|
||||||
self.option_settings_enabled(False)
|
self.option_settings_enabled(False)
|
||||||
|
|
@ -315,7 +317,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
for sgroup in self.settings['setting_groups']:
|
for sgroup in self.settings['setting_groups']:
|
||||||
for sname, setting in sgroup.items():
|
for sname, setting in sgroup.items():
|
||||||
setting_path = os.path.join(self.project_dir(),
|
setting_path = os.path.join(self.project_dir(),
|
||||||
str(setting.value))
|
unicode(setting.value))
|
||||||
|
|
||||||
if setting.required and not setting.value:
|
if setting.required and not setting.value:
|
||||||
settings_valid = False
|
settings_valid = False
|
||||||
|
|
@ -334,7 +336,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
widget = self.find_child_by_name(setting.name)
|
widget = self.find_child_by_name(setting.name)
|
||||||
if widget is not None:
|
if widget is not None:
|
||||||
widget.setStyleSheet(red_border)
|
widget.setStyleSheet(red_border)
|
||||||
widget.setToolTip('The file "{}" does not exist.'.format(os.path.join(self.project_dir(),setting.value)))
|
widget.setToolTip(u'The file "{}" does not exist.'.format(os.path.join(self.project_dir(),setting.value)))
|
||||||
tab = self.get_tab_index_for_setting_name(setting.name)
|
tab = self.get_tab_index_for_setting_name(setting.name)
|
||||||
self.tab_widget.setTabIcon(tab, self.warning_settings_icon)
|
self.tab_widget.setTabIcon(tab, self.warning_settings_icon)
|
||||||
|
|
||||||
|
|
@ -345,7 +347,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
widget = self.find_child_by_name(setting.name)
|
widget = self.find_child_by_name(setting.name)
|
||||||
if widget is not None:
|
if widget is not None:
|
||||||
widget.setStyleSheet(red_border)
|
widget.setStyleSheet(red_border)
|
||||||
widget.setToolTip('The folder "{}" does not exist'.format(os.path.join(self.project_dir(), setting.value)))
|
widget.setToolTip(u'The folder "{}" does not exist'.format(os.path.join(self.project_dir(), setting.value)))
|
||||||
tab = self.get_tab_index_for_setting_name(setting.name)
|
tab = self.get_tab_index_for_setting_name(setting.name)
|
||||||
self.tab_widget.setTabIcon(tab, self.warning_settings_icon)
|
self.tab_widget.setTabIcon(tab, self.warning_settings_icon)
|
||||||
if settings_valid:
|
if settings_valid:
|
||||||
|
|
@ -454,7 +456,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
def read_response_header(self, response_header):
|
def read_response_header(self, response_header):
|
||||||
# Check for genuine error conditions.
|
# Check for genuine error conditions.
|
||||||
if response_header.statusCode() not in (200, 300, 301, 302, 303, 307):
|
if response_header.statusCode() not in (200, 300, 301, 302, 303, 307):
|
||||||
self.show_error('Download failed: {}.'.format(response_header.reasonPhrase()))
|
self.show_error(u'Download failed: {}.'.format(response_header.reasonPhrase()))
|
||||||
self.http_request_aborted = True
|
self.http_request_aborted = True
|
||||||
self.http.abort()
|
self.http.abort()
|
||||||
self.enable_ui_after_error()
|
self.enable_ui_after_error()
|
||||||
|
|
@ -475,7 +477,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
|
|
||||||
if error:
|
if error:
|
||||||
self.out_file.remove()
|
self.out_file.remove()
|
||||||
self.show_error('Download failed: {}.'.format(self.http.errorString()))
|
self.show_error(u'Download failed: {}.'.format(self.http.errorString()))
|
||||||
self.enable_ui_after_error()
|
self.enable_ui_after_error()
|
||||||
else:
|
else:
|
||||||
self.continue_downloading_or_extract()
|
self.continue_downloading_or_extract()
|
||||||
|
|
@ -499,7 +501,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
|
|
||||||
@progress_text.setter
|
@progress_text.setter
|
||||||
def progress_text(self, value):
|
def progress_text(self, value):
|
||||||
self.progress_label.setText(str(value))
|
self.progress_label.setText(unicode(value))
|
||||||
|
|
||||||
def run_in_background(self, method_name, callback):
|
def run_in_background(self, method_name, callback):
|
||||||
self.thread = BackgroundThread(self, method_name)
|
self.thread = BackgroundThread(self, method_name)
|
||||||
|
|
@ -581,7 +583,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
if minor >= 12:
|
if minor >= 12:
|
||||||
path = path.replace('node-webkit', 'nwjs')
|
path = path.replace('node-webkit', 'nwjs')
|
||||||
|
|
||||||
self.progress_text = 'Downloading {}'.format(path.replace(version_file, ''))
|
self.progress_text = u'Downloading {}'.format(path.replace(version_file, ''))
|
||||||
|
|
||||||
url = QUrl(path)
|
url = QUrl(path)
|
||||||
file_name = setting.save_file_path(self.selected_version(), location)
|
file_name = setting.save_file_path(self.selected_version(), location)
|
||||||
|
|
@ -603,7 +605,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
self.out_file = QFile(file_name)
|
self.out_file = QFile(file_name)
|
||||||
if not self.out_file.open(QIODevice.WriteOnly):
|
if not self.out_file.open(QIODevice.WriteOnly):
|
||||||
error = self.out_file.error().name
|
error = self.out_file.error().name
|
||||||
self.show_error('Unable to save the file {}: {}.'.format(file_name,
|
self.show_error(u'Unable to save the file {}: {}.'.format(file_name,
|
||||||
error))
|
error))
|
||||||
self.out_file = None
|
self.out_file = None
|
||||||
self.enable_ui()
|
self.enable_ui()
|
||||||
|
|
@ -618,9 +620,9 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
|
|
||||||
path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
|
path = QUrl.toPercentEncoding(url.path(), "!$&'()*+,;=:@/")
|
||||||
if path:
|
if path:
|
||||||
path = str(path)
|
path = unicode(path)
|
||||||
else:
|
else:
|
||||||
path = '/'
|
path = u'/'
|
||||||
|
|
||||||
# Download the file.
|
# Download the file.
|
||||||
self.http_get_id = self.http.get(path, self.out_file)
|
self.http_get_id = self.http.get(path, self.out_file)
|
||||||
|
|
@ -944,7 +946,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
text.textChanged.connect(self.call_with_object('setting_changed',
|
text.textChanged.connect(self.call_with_object('setting_changed',
|
||||||
text, setting))
|
text, setting))
|
||||||
if setting.value:
|
if setting.value:
|
||||||
text.setText(str(setting.value))
|
text.setText(unicode(setting.value))
|
||||||
text.setStatusTip(setting.description)
|
text.setStatusTip(setting.description)
|
||||||
text.setToolTip(setting.description)
|
text.setToolTip(setting.description)
|
||||||
|
|
||||||
|
|
@ -968,7 +970,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
text, setting))
|
text, setting))
|
||||||
|
|
||||||
if setting.value:
|
if setting.value:
|
||||||
text.setText(str(setting.value))
|
text.setText(unicode(setting.value))
|
||||||
text.setStatusTip(setting.description)
|
text.setStatusTip(setting.description)
|
||||||
text.setToolTip(setting.description)
|
text.setToolTip(setting.description)
|
||||||
|
|
||||||
|
|
@ -996,7 +998,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
text, setting))
|
text, setting))
|
||||||
|
|
||||||
if setting.value:
|
if setting.value:
|
||||||
text.setText(str(setting.value))
|
text.setText(unicode(setting.value))
|
||||||
text.setStatusTip(setting.description)
|
text.setStatusTip(setting.description)
|
||||||
text.setToolTip(setting.description)
|
text.setToolTip(setting.description)
|
||||||
|
|
||||||
|
|
@ -1024,7 +1026,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
old_val = setting.default_value
|
old_val = setting.default_value
|
||||||
|
|
||||||
setting.value = old_val.replace('\\', '\\\\')
|
setting.value = old_val.replace('\\', '\\\\')
|
||||||
widget.setText(str(old_val))
|
widget.setText(unicode(old_val))
|
||||||
|
|
||||||
elif setting.type == 'check':
|
elif setting.type == 'check':
|
||||||
old_val = False
|
old_val = False
|
||||||
|
|
@ -1045,10 +1047,10 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
def set_kiosk_emulation_options(self, is_checked):
|
def set_kiosk_emulation_options(self, is_checked):
|
||||||
if is_checked:
|
if is_checked:
|
||||||
width_field = self.find_child_by_name('width')
|
width_field = self.find_child_by_name('width')
|
||||||
width_field.setText(str(self.desktop_width))
|
width_field.setText(unicode(self.desktop_width))
|
||||||
|
|
||||||
height_field = self.find_child_by_name('height')
|
height_field = self.find_child_by_name('height')
|
||||||
height_field.setText(str(self.desktop_height))
|
height_field.setText(unicode(self.desktop_height))
|
||||||
|
|
||||||
toolbar_field = self.find_child_by_name('toolbar')
|
toolbar_field = self.find_child_by_name('toolbar')
|
||||||
toolbar_field.setChecked(not is_checked)
|
toolbar_field.setChecked(not is_checked)
|
||||||
|
|
@ -1094,7 +1096,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
if self.update_json:
|
if self.update_json:
|
||||||
json_file = os.path.join(self.project_dir(), 'package.json')
|
json_file = os.path.join(self.project_dir(), 'package.json')
|
||||||
|
|
||||||
with open(json_file, 'w+') as f:
|
with codecs.open(json_file, 'w+', encoding='utf-8') as f:
|
||||||
f.write(self.generate_json())
|
f.write(self.generate_json())
|
||||||
|
|
||||||
self.ex_button.setEnabled(self.required_settings_filled())
|
self.ex_button.setEnabled(self.required_settings_filled())
|
||||||
|
|
@ -1183,7 +1185,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
slider.setStatusTip(setting.description)
|
slider.setStatusTip(setting.description)
|
||||||
slider.setToolTip(setting.description)
|
slider.setToolTip(setting.description)
|
||||||
|
|
||||||
range_label = QtGui.QLabel(str(setting.default_value))
|
range_label = QtGui.QLabel(unicode(setting.default_value))
|
||||||
range_label.setMaximumWidth(30)
|
range_label.setMaximumWidth(30)
|
||||||
|
|
||||||
slider.valueChanged.connect(self.call_with_object('_update_range_label',
|
slider.valueChanged.connect(self.call_with_object('_update_range_label',
|
||||||
|
|
@ -1200,7 +1202,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase):
|
||||||
return hlayout
|
return hlayout
|
||||||
|
|
||||||
def _update_range_label(self, label, value):
|
def _update_range_label(self, label, value):
|
||||||
label.setText(str(value))
|
label.setText(unicode(value))
|
||||||
|
|
||||||
def load_package_json(self):
|
def load_package_json(self):
|
||||||
setting_list = super(MainWindow, self).load_package_json()
|
setting_list = super(MainWindow, self).load_package_json()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue