From 35bf4ad53c76c26c5498e07080e64ab1eb0e543c Mon Sep 17 00:00:00 2001 From: Joey Payne Date: Wed, 11 Nov 2015 13:52:02 -0700 Subject: [PATCH] Added .bat and .bash scripts for exporting. --- command_line.py | 72 +++++++++++++++++++++++++++++++++++++++++----- files/settings.cfg | 3 +- main.py | 16 +++++++++-- 3 files changed, 80 insertions(+), 11 deletions(-) diff --git a/command_line.py b/command_line.py index 04ef655..7333ff5 100644 --- a/command_line.py +++ b/command_line.py @@ -116,6 +116,7 @@ class Setting(object): self.last_value = None self.required = required self.type = type + self.copy = kwargs.pop('copy', True) self.file_types = file_types self.scope = kwargs.pop('scope', 'local') @@ -828,7 +829,7 @@ class CommandBase(object): upx_version = comp_dict.get(plat, None) if upx_version is not None: - upx_bin = utils.path_join('files', 'compressors', upx_version) + upx_bin = upx_version os.chmod(upx_bin, 0755) cmd = [upx_bin, '--lzma', u'-{}'.format(compression.value), unicode(nw_path)] if platform.system() == 'Windows': @@ -856,7 +857,7 @@ class CommandBase(object): self.logger.info(u'Copying files to {}'.format(self.project_dir())) for sgroup in self.settings['setting_groups']: for setting in sgroup.values(): - if setting.type == 'file' and setting.value: + if setting.copy and setting.type == 'file' and setting.value: f_path = setting.value.replace(self.project_dir(), '') if os.path.isabs(f_path): try: @@ -885,7 +886,7 @@ class CommandBase(object): with codecs.open(script, 'r', encoding='utf-8') as f: contents = f.read() - filename, ext = os.path.splitext(script) + _, ext = os.path.splitext(script) export_opts = self.get_export_options() export_dir = '{}{}{}'.format(self.output_dir(), @@ -895,6 +896,8 @@ class CommandBase(object): for opt in export_opts: export_dirs.append('{}{}{}'.format(export_dir, os.path.sep, opt)) + command = None + if ext == '.py': env_file = get_file('files/env_vars.py') env_contents = codecs.open(env_file, 'r', encoding='utf-8').read() @@ -903,11 +906,66 @@ class CommandBase(object): export_dir=export_dir, export_dirs=str(export_dirs)) pycontents = '{}\n{}'.format(env_vars, contents) - exec(pycontents) - self.progress_text = 'Done executing script.' - else: - pass + command = ['python', '-c', pycontents] + + + elif ext == '.bash': + env_file = get_file('files/env_vars.bash') + env_contents = codecs.open(env_file, 'r', encoding='utf-8').read() + ex_dir_vars = '' + + for ex_dir in export_dirs: + ex_dir_vars += "'{}' ".format(ex_dir) + + env_vars = env_contents.format(proj_dir=self.project_dir(), + proj_name=self.project_name(), + export_dir=export_dir, + export_dirs=ex_dir_vars) + shcontents = '{}\n{}'.format(env_vars, contents) + + command = ['bash', '-c', shcontents] + + elif ext == '.bat': + env_file = get_file('files/env_vars.bat') + env_contents = codecs.open(env_file, 'r', encoding='utf-8').read() + ex_dir_vars = '' + export_dict = {'mac-x64_dir': '', + 'mac-x32_dir': '', + 'win-x64_dir': '', + 'win-x32_dir': '', + 'linux-x64_dir': '', + 'linux-x32_dir': ''} + + for i, ex_dir in enumerate(export_dirs): + opt = export_opts[i] + export_dict[opt+'_dir'] = ex_dir + ex_dir_vars += 'set EXPORT_DIRS[{}]={} & '.format(i, ex_dir) + + env_vars = env_contents.format(proj_dir=self.project_dir(), + proj_name=self.project_name(), + export_dir=export_dir, + num_dirs=len(export_dirs), + export_dirs=ex_dir_vars, + **export_dict) + batcontents = '{}{}'.format(env_vars.replace('\n',''), contents.replace('\n', ' & ')) + batcontents = batcontents[:-3] + + command = ['cmd', '/c', "'" + batcontents + "'"] + + proc = subprocess.Popen(' '.join(command), stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True) + output, error = proc.communicate() + output = output.strip() + error = error.strip() + + with open(get_file('script-output.txt'), 'w+') as f: + f.write('Output:\n{}'.format(output)) + if error: + f.write('\n\nErrors:\n{}\n'.format(error)) + + + + self.progress_text = 'Done executing script.' else: self.progress_text = '\nThe script {} does not exist. Not running.'.format(script) diff --git a/files/settings.cfg b/files/settings.cfg index ac498e8..772aefb 100644 --- a/files/settings.cfg +++ b/files/settings.cfg @@ -114,7 +114,8 @@ linux_64_dir_prefix = 'node-webkit-v{}-linux-x64' type='string' [[[custom_script]]] default_value='' - type='string' + copy=False + type='file' [[window_settings]] [[[title]]] diff --git a/main.py b/main.py index 329b012..0d072fc 100644 --- a/main.py +++ b/main.py @@ -317,6 +317,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase): 'webkit_settings': 0, 'window_settings': 1, 'export_settings': 2, + 'web2exe_settings': 2, 'compression': 3, 'download_settings': 4} for setting_group_name, setting_group in self._setting_items: @@ -330,7 +331,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase): red_border = 'QLineEdit{border:3px solid rgba(238, 68, 83, 200); border-radius:5px;}' settings_valid = True - for sgroup in self.settings['setting_groups']: + for sgroup in self.settings['setting_groups']+[self.settings['web2exe_settings']]: for sname, setting in sgroup.items(): if setting.type in set(['file', 'folder']) and os.path.isabs(setting.value): setting_path = unicode(setting.value) @@ -384,6 +385,9 @@ class MainWindow(QtGui.QMainWindow, CommandBase): if setting.value: export_chosen = True + if not settings_valid: + return export_chosen and settings_valid + for setting_name, setting in self.settings['export_settings'].items(): if not export_chosen: widget = self.find_child_by_name(setting.name) @@ -554,6 +558,7 @@ class MainWindow(QtGui.QMainWindow, CommandBase): def script_done(self): self.ex_button.setEnabled(self.required_settings_filled()) self.enable_ui() + self.progress_text = 'Done!' def done_making_files(self): self.ex_button.setEnabled(self.required_settings_filled()) @@ -933,9 +938,11 @@ class MainWindow(QtGui.QMainWindow, CommandBase): output_layout = QtGui.QHBoxLayout() output_label = QtGui.QLabel('Output Directory:') + output_label.setMinimumWidth(150) self.output_line = QtGui.QLineEdit() self.output_line.textChanged.connect(self.call_with_object('setting_changed', - self.output_line, self.get_setting('export_dir'))) + self.output_line, + self.get_setting('export_dir'))) self.output_line.textChanged.connect(self.project_path_changed) self.output_line.setStatusTip('The output directory relative to the project directory.') output_button = QtGui.QPushButton('...') @@ -948,11 +955,13 @@ class MainWindow(QtGui.QMainWindow, CommandBase): script_layout = QtGui.QHBoxLayout() script_label = QtGui.QLabel('Execute Script:') + 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) self.script_line.textChanged.connect(self.call_with_object('setting_changed', self.script_line, @@ -965,7 +974,8 @@ class MainWindow(QtGui.QMainWindow, CommandBase): if platform.system() == 'Windows': file_types.append('*.bat') else: - file_types.extend(['*.bash', '*.sh', '*.zsh']) + file_types.append('*.bash') + file_types.append('*.bat') script_button.clicked.connect(self.call_with_object('get_file_reg', script_button, self.script_line, script_setting,