Skip to content

Commit e8b51f9

Browse files
committed
Implement #167: Web2exe settings in separate file
1 parent 2c272ee commit e8b51f9

File tree

4 files changed

+42
-42
lines changed

4 files changed

+42
-42
lines changed

command_line.py

Lines changed: 27 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -456,26 +456,30 @@ def process_webexe_settings(self, dic, global_json):
456456
if setting.value is not None:
457457
dic['webexe_settings'][setting_name] = setting.value
458458

459+
def generate_web2exe_json(self, global_json=False):
460+
"""Generates web2exe's settings json"""
461+
self.logger.info('Generating web2exe json file...')
459462

460-
def generate_json(self, global_json=False):
461-
"""Generates the json config files for the exported app"""
462-
self.logger.info('Generating package.json...')
463+
web2exe_dic = {'webexe_settings': {}}
463464

464-
dic = {'webexe_settings': {}}
465+
self.process_webexe_settings(web2exe_dic, global_json)
465466

466-
if not global_json:
467-
dic.update({'webkit': {}, 'window': {}})
468-
dic.update(self.original_packagejson)
467+
return json.dumps(web2exe_dic, indent=4, sort_keys=True)
468+
469+
def generate_project_json(self):
470+
"""Generates the json config files for the exported app"""
471+
self.logger.info('Generating package.json...')
469472

470-
self.process_app_settings(dic)
471-
self.process_window_settings(dic)
472-
self.process_webkit_settings(dic)
473+
dic = {}
473474

474-
self.process_webexe_settings(dic, global_json)
475+
dic.update({'webkit': {}, 'window': {}})
476+
dic.update(self.original_packagejson)
475477

476-
s = json.dumps(dic, indent=4, sort_keys=True)
478+
self.process_app_settings(dic)
479+
self.process_window_settings(dic)
480+
self.process_webkit_settings(dic)
477481

478-
return s
482+
return json.dumps(dic, indent=4, sort_keys=True)
479483

480484
@property
481485
def extract_error(self):
@@ -636,18 +640,23 @@ def replace_icon_in_exe(self, exe_path):
636640
def write_package_json(self):
637641
"""Collects filled options and writes corresponding json files"""
638642
json_file = utils.path_join(self.project_dir(), 'package.json')
643+
w2e_json_file = utils.path_join(self.project_dir(),
644+
config.WEB2EXE_JSON_FILE)
639645

640646
global_json = utils.get_data_file_path(config.GLOBAL_JSON_FILE)
641647

642648
# Write package json
643649
if self.output_package_json:
644650
with codecs.open(json_file, 'w+', encoding='utf-8') as f:
645-
f.write(self.generate_json())
651+
f.write(self.generate_project_json())
652+
with codecs.open(w2e_json_file,
653+
'w+', encoding='utf-8') as f:
654+
f.write(self.generate_web2exe_json())
646655

647656
# Write global settings that are kept when installing new
648657
# versions
649658
with codecs.open(global_json, 'w+', encoding='utf-8') as f:
650-
f.write(self.generate_json(global_json=True))
659+
f.write(self.generate_web2exe_json(global_json=True))
651660

