Exemple #1
0
    def get_versions(self):
        if self.logger is not None:
            self.logger.info('Getting versions...')
        response = urllib2.urlopen(self.settings['version_info']['url'])
        html = response.read()

        nw_version = self.get_setting('nw_version')

        old_versions = set(nw_version.values)
        new_versions = set(re.findall('(\S+) / \S+', html))

        union_versions = list(old_versions.union(new_versions))

        versions = sorted(union_versions, key=Version, reverse=True)

        nw_version.values = versions
        f = None
        try:
            f = codecs.open(get_data_file_path('files/nw-versions.txt'),
                            'w',
                            encoding='utf-8')
            for v in nw_version.values:
                f.write(v + os.linesep)
            f.close()
        except IOError:
            error = u''.join(
                traceback.format_exception(sys.exc_info()[0],
                                           sys.exc_info()[1],
                                           sys.exc_info()[2]))
            self.show_error(error)
            self.enable_ui_after_error()
        finally:
            if f:
                f.close()
    def get_versions(self):
        if self.logger is not None:
            self.logger.info('Getting versions...')
        response = urllib2.urlopen(self.settings['version_info']['url'])
        html = response.read()

        nw_version = self.get_setting('nw_version')

        old_versions = set(nw_version.values)
        new_versions = set(re.findall('(\S+) / \S+', html))

        union_versions = list(old_versions.union(new_versions))

        versions = sorted(union_versions,
                          key=Version, reverse=True)

        nw_version.values = versions
        f = None
        try:
            f = codecs.open(get_data_file_path('files/nw-versions.txt'), 'w', encoding='utf-8')
            for v in nw_version.values:
                f.write(v+os.linesep)
            f.close()
        except IOError:
            error = u''.join(traceback.format_exception(sys.exc_info()[0],
                                                       sys.exc_info()[1],
                                                       sys.exc_info()[2]))
            self.show_error(error)
            self.enable_ui_after_error()
        finally:
            if f:
                f.close()
Exemple #3
0
 def delete_files(self):
     for ex_setting in self.settings['export_settings'].values():
         for dest_file in ex_setting.dest_files:
             f_path = get_data_file_path('files/{}/{}'.format(
                 ex_setting.name, dest_file))
             if os.path.exists(f_path):
                 os.remove(f_path)
Exemple #4
0
 def setup_nw_versions(self):
     nw_version = self.get_setting("nw_version")
     try:
         f = codecs.open(get_data_file_path("files/nw-versions.txt"), encoding="utf-8")
         for line in f:
             nw_version.values.append(line.strip())
         f.close()
     except IOError:
         nw_version.values.append(nw_version.default_value)
Exemple #5
0
 def setup_nw_versions(self):
     nw_version = self.get_setting('nw_version')
     try:
         f = codecs.open(get_data_file_path('files/nw-versions.txt'), encoding='utf-8')
         for line in f:
             nw_version.values.append(line.strip())
         f.close()
     except IOError:
         nw_version.values.append(nw_version.default_value)
 def setup_nw_versions(self):
     nw_version = self.get_setting('nw_version')
     nw_version.values = []
     try:
         f = codecs.open(get_data_file_path('files/nw-versions.txt'), encoding='utf-8')
         for line in f:
             nw_version.values.append(line.strip())
         f.close()
     except IOError:
         nw_version.values.append(nw_version.default_value)
    def compress_nw(self, nw_path):
        compression = self.get_setting('nw_compression_level')
        if compression.value == 0:
            return

        comp_dict = {'Darwin64bit': get_file('files/compressors/upx-mac'),
                     'Darwin32bit': get_file('files/compressors/upx-mac'),
                     'Linux64bit':  get_file('files/compressors/upx-linux-x64'),
                     'Linux32bit':  get_file('files/compressors/upx-linux-x32'),
                     'Windows64bit':  get_file('files/compressors/upx-win.exe'),
                     'Windows32bit':  get_file('files/compressors/upx-win.exe')
                     }

        if is_installed():
            comp_dict['Windows64bit'] = get_data_file_path('files/compressors/upx-win.exe')
            comp_dict['Windows32bit'] = get_data_file_path('files/compressors/upx-win.exe')

        plat = platform.system()+platform.architecture()[0]
        upx_version = comp_dict.get(plat, None)

        if upx_version is not None:
            upx_bin = upx_version
            os.chmod(upx_bin, 0755)
            cmd = [upx_bin, '--lzma', u'-{}'.format(compression.value), unicode(nw_path)]
            if platform.system() == 'Windows':
                startupinfo = subprocess.STARTUPINFO()
                startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
                startupinfo.wShowWindow = subprocess.SW_HIDE
                proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                        stderr=subprocess.PIPE,
                                        stdin=subprocess.PIPE,
                                        startupinfo=startupinfo)
            else:
                proc = subprocess.Popen(cmd, stdout=subprocess.PIPE,
                                    stderr=subprocess.PIPE,
                                    stdin=subprocess.PIPE)
            self.progress_text = '\n\n'
            self.progress_text = 'Compressing files'
            while proc.poll() is None:
                self.progress_text += '.'
                time.sleep(2)
            output, err = proc.communicate()
