Esempio n. 1
0
    def make_output_dirs(self):
        self.output_err = ''
        try:
            self.progress_text = 'Removing old output directory...\n'

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

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

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

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

            os.makedirs(temp_dir)

            self.copy_files_to_project_folder()

            json_file = utils.path_join(self.project_dir(), 'package.json')

            global_json = utils.get_data_file_path('files/global.json')

            if self.output_package_json:
                with codecs.open(json_file, 'w+', encoding='utf-8') as f:
                    f.write(self.generate_json())


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

            zip_file = utils.path_join(temp_dir, self.project_name()+'.nw')

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

            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():
                if ex_setting.value:
                    self.progress_text = '\n'
                    name = ex_setting.display_name
                    self.progress_text = u'Making files for {}...'.format(name)
                    export_dest = utils.path_join(output_dir, ex_setting.name)
                    versions = re.findall('(\d+)\.(\d+)\.(\d+)', self.selected_version())[0]

                    minor = int(versions[1])
                    if minor >= 12:
                        export_dest = export_dest.replace('node-webkit', 'nwjs')

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

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

                    if 'mac' in ex_setting.name:
                        uncomp_setting = self.get_setting('uncompressed_folder')
                        uncompressed = uncomp_setting.value
                        app_path = utils.path_join(export_dest,
                                                self.project_name()+'.app')

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

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

                        plist_dict = plistlib.readPlist(plist_path)

                        plist_dict['CFBundleDisplayName'] = self.project_name()
                        plist_dict['CFBundleName'] = self.project_name()
                        version_setting = self.get_setting('version')
                        plist_dict['CFBundleShortVersionString'] = version_setting.value
                        plist_dict['CFBundleVersion'] = version_setting.value

                        plistlib.writePlist(plist_dict, plist_path)


                        self.progress_text += '.'

                        app_nw_res = utils.path_join(app_path,
                                                  'Contents',
                                                  'Resources',
                                                  'app.nw')

                        if uncompressed:
                            utils.copytree(app_nw_folder, app_nw_res)
                        else:
                            utils.copy(zip_file, app_nw_res)
                        self.create_icns_for_app(utils.path_join(app_path,
                                                              'Contents',
                                                              'Resources',
                                                              'nw.icns'))

                        self.progress_text += '.'
                    else:
                        ext = ''
                        windows = False
                        if 'windows' in ex_setting.name:
                            ext = '.exe'
                            windows = True

                        nw_path = utils.path_join(export_dest,
                                               ex_setting.dest_files[0])

                        if windows:
                            self.replace_icon_in_exe(nw_path)

                        self.compress_nw(nw_path)

                        dest_binary_path = utils.path_join(export_dest,
                                                        self.project_name() +
                                                        ext)
                        if 'linux' in ex_setting.name:
                            self.make_desktop_file(dest_binary_path, export_dest)

                        join_files(dest_binary_path, nw_path, zip_file)

                        sevenfivefive = (stat.S_IRWXU |
                                         stat.S_IRGRP |
                                         stat.S_IXGRP |
                                         stat.S_IROTH |
                                         stat.S_IXOTH)
                        os.chmod(dest_binary_path, sevenfivefive)

                        self.progress_text += '.'

                        if os.path.exists(nw_path):
                            os.remove(nw_path)

        except Exception:
            error = u''.join([unicode(x) for x in traceback.format_exception(sys.exc_info()[0],
                                                                             sys.exc_info()[1],
                                                                             sys.exc_info()[2])])
            self.logger.error(error)
            self.output_err += error
        finally:
            utils.rmtree(temp_dir, ignore_errors=True)
Esempio n. 2
0
 def subzip(self, *members):
     """
     Returns a subset of the zip package according to a list of members/files.
     """
     dmembers = {member:self.get_fp(member) for member in members}
     return utils.zip_files(dmembers)