652661
def clean_dirs(self, *dirs):
653662
"""
@@ -1603,25 +1612,6 @@ def read_package_json_file(args, command_base):
16031612
# Load json is a path, so load JSON from the specified file
16041613
command_base.load_package_json(args.load_json)
16051614

1606-
def write_package_json_file(args, command_base):
1607-
"""Determine whether or not to write the package json file."""
1608-
write_json = False
1609-
1610-
if args.load_json is not True and args.load_json:
1611-
# Load json is a path, so check if the default package json
1612-
# exists before writing it. If it exists, don't overwrite it
1613-
# so that people's changes to the file are preserved
1614-
project_dir = command_base.project_dir()
1615-
json_path = os.path.abspath(os.path.expanduser(args.load_json))
1616-
left_over_path = json_path.replace(project_dir, '')
1617-
1618-
# Write package.json if it's not already in the root
1619-
# of the project
1620-
if left_over_path != 'package.json':
1621-
write_json = True
1622-
1623-
command_base.export(write_json)
1624-
16251615
def initialize_setting_values(args, command_base):
16261616
for name, val in args._get_kwargs():
16271617
if callable(val):
@@ -1650,7 +1640,9 @@ def main():
16501640
initialize_setting_values(args, command_base)
16511641

16521642
read_package_json_file(args, command_base)
1653-
write_package_json_file(args, command_base)
1643+
1644+
# Never write package.json on command line. Only load it.
1645+
command_base.export(write_json=False)
16541646

16551647
if __name__ == '__main__':
16561648
main()

config.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ def is_installed():
7272
VER_FILE = 'files/nw-versions.txt'
7373
SETTINGS_FILE = 'files/settings.cfg'
7474
GLOBAL_JSON_FILE = 'files/global.json'
75+
WEB2EXE_JSON_FILE = 'web2exe.json'
7576

7677
LAST_PROJECT_FILE = 'files/last_project_path.txt'
7778
RECENT_FILES_FILE = 'files/recent_files.txt'

files/settings.cfg

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -114,20 +114,20 @@ linux_64_dir_prefix = 'nwjs-v{}-linux-x64'
114114
[[web2exe_settings]]
115115
[[[export_dir]]]
116116
display_name='Output Directory'
117-
default_value=None
117+
default_value=''
118118
type='string'
119119
description='The output directory relative to the project directory.'
120120
[[[custom_script]]]
121121
display_name='Execute Script'
122-
default_value=None
122+
default_value=''
123123
copy=False
124124
type='file'
125125
description='The script to execute after a project was successfully exported.'
126126
[[[output_pattern]]]
127127
display_name='Output Name Pattern'
128-
default_value=None
128+
default_value=''
129129
type='string'
130-
description='Instead of using the App Name for the output directory, this field can\nbe used to reference different settings of the package.json to name the output folder.'
130+
description='Type "%(" to see a list of options to reference. Name your output folder.'
131131

132132
[[window_settings]]
133133
[[[id]]]

main.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -946,8 +946,10 @@ def load_project(self, directory):
946946

947947
# Load the global json and then overwrite the settings with user
948948
# chosen values
949-
self.load_package_json(utils.get_data_file_path(config.GLOBAL_JSON_FILE))
950949
self.load_package_json()
950+
self.load_package_json(utils.get_data_file_path(config.GLOBAL_JSON_FILE))
951+
self.load_package_json(utils.path_join(self.project_dir(),
952+
config.WEB2EXE_JSON_FILE))
951953

952954
default_dir = 'output'
953955
export_dir_setting = self.get_setting('export_dir')
@@ -1482,13 +1484,18 @@ def setting_changed(self, obj, setting, *args):
14821484
# Generate json file
14831485
if self.update_json:
14841486
json_file = utils.path_join(self.project_dir(), 'package.json')
1487+
w2e_json_file = utils.path_join(self.project_dir(), config.WEB2EXE_JSON_FILE)
14851488
global_json = utils.get_data_file_path(config.GLOBAL_JSON_FILE)
14861489

14871490
with codecs.open(json_file, 'w+', encoding='utf-8') as f:
1488-
f.write(self.generate_json())
1491+
f.write(self.generate_project_json())
1492+
1493+
with codecs.open(w2e_json_file,
1494+
'w+', encoding='utf-8') as f:
1495+
f.write(self.generate_web2exe_json())
14891496

14901497
with codecs.open(global_json, 'w+', encoding='utf-8') as f:
1491-
f.write(self.generate_json(global_json=True))
1498+
f.write(self.generate_web2exe_json(global_json=True))
14921499

14931500
self.ex_button.setEnabled(self.required_settings_filled())
14941501

0 commit comments

Comments
 (0)