Exemple #8
0
    def load_last_project_path(self):
        proj_path = ''
        proj_file = get_data_file_path('files/last_project_path.txt')
        if os.path.exists(proj_file):
            with codecs.open(proj_file, encoding='utf-8') as f:
                proj_path = f.read().strip()

        if not proj_path:
            proj_path = QtCore.QDir.currentPath()

        return proj_path
Exemple #9
0
def test_get_versions(command_base):
    path = utils.get_data_file_path(config.VER_FILE)

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

    command_base.get_versions()

    with open(path, 'r') as ver_file:
        data = ver_file.read()
        assert len(data) > 0
Exemple #10
0
    def load_last_project_path(self):
        proj_path = ""
        proj_file = get_data_file_path("files/last_project_path.txt")
        if os.path.exists(proj_file):
            with codecs.open(proj_file, encoding="utf-8") as f:
                proj_path = f.read().strip()

        if not proj_path:
            proj_path = QtCore.QDir.currentPath()

        return proj_path
Exemple #11
0
 def load_recent_projects(self):
     files = []
     history_file = get_data_file_path("files/recent_files.txt")
     if not os.path.exists(history_file):
         return files
     with codecs.open(history_file, encoding="utf-8") as f:
         for line in f:
             line = line.strip()
             if line and os.path.exists(line):
                 files.append(line)
     files.reverse()
     return files
Exemple #12
0
 def load_recent_projects(self):
     files = []
     history_file = get_data_file_path('files/recent_files.txt')
     if not os.path.exists(history_file):
         return files
     with codecs.open(history_file, encoding='utf-8') as f:
         for line in f:
             line = line.strip()
             if line and os.path.exists(line):
                 files.append(line)
     files.reverse()
     return files
Exemple #13
0
 def save_recent_project(self, proj):
     recent_file_path = get_data_file_path("files/recent_files.txt")
     max_length = MAX_RECENT
     recent_files = []
     if os.path.exists(recent_file_path):
         recent_files = codecs.open(recent_file_path, encoding="utf-8").read().split(u"\n")
     try:
         recent_files.remove(proj)
     except ValueError:
         pass
     recent_files.append(proj)
     with codecs.open(recent_file_path, "w+", encoding="utf-8") as f:
         for recent_file in recent_files[-max_length:]:
             if recent_file and os.path.exists(recent_file):
                 f.write(u"{}\n".format(recent_file))
Exemple #14
0
 def save_recent_project(self, proj):
     recent_file_path = get_data_file_path('files/recent_files.txt')
     max_length = MAX_RECENT
     recent_files = []
     if os.path.exists(recent_file_path):
         recent_files = codecs.open(recent_file_path, encoding='utf-8').read().split(u'\n')
     try:
         recent_files.remove(proj)
     except ValueError:
         pass
     recent_files.append(proj)
     with codecs.open(recent_file_path, 'w+', encoding='utf-8') as f:
         for recent_file in recent_files[-max_length:]:
             if recent_file and os.path.exists(recent_file):
                 f.write(u'{}\n'.format(recent_file))
Exemple #15
0
RECENT_FILES_FILE = 'files/recent_files.txt'

NW_BRANCH_FILE = 'files/nw-branch.txt'

UPX_WIN_PATH = 'files/compressors/upx-win.exe'
UPX_MAC_PATH = 'files/compressors/upx-mac'
UPX_LIN32_PATH = 'files/compressors/upx-linux-x32'
UPX_LIN64_PATH = 'files/compressors/upx-linux-x64'

ENV_VARS_PY_PATH = 'files/env_vars.py'
ENV_VARS_BAT_PATH = 'files/env_vars.bat'
ENV_VARS_BASH_PATH = 'files/env_vars.bash'

## Logger setup ----------------------------------------------

LOG_FILENAME = utils.get_data_file_path(ERROR_LOG_FILE)

def getLogHandler():
    return lh.RotatingFileHandler(
        LOG_FILENAME,
        maxBytes=100000,
        backupCount=2,
        encoding='utf-8'
    )


