Skip to content

Commit c7ce8a0

Browse files
committed
Close #172: Customize output pattern directory
1 parent 37c68a5 commit c7ce8a0

File tree

2 files changed

+61
-40
lines changed

2 files changed

+61
-40
lines changed

command_line.py

Lines changed: 45 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -156,13 +156,13 @@ def project_name(self):
156156
return (self._project_name or
157157
os.path.basename(os.path.abspath(self.project_dir())))
158158

159-
def sub_output_pattern(self, pattern):
159+
def sub_output_pattern(self, pattern, tag_dict=None):
160160
"""
161161
Substitute patterns for setting values
162162
"""
163163
byte_pattern = bytearray(pattern.encode())
164164

165-
val_dict = self.get_tag_value_dict()
165+
val_dict = tag_dict or self.get_tag_value_dict()
166166

167167
start = 0
168168
end = 0
@@ -197,8 +197,7 @@ def sub_output_pattern(self, pattern):
197197

198198
i += 1
199199

200-
return str(byte_pattern, 'utf-8').replace('/', '_').replace('\\', '_')
201-
200+
return str(byte_pattern, 'utf-8')
202201

203202
def get_tag_dict(self):
204203
"""
@@ -217,6 +216,10 @@ def get_tag_dict(self):
217216
setting = setting_group[key]
218217
tag_dict[setting.display_name] = '%('+key+')'
219218

219+
tag_dict['System'] = '%(system)'
220+
tag_dict['Architecture'] = '%(arch)'
221+
tag_dict['Short System'] = '%(sys)'
222+
220223
return tag_dict
221224

222225
def get_tag_value_dict(self):
@@ -677,7 +680,7 @@ def clean_dirs(self, *dirs):
677680
if not os.path.exists(directory):
678681
os.makedirs(directory)
679682

680-
def get_export_dest(self, ex_setting, output_dir):
683+
def get_export_path(self, ex_setting, name_pattern):
681684
"""Get the export destination path using the export setting
682685
683686
Args:
@@ -687,9 +690,20 @@ def get_export_dest(self, ex_setting, output_dir):
687690
Returns:
688691
A path to store the output files
689692
"""
690-
export_dest = utils.path_join(output_dir, ex_setting.name)
691693

692-
return export_dest
694+
tag_dict = {
695+
'%(system)': ex_setting.system,
696+
'%(sys)': ex_setting.short_system,
697+
'%(arch)': ex_setting.arch,
698+
'%(platform)': ex_setting.name
699+
}
700+
701+
dest = self.sub_output_pattern(name_pattern, tag_dict)
702+
703+
if dest == name_pattern:
704+
dest = utils.path_join(name_pattern, ex_setting.name)
705+
706+
return dest
693707

694708
def copy_export_files(self, ex_setting, export_dest):
695709
"""Copy the export files to the destination path
@@ -749,13 +763,12 @@ def replace_plist(self, app_path):
749763
plistlib.writePlist(plist_dict, plist_path)
750764

751765
def process_mac_setting(self, app_loc, export_dest,
752-
ex_setting, uncompressed):
766+
ex_setting):
753767
"""Process the Mac settings
754768
755769
Args:
756770
app_loc: the app's location
757771
export_dest: the destination to export the app to
758-
uncompressed: boolean -> app is compressed or not
759772
"""
760773