Esempio n. 3
0
    def makeOutputDirs(self):
        self.output_err = ''
        try:
            self.progress_text = 'Removing old output directory...'

            outputDir = os.path.join(self.outputDir(), self.projectName())
            tempDir = os.path.join(TEMP_DIR, 'webexectemp')
            if os.path.exists(tempDir):
                shutil.rmtree(tempDir)

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

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

            os.makedirs(tempDir)

            self.copyFilesToProjectFolder()

            json_file = os.path.join(self.projectDir(), 'package.json')

            with open(json_file, 'w+') as f:
                f.write(self.generate_json())

            zip_file = os.path.join(tempDir, self.projectName()+'.nw')

            zip_files(zip_file, self.projectDir(), exclude_paths=[outputDir])
            for ex_setting in self.export_settings.values():
                if ex_setting.value:
                    self.progress_text = 'Making files for {}'.format(ex_setting.display_name)
                    export_dest = os.path.join(outputDir, ex_setting.name)

                    if os.path.exists(export_dest):
                        shutil.rmtree(export_dest)

                    #shutil will make the directory for us
                    shutil.copytree(os.path.join('files', ex_setting.name), export_dest)
                    self.progress_text += '.'

                    if ex_setting.name == 'mac':
                        app_path = os.path.join(export_dest, self.projectName()+'.app')
                        enc_app_path = app_path.encode('utf8')
                        enc_export_dest = export_dest.encode('utf8')
                        shutil.move(os.path.join(export_dest, 'node-webkit.app'), app_path)

                        self.progress_text += '.'

                        shutil.copy(zip_file, os.path.join(app_path, 'Contents', 'Resources', 'app.nw'))

                        self.progress_text += '.'
                    else:
                        ext = ''
                        if ex_setting.name == 'windows':
                            ext = '.exe'

                        nw_path = os.path.join(export_dest, ex_setting.dest_files[0])
                        dest_binary_path = os.path.join(export_dest, self.projectName()+ext)
                        if ex_setting.name == 'linux-x64-NewLib':
                          command = 'sed -i s/udev.so.0/udev.so.1/g ' + nw_path
                          os.system(command.encode('utf8'))
                        elif ex_setting.name == 'linux-x32-NewLib':
                          command = 'sed -i s/udev.so.0/udev.so.1/g ' + nw_path
                          os.system(command.encode('utf8'))

                        join_files(os.path.join(export_dest, self.projectName()+ext), nw_path, zip_file)

                        sevenfivefive = stat.S_IRWXU | stat.S_IRGRP | stat.S_IXGRP | stat.S_IROTH | stat.S_IXOTH
                        os.chmod(dest_binary_path, sevenfivefive)

                        self.progress_text += '.'

                        if os.path.exists(nw_path):
                            os.remove(nw_path)

        except Exception as e:
            self.output_err += ''.join(traceback.format_exception(sys.exc_info()[0], sys.exc_info()[1], sys.exc_info()[2]))
        finally:
            shutil.rmtree(tempDir)
    def make_output_dirs(self):
        self.output_err = ''
        try:
            self.progress_text = 'Removing old output directory...\n'

            output_dir = os.path.join(self.output_dir(), self.project_name())
            temp_dir = os.path.join(TEMP_DIR, 'webexectemp')
            if os.path.exists(temp_dir):
                shutil.rmtree(temp_dir)

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

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

            os.makedirs(temp_dir)

            self.copy_files_to_project_folder()

            json_file = os.path.join(self.project_dir(), 'package.json')

            if self.output_package_json:
                with open(json_file, 'w+') as f:
                    f.write(self.generate_json())

            zip_file = os.path.join(temp_dir, self.project_name()+'.nw')

            zip_files(zip_file, self.project_dir(), exclude_paths=[output_dir])
            for ex_setting in self.settings['export_settings'].values():
                if ex_setting.value:
                    self.progress_text = '\n'
                    name = ex_setting.display_name
                    self.progress_text = 'Making files for {}...'.format(name)
                    export_dest = os.path.join(output_dir, ex_setting.name)
                    versions = re.findall('(\d+)\.(\d+)\.(\d+)', self.selected_version())[0]

                    minor = int(versions[1])
                    if minor >= 12:
                        export_dest = export_dest.replace('node-webkit', 'nwjs')

                    if os.path.exists(export_dest):
                        shutil.rmtree(export_dest)

                    # shutil will make the directory for us
                    shutil.copytree(os.path.join('files', ex_setting.name),
                                    export_dest,
                                    ignore=shutil.ignore_patterns('place_holder.txt'))
                    shutil.rmtree(os.path.join('files', ex_setting.name))
                    self.progress_text += '.'

                    if 'mac' in ex_setting.name:
                        app_path = os.path.join(export_dest,
                                                self.project_name()+'.app')

                        try:
                            shutil.move(os.path.join(export_dest,
                                                     'nwjs.app'),
                                        app_path)
                        except IOError:
                            shutil.move(os.path.join(export_dest,
                                                     'node-webkit.app'),
                                        app_path)

                        self.progress_text += '.'

                        shutil.copy(zip_file, os.path.join(app_path,
                                                           'Contents',
                                                           'Resources',
                                                           'app.nw'))
                        self.create_icns_for_app(os.path.join(app_path,
                                                              'Contents',
                                                              'Resources',
                                                              'nw.icns'))

                        self.progress_text += '.'
                    else:
                        ext = ''
                        windows = False
                        if 'windows' in ex_setting.name:
                            ext = '.exe'
                            windows = True

                        nw_path = os.path.join(export_dest,
                                               ex_setting.dest_files[0])

                        if windows:
                            self.replace_icon_in_exe(nw_path)

                        #self.compress_nw(nw_path)

                        dest_binary_path = os.path.join(export_dest,
                                                        self.project_name() +
                                                        ext)

                        join_files(dest_binary_path, nw_path, zip_file)

                        sevenfivefive = (stat.S_IRWXU |
                                         stat.S_IRGRP |
                                         stat.S_IXGRP |
                                         stat.S_IROTH |
                                         stat.S_IXOTH)
                        os.chmod(dest_binary_path, sevenfivefive)

                        self.progress_text += '.'

                        if os.path.exists(nw_path):
                            os.remove(nw_path)

        except Exception:
            exc = traceback.format_exception(sys.exc_info()[0],
                                             sys.exc_info()[1],
                                             sys.exc_info()[2])
            self.output_err += ''.join(exc)
        finally:
            shutil.rmtree(temp_dir)