if DEBUG:
    logging.basicConfig(
        format=("%(levelname) -10s %(asctime)s %(module)s.py: "
                "%(lineno)s %(funcName)s - %(message)s"),
        level=logging.DEBUG,
Exemple #16
0
RECENT_FILES_FILE = 'files/recent_files.txt'

NW_BRANCH_FILE = 'files/nw-branch.txt'

UPX_WIN_PATH = 'files/compressors/upx-win.exe'
UPX_MAC_PATH = 'files/compressors/upx-mac'
UPX_LIN32_PATH = 'files/compressors/upx-linux-x32'
UPX_LIN64_PATH = 'files/compressors/upx-linux-x64'

ENV_VARS_PY_PATH = 'files/env_vars.py'
ENV_VARS_BAT_PATH = 'files/env_vars.bat'
ENV_VARS_BASH_PATH = 'files/env_vars.bash'

## Logger setup ----------------------------------------------

LOG_FILENAME = utils.get_data_file_path(ERROR_LOG_FILE)

if DEBUG:
    logging.basicConfig(
        filename=LOG_FILENAME,
        format=("%(levelname) -10s %(asctime)s %(module)s.py: "
                "%(lineno)s %(funcName)s - %(message)s"),
        level=logging.DEBUG
    )
else:
    logging.basicConfig(
        filename=LOG_FILENAME,
        format=("%(levelname) -10s %(asctime)s %(module)s.py: "
                "%(lineno)s %(funcName)s - %(message)s"),
        level=logging.INFO
    )
Exemple #17
0
 def save_project_path(self, path):
     proj_file = get_data_file_path("files/last_project_path.txt")
     with codecs.open(proj_file, "w+", encoding="utf-8") as f:
         f.write(path)
Exemple #18
0
 def save_project_path(self, path):
     proj_file = get_data_file_path('files/last_project_path.txt')
     with codecs.open(proj_file, 'w+', encoding='utf-8') as f:
         f.write(path)
    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)
def get_file(path):
    parts = path.split('/')
    independent_path = utils.path_join(CWD, *parts)
    return independent_path

__version__ = "v0.0.0"

with open(get_file('files/version.txt')) as f:
    __version__ = f.read().strip()


TEMP_DIR = get_temp_dir()
DEFAULT_DOWNLOAD_PATH = get_data_path('files/downloads')

logger = logging.getLogger('W2E logger')
LOG_FILENAME = get_data_file_path('files/error.log')
if __name__ != '__main__':
    logging.basicConfig(
        filename=LOG_FILENAME,
        format=("%(levelname) -10s %(asctime)s %(module)s.py: "
                "%(lineno)s %(funcName)s - %(message)s"),
        level=logging.DEBUG
    )
    logger = logging.getLogger('W2E logger')

handler = lh.RotatingFileHandler(LOG_FILENAME, maxBytes=100000, backupCount=2)
logger.addHandler(handler)

def my_excepthook(type_, value, tback):
    output_err = u''.join([unicode(x) for x in traceback.format_exception(type_, value, tback)])
    logger.error(u'{}'.format(output_err))
 def delete_files(self):
     for ex_setting in self.settings['export_settings'].values():
         for dest_file in ex_setting.dest_files:
             f_path = get_data_file_path('files/{}/{}'.format(ex_setting.name, dest_file))
             if os.path.exists(f_path):
                 os.remove(f_path)
Exemple #22
0
 def save_project_path(self, path):
     proj_file = get_data_file_path('files/last_project_path.txt')
     with codecs.open(proj_file, 'w+', encoding='utf-8') as f:
         f.write(path)
    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)
Exemple #24
0
## Version Setting ----------------------------------------

__version__ = "v0.0.0"

with open(get_file('files/version.txt')) as f:
    __version__ = f.read().strip()


TEMP_DIR = utils.get_temp_dir()
DEFAULT_DOWNLOAD_PATH = utils.get_data_path('files/downloads')

## Logger setup ----------------------------------------------

logger = logging.getLogger('W2E logger')
LOG_FILENAME = utils.get_data_file_path('files/error.log')
if __name__ != '__main__':
    logging.basicConfig(
        filename=LOG_FILENAME,
        format=("%(levelname) -10s %(asctime)s %(module)s.py: "
                "%(lineno)s %(funcName)s - %(message)s"),
        level=logging.DEBUG
    )
    logger = logging.getLogger('W2E logger')

handler = lh.RotatingFileHandler(LOG_FILENAME, maxBytes=100000, backupCount=2)
logger.addHandler(handler)

## Custom except hook to log all errors ----------------------

def my_excepthook(type_, value, tback):