761774
app_path = utils.path_join(export_dest,
@@ -775,7 +788,7 @@ def process_mac_setting(self, app_loc, export_dest,
775788

776789
app_nw_res = utils.path_join(resource_path, 'app.nw')
777790

778-
if uncompressed:
791+
if self.uncompressed:
779792
utils.copytree(app_loc, app_nw_res)
780793
else:
781794
utils.copy(app_loc, app_nw_res)
@@ -792,7 +805,7 @@ def process_mac_setting(self, app_loc, export_dest,
792805

793806

794807
def process_win_linux_setting(self, app_loc, export_dest,
795-
ex_setting, uncompressed):
808+
ex_setting):
796809
"""Processes windows and linux settings
797810
798811
Creates executable, modifies exe icon, and copies to the destination
@@ -801,7 +814,6 @@ def process_win_linux_setting(self, app_loc, export_dest,
801814
app_loc: the location of the app
802815
export_dest: directory to copy app to
803816
ex_setting: the export setting (eg: mac-x32)
804-
uncompressed: boolean -> app is compressed or not
805817
806818
"""
807819

@@ -822,7 +834,7 @@ def process_win_linux_setting(self, app_loc, export_dest,
822834
self.make_desktop_file(dest_binary_path, export_dest)
823835

824836
self.copy_executable(export_dest, dest_binary_path,
825-
nw_path, app_loc, uncompressed)
837+
nw_path, app_loc)
826838

827839
self.set_executable(dest_binary_path)
828840

@@ -831,8 +843,7 @@ def process_win_linux_setting(self, app_loc, export_dest,
831843
if os.path.exists(nw_path):
832844
os.remove(nw_path)
833845

834-
def process_export_setting(self, ex_setting, output_dir,
835-
temp_dir, app_loc, uncompressed):
846+
def process_export_setting(self, ex_setting, output_name):
836847
"""Create the executable based on the export setting"""
837848
if ex_setting.value:
838849
self.progress_text = '\n'
@@ -841,45 +852,44 @@ def process_export_setting(self, ex_setting, output_dir,
841852

842853
self.progress_text = 'Making files for {}...'.format(name)
843854

844-
export_dest = self.get_export_dest(ex_setting, output_dir)
855+
temp_dir = utils.path_join(config.TEMP_DIR, 'webexectemp')
856+
857+
name_path = self.get_export_path(ex_setting, output_name)
858+
output_dir = utils.path_join(self.output_dir(), name_path)
859+
self.clean_dirs(temp_dir, output_dir)
860+
app_loc = self.get_app_nw_loc(temp_dir, output_dir)
845861

846-
self.copy_export_files(ex_setting, export_dest)
862+
self.copy_export_files(ex_setting, output_dir)
847863

848864
self.progress_text += '.'
849865

850866
if 'mac' in ex_setting.name:
851-
self.process_mac_setting(app_loc, export_dest, ex_setting,
852-
uncompressed)
867+
self.process_mac_setting(app_loc, output_dir, ex_setting)
853868
else:
854-
self.process_win_linux_setting(app_loc, export_dest,
855-
ex_setting, uncompressed)
869+
self.process_win_linux_setting(app_loc, output_dir,
870+
ex_setting)
856871

857872

858873
def make_output_dirs(self, write_json=True):
859874
"""Create the output directories for the application to be copied"""
860875

861876
output_name = self.sub_pattern() or self.project_name()
862877

863-
output_dir = utils.path_join(self.output_dir(), output_name)
864-
temp_dir = utils.path_join(config.TEMP_DIR, 'webexectemp')
865-
866878
self.progress_text = 'Making new directories...\n'
867879

868-
self.clean_dirs(temp_dir, output_dir)
869-
870880
self.copy_files_to_project_folder()
871881

872882
if write_json:
873883
self.write_package_json()
874884

875-
app_loc = self.get_app_nw_loc(temp_dir, output_dir)
885+
for ex_setting in self.settings['export_settings'].values():
886+
self.process_export_setting(ex_setting, output_name)
876887

888+
@property
889+
def uncompressed(self):
890+
"""Returns true if the exported app is to be uncompressed"""
877891
uncomp_setting = self.get_setting('uncompressed_folder')
878-
uncompressed = uncomp_setting.value
879-
880-
for ex_setting in self.settings['export_settings'].values():
881-
self.process_export_setting(ex_setting, output_dir, temp_dir,
882-
app_loc, uncompressed)
892+
return uncomp_setting.value
883893

884894
def sub_pattern(self):
885895
"""Returns the output pattern substitution or an empty string"""
@@ -903,10 +913,7 @@ def get_app_nw_loc(self, temp_dir, output_dir):
903913
"""Copy the temporary app to the output_dir"""
904914
app_file = utils.path_join(temp_dir, self.project_name()+'.nw')
905915

906-
uncomp_setting = self.get_setting('uncompressed_folder')
907-
uncompressed = uncomp_setting.value
908-
909-
if uncompressed:
916+
if self.uncompressed:
910917
app_nw_folder = utils.path_join(temp_dir,
911918
self.project_name()+'.nwf')
912919

@@ -931,12 +938,12 @@ def get_version_tuple(self):
931938
return [int(s) for s in strs]
932939

933940
def copy_executable(self, export_path, dest_path,
934-
nw_path, app_loc, uncompressed):
941+
nw_path, app_loc):
935942
"""
936943
Merge the zip file into the exe and copy it to the destination path
937944
"""
938945
package_loc = utils.path_join(export_path, 'package.nw')
939-
if uncompressed:
946+
if self.uncompressed:
940947
utils.copytree(app_loc, package_loc)
941948
utils.copy(nw_path, dest_path)
942949
else:

files/settings.cfg

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ linux_64_dir_prefix = 'nwjs-v{}-linux-x64'
127127
display_name='Output Name Pattern'
128128
default_value=''
129129
type='string'
130-
description='Type "%(" to see a list of options to reference. Name your output folder.'
130+
description='Type "%(" to see a list of options to reference. Name your output folder.\n Include slashes to make sub-directories.'
131131

132132
[[window_settings]]
133133
[[[id]]]
@@ -263,26 +263,40 @@ linux_64_dir_prefix = 'nwjs-v{}-linux-x64'
263263
type='check'
264264
url='%(base_url)s%(win_32_dir_prefix)s.zip'
265265
binary_location='nw.exe'
266+
system='windows'
267+
short_system='win'
268+
arch='x32'
266269
[[windows-x64]]
267270
default_value=None
268271
type='check'
269272
url='%(base_url)s%(win_64_dir_prefix)s.zip'
270273
binary_location='nw.exe'
274+
system='windows'
275+
short_system='win'
276+
arch='x64'
271277
[[mac-x64]]
272278
default_value=None
273279
type='check'
274280
url='%(base_url)s%(mac_64_dir_prefix)s.zip'
275-
281+
system='mac'
282+
short_system='mac'
283+
arch='x64'
276284
[[linux-x64]]
277285
default_value=None
278286
type='check'
279287
url='%(base_url)s%(linux_64_dir_prefix)s.tar.gz'
280288
binary_location='nw'
289+
system='linux'
290+
short_system='lin'
291+
arch='x64'
281292
[[linux-x32]]
282293
default_value=None
283294
type='check'
284295
url='%(base_url)s%(linux_32_dir_prefix)s.tar.gz'
285296
binary_location='nw'
297+
system='linux'
298+
short_system='lin'
299+
arch='x32'
286300

287301
[compression]
288302
[[nw_compression_level]]

0 commit comments

Comments
 (0)