Esempio n. 1
0
 def find_module(self, fullname, path=None):
     # Python's default import implementation doesn't handle builtins with '.' in them well, so we handle them here
     # as well.
     # We allow freeze_overrides to give prefixes that although may be frozen we'll skip so they can be found in
     # the PYTHONPATH - this is good for development.
     if (not any(fullname.startswith(override) for override in freeze_overrides)) and \
        (imp.is_frozen('freezer_package.' + fullname) or imp.is_frozen('freezer.' + fullname) or
             (fullname.find('.') != -1 and imp.is_builtin(fullname))):
         return self
     else:
         return None
Esempio n. 2
0
def main_is_frozen():
    """Returns True if maijn function is frozen
    (e.g. PyInstaller/Py2Exe executable)
    """
    return (hasattr(sys, "frozen") or  # new py2exe
            hasattr(sys, "importers") or  # old py2exe
            imp.is_frozen("__main__"))  # tools/freeze
Esempio n. 3
0
def main_is_frozen():
    """Return True if we are running from an executable, False otherwise"""
    return (
        hasattr(sys, 'frozen') or  # new py2exe
        hasattr(sys, 'importers') or  # old py2exe
        imp.is_frozen('__main__')  # tools/freeze
    )
Esempio n. 4
0
    def loadUi(self, ui):
        """
        desc:
            Dynamically loads a UI file.
            
        arguments:
            ui:
                desc:   The name of a UI file, which should match.
                        libqnotero/ui/[name].ui
                type:   str
        """

        path = os.path.dirname(__file__)
        # If we are running from a frozen state (i.e. packaged by py2exe), we
        # need to find the UI files relative to the executable directory,
        # because the modules are packaged into library.zip.
        if os.name == 'nt':
            import imp
            import sys
            if (hasattr(sys, 'frozen') or hasattr(sys, 'importers') or \
                imp.is_frozen('__main__')):
                path = os.path.join(os.path.dirname(sys.executable),
                                    'libqnotero')
        uiPath = os.path.join(path, 'ui', '%s.ui' % ui)
        self.ui = uic.loadUi(uiPath, self)
Esempio n. 5
0
    def loadUi(self, ui):
        
        """
        desc:
            Dynamically loads a UI file.
            
        arguments:
            ui:
                desc:   The name of a UI file, which should match.
                        libqnotero/ui/[name].ui
                type:   str
        """

        path = os.path.dirname(__file__)
        # If we are running from a frozen state (i.e. packaged by py2exe), we
        # need to find the UI files relative to the executable directory,
        # because the modules are packaged into library.zip.
        if os.name == 'nt':
            import imp
            import sys
            if (hasattr(sys, 'frozen') or hasattr(sys, 'importers') or \
                imp.is_frozen('__main__')):
                path = os.path.join(os.path.dirname(sys.executable),
                    'libqnotero')
        uiPath = os.path.join(path, 'ui', '%s.ui' % ui)
        self.ui = uic.loadUi(uiPath, self)
Esempio n. 6
0
def get_main_dir():
    '''Returns the directory name of the script or the directory name of the exe if py2exe was used
    Code from http://www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
    '''
    if (hasattr(sys, "frozen") or hasattr(sys, "importers") or imp.is_frozen("__main__")):
        return os.path.dirname(sys.executable)
    return os.path.dirname(sys.argv[0])
Esempio n. 7
0
def main_is_frozen():
    """ main_is_frozen() -> bool
    Returns True when running the exe, or False when running from a script. 
    """
    return (hasattr(sys, "frozen") or # new py2exe
            hasattr(sys, "importers") # old py2exe
            or imp.is_frozen("__main__")) # tools/freeze
Esempio n. 8
0
def is_frozen():
    """ Check if application is frozen. """
    if __file__.startswith(sys.prefix):
        return True
    return (hasattr(sys, "frozen")      # new py2exe
            or hasattr(sys, "importers")        # old py2exe
            or imp.is_frozen("__main__"))       # tools/freeze
Esempio n. 9
0
def main_is_frozen():
    """
  Determine if the main script is frozen.
  """
    return (hasattr(sys, "frozen") or  # new py2exe
            hasattr(sys, "importers")  # old py2exe
            or imp.is_frozen("__main__"))  # tools/freeze
Esempio n. 10
0
 def find_builtin_module(self, name):
     if imp.is_builtin(name):
         return (None, '', ('', '', BUILTIN_MODULE))
     elif imp.is_frozen(name):
         return (None, '', ('', '', FROZEN_MODULE))
     else:
         return None
Esempio n. 11
0
def opensesame_folder():
    """
	Determines the folder that contains the OpenSesame executable. This is only
	applicable under Windows.

	Returns:
	The OpenSesame folder or None if the os is not Windows.
	"""

    if os.name != u'nt':
        return None
    # Determines the directory name of the script or the directory name
    # of the executable after being packaged with py2exe. This has to be
    # done so the child process can find all relevant modules too.
    # See http://www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
    #
    # There are two scenarios: Either OpenSesame is run from a frozen state,
    # in which case the OpenSesame folder is the folder containing the
    # executable, or OpenSesame is run from source, in which case we go to
    # the OpenSesame folder by going two levels up from the __file__ folder.
    import imp
    if (hasattr(sys, u'frozen') or hasattr(sys, u'importers') or \
     imp.is_frozen(u'__main__')):
        path = os.path.dirname(sys.executable).decode( \
         sys.getfilesystemencoding())
    else:
        # To get the opensesame folder, simply jump to levels up
        path = os.path.dirname(__file__).decode( \
         sys.getfilesystemencoding())
        path = os.path.normpath(os.path.join(path, u'..'))
    return path
Esempio n. 12
0
 def find_builtin_module(self, name):
     if imp.is_builtin(name):
         return (None, '', ('', '', BUILTIN_MODULE))
     else:
         if imp.is_frozen(name):
             return (None, '', ('', '', FROZEN_MODULE))
         return None
Esempio n. 13
0
def _load_static_data(filename):
    """Load a static file from the 'static' directory"""

    is_frozen = (hasattr(sys, 'frozen')  # new py2exe
                 or imp.is_frozen('__main__'))  # tools/freeze

    if is_frozen:
        if sys.platform.startswith("darwin"):
            path = os.path.join(os.path.dirname(sys.executable),
                                "../Resources",
                                STATIC_REL_PATH, filename)
        else:
            path = os.path.join(os.path.dirname(sys.executable),
                                STATIC_REL_PATH, filename)
        with open(path, 'rb') as f:
            data = f.read()
    else:
        try:
            from pkgutil import get_data as _get
        except ImportError:
            from pkg_resources import resource_string as _get

        data = _get(basepkgname, os.path.join(STATIC_REL_PATH, filename))

    if filename.endswith('.css'):
        s = data.decode('utf-8')
        s = fontfallback.css_replace_fontfamily(s)
        data = s.encode('utf-8')
    elif filename.endswith('.html'):
        s = data.decode('utf-8')
        s = s.replace('{% current_version %}', __version__)
        data = s.encode('utf-8')

    return data
Esempio n. 14
0
    def process_template(self, template_path, dest_filename):
        """
        Generates a file from a template.
        """
        domain_name_escaped = self.domain_name.replace(".", "\\.")
        template = pkg_resources.resource_string("reviewboard", template_path)
        sitedir = os.path.abspath(self.install_dir).replace("\\", "/")

        # Check if this is a .exe.
        if (hasattr(sys, "frozen") or    # new py2exe
            hasattr(sys, "importers") or # new py2exe
            imp.is_frozen("__main__")):  # tools/freeze
            rbsite_path = sys.executable
        else:
            rbsite_path = '"%s" "%s"' % (sys.executable, sys.argv[0])

        data = {
            'rbsite': rbsite_path,
            'sitedir': sitedir,
            'sitedomain': self.domain_name,
            'sitedomain_escaped': domain_name_escaped,
            'siteid': self.site_id,
        }

        template = re.sub("@([a-z_]+)@", lambda m: data.get(m.group(1)),
                          template)

        fp = open(dest_filename, "w")
        fp.write(template)
        fp.close()
Esempio n. 15
0
def get_exe_dir():
    import imp, sys
    if (getattr(sys, "frozen", False) or # new py2exe
            hasattr(sys, "importers") # old py2exe
            or imp.is_frozen("__main__")): # tools/freeze
        return os.path.dirname(sys.executable)
    return None
Esempio n. 16
0
def _load_static_data(filename):
    """Load a static file from the 'static' directory"""

    is_frozen = (
        hasattr(sys, 'frozen')  # new py2exe
        or imp.is_frozen('__main__'))  # tools/freeze

    if is_frozen:
        if sys.platform.startswith("darwin"):
            path = os.path.join(os.path.dirname(sys.executable),
                                "../Resources", STATIC_REL_PATH, filename)
        else:
            path = os.path.join(os.path.dirname(sys.executable),
                                STATIC_REL_PATH, filename)
        with open(path, 'rb') as f:
            data = f.read()
    else:
        try:
            from pkgutil import get_data as _get
        except ImportError:
            from pkg_resources import resource_string as _get

        data = _get(basepkgname, os.path.join(STATIC_REL_PATH, filename))

    if filename.endswith('.css'):
        s = data.decode('utf-8')
        s = fontfallback.css_replace_fontfamily(s)
        data = s.encode('utf-8')
    elif filename.endswith('.html'):
        s = data.decode('utf-8')
        s = s.replace('{% current_version %}', __version__)
        data = s.encode('utf-8')

    return data
Esempio n. 17
0
 def find_builtin_module(self, name):
     # XXX frozen packages?
     if imp.is_builtin(name):
         return None, '', ('', '', BUILTIN_MODULE)
     if imp.is_frozen(name):
         return None, '', ('', '', FROZEN_MODULE)
     return None
Esempio n. 18
0
def main_is_frozen():
    """ Return T if running from an exe, F otherwise
    """
    return (hasattr(sys, "frozen")  # new py2exe
            or hasattr(sys, "importers")  # old py2exe
            or imp.is_frozen("__main__")  # tools/freeze
            or os.path.isfile(sys.path[0]))  # cxfreeze
def main_is_frozen():
    """ Return T if running from an exe, F otherwise
    """
    return (hasattr(sys, "frozen")  # new py2exe
           or hasattr(sys, "importers") # old py2exe
           or imp.is_frozen("__main__") # tools/freeze
            or os.path.isfile(sys.path[0])) # cxfreeze
Esempio n. 20
0
def main_is_frozen():
	"Return True if it runs from a frozen script (py2exe, cx_Freeze...)"
	return (
		hasattr(sys, "frozen") or    # new py2exe
		hasattr(sys, "importers") or # old py2exe
		imp.is_frozen("__main__")    # tools/freeze
	)
Esempio n. 21
0
 def find_builtin_module(self, name):
     # XXX frozen packages?
     if imp.is_builtin(name):
         return None, '', ('', '', BUILTIN_MODULE)
     if imp.is_frozen(name):
         return None, '', ('', '', FROZEN_MODULE)
     return None
Esempio n. 22
0
def run_as_app():
    """ returns True when running the exe, and False when running from a script. -> boolean
    """
    import imp, sys
    return (hasattr(sys, "frozen") or  # new py2exe
            hasattr(sys, "importers")  # old py2exe
            or imp.is_frozen("__main__"))  # tools/freeze
Esempio n. 23
0
def run_as_app():
    """ returns True when running the exe, and False when running from a script. -> boolean
    """
    import imp, sys
    return (hasattr(sys, "frozen") or # new py2exe
        hasattr(sys, "importers") # old py2exe
            or imp.is_frozen("__main__") ) # tools/freeze
Esempio n. 24
0
def mainIsFrozen():
    '''
        Returns True if running from .exe
    '''
    return (hasattr(sys, "frozen") or # new py2exe
            hasattr(sys, "importers") # old py2exe
            or imp.is_frozen("__main__")) # tools/freeze
Esempio n. 25
0
def opensesame_folder():

	"""
	Determines the folder that contains the OpenSesame executable. This is only
	applicable under Windows.

	Returns:
	The OpenSesame folder or None if the os is not Windows.
	"""
	# Determines the directory name of the script or the directory name
	# of the executable after being packaged with py2exe. This has to be
	# done so the child process can find all relevant modules too.
	# See http://www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
	#
	# There are two scenarios: Either OpenSesame is run from a frozen state,
	# in which case the OpenSesame folder is the folder containing the
	# executable, or OpenSesame is run from source, in which case we go to
	# the OpenSesame folder by going two levels up from the __file__ folder.
	if platform.system() == u'Darwin':
		return os.getcwd()
	elif platform.system() == u'Windows':
		import imp
		if (hasattr(sys, u'frozen') or hasattr(sys, u'importers') or \
			imp.is_frozen(u'__main__')):
			path = safe_decode(os.path.dirname(sys.executable),
				enc=sys.getfilesystemencoding())
		else:
			# To get the opensesame folder, simply jump to levels up
			path = safe_decode(os.path.dirname(__file__),
				enc=sys.getfilesystemencoding())
			path = os.path.normpath(os.path.join(path, u'..'))
		return path
	else:
		return None
Esempio n. 26
0
def vfp_sys(funcnum, *args):
    if funcnum == 16:
        import imp
        if hasattr(sys, "frozen") or hasattr(
                sys, "importers") or imp.is_frozen("__main__"):
            return os.path.dirname(sys.executable)
        return os.path.dirname(sys.argv[0])
Esempio n. 27
0
def main_is_frozen():
    """
	Checks if the application is "frozen", ie. packaged with py2exe for windows, py2app for mac or freeze for linux.
	"""
    return (hasattr(sys, "frozen") or  # new py2exe
            hasattr(sys, "importers")  # old py2exe
            or imp.is_frozen("__main__"))  # tools/freeze
def main_is_frozen():
	"""
	Checks if the application is "frozen", ie. packaged with py2exe for windows, py2app for mac or freeze for linux.
	"""
	return (hasattr(sys, "frozen") or # new py2exe
			hasattr(sys, "importers") # old py2exe
			or imp.is_frozen("__main__")) # tools/freeze
Esempio n. 29
0
def get_program_path():
    if hasattr(sys, "frozen") or imp.is_frozen("__main__"):
        return os.path.dirname(sys.executable)
    else:
        try:
            return os.path.dirname(__file__)
        except NameError:
            return os.path.dirname(sys.argv[0])
Esempio n. 30
0
def main_is_frozen():
    """
    Return True if we are running in a py2exe environment, else
    return False
    """
    return (hasattr(sys, "frozen") or  # new py2exe
            hasattr(sys, "importers") or  # old py2exe
            imp.is_frozen("__main__"))  # tools/freeze
Esempio n. 31
0
def main_is_frozen():
    """
    Return True if DataHaven.NET is started from .exe not from sources.
        http://www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
    """
    return (hasattr(sys, "frozen") or       # new py2exe
            hasattr(sys, "importers") or    # old py2exe
            imp.is_frozen("__main__"))      # tools/freeze
def main_is_frozen():
    """
    Return True if we are running in a py2exe environment, else
    return False
    """
    return (hasattr(sys, "frozen") or # new py2exe
            hasattr(sys, "importers") or # old py2exe
            imp.is_frozen("__main__")) # tools/freeze
Esempio n. 33
0
def get_main_dir():
    '''Returns the directory name of the script or the directory name of the exe if py2exe was used
    Code from http://www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
    '''
    if (hasattr(sys, "frozen") or hasattr(sys, "importers")
            or imp.is_frozen("__main__")):
        return os.path.dirname(sys.executable)
    return os.path.dirname(sys.argv[0])
Esempio n. 34
0
 def _isFrozen(self):
     """
     This should return true if the program that is being run is a compiled
     exe
     """
     return (hasattr(sys, "frozen") # new py2exe
             or hasattr(sys, "importers") # old py2exe
             or imp.is_frozen("__main__")) # tools/freeze
def main_is_frozen():
    """Return ``True`` if we're running from a frozen program."""
    import imp
    return (
        # new py2exe
        hasattr(sys, "frozen") or
        # tools/freeze
        imp.is_frozen("__main__"))
Esempio n. 36
0
def main_is_frozen():
    if sys.platform == 'darwin':
        # this is a temporary hack for bundlebuilder
        return not sys.executable == '/System/Library/Frameworks/Python.framework/Versions/2.3/Resources/Python.app/Contents/MacOS/Python'
    else:
        return (hasattr(sys, "frozen") or # new py2exe, McMillan
                hasattr(sys, "importers") # old py2exe
                or imp.is_frozen("__main__")) # tools/freeze, cx_freeze
Esempio n. 37
0
def get_program_path():
    if hasattr(sys, "frozen") or imp.is_frozen("__main__"):
        return os.path.dirname(sys.executable)
    else:
        try:
            return os.path.dirname(__file__)
        except NameError:
            return os.path.dirname(sys.argv[0])
Esempio n. 38
0
def main_is_frozen():
    """Return ``True`` if we're running from a frozen program."""
    import imp
    return (
        # new py2exe
        hasattr(sys, "frozen") or
        # tools/freeze
        imp.is_frozen("__main__"))
Esempio n. 39
0
def pasta_is_frozen():
    """Will return True if PASTA is frozen.
    """
    import imp
    return (hasattr(sys, "frozen")  # new py2exe
            or hasattr(sys, "importers")  # old py2exe
            or imp.is_frozen("__main__")  # tools/freeze
            )
def isExe ():
    """
    Indicates whether the execution is exe with py2exe or. py with the Python interpreter

    @return:
    @rtype: boolean
    """
    return imp.is_frozen("__main__") # cx_freeze
Esempio n. 41
0
def main_is_frozen():
    """detect if the script is running from frozen
    distribution. i.e: from a py2exe build or others
    """
    import imp
    return (hasattr(sys, "frozen") or # new py2exe
        hasattr(sys, "importers") or # old py2exe
        imp.is_frozen("__main__")) # tools/freeze
Esempio n. 42
0
def main_is_frozen():
    """
    执行环境判断
    :return:
    """
    return (hasattr(sys, "frozen") or       # new py2exe
            hasattr(sys, "importers") or    # old py2exe
            imp.is_frozen("__main__"))      # tools/freeze
def main_is_frozen():

    """ Return T if running from an exe, F otherwise
    """

    return (hasattr(sys, "frozen")  
           or hasattr(sys, "importers") 
           or imp.is_frozen("__main__") 
            or os.path.isfile(sys.path[0]))
Esempio n. 44
0
def sate_is_frozen():
    """Will return True if SATe is frozen.
    """
    import imp
    return (
        hasattr(sys, "frozen")          # new py2exe
        or hasattr(sys, "importers")    # old py2exe
        or imp.is_frozen("__main__")    # tools/freeze
    )
Esempio n. 45
0
def main_is_frozen():
    """
    Return True if BitDust is started from .exe not from sources.

    http://www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
    """
    return (hasattr(sys, "frozen") or       # new py2exe
            hasattr(sys, "importers") or    # old py2exe
            imp.is_frozen("__main__"))      # tools/freeze
Esempio n. 46
0
def main_is_frozen():
    """
    To determine whether the script is launched from the interpreter or if it
    is an executable compiled with py2exe.
    See http://www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
    """
    return (hasattr(sys, "frozen")  # new py2exe
            or hasattr(sys, "importers")  # old py2exe
            or imp.is_frozen("__main__"))  # tools/freeze
Esempio n. 47
0
def mainfrozen():
    """return True if we are a frozen executable.

    The code supports py2exe (most common, Windows only) and tools/freeze
    (portable, not much used).
    """
    return (pycompat.safehasattr(sys, "frozen") or  # new py2exe
            pycompat.safehasattr(sys, "importers") or  # old py2exe
            imp.is_frozen(u"__main__"))  # tools/freeze
Esempio n. 48
0
def main_is_frozen():
    """return True if we are a frozen executable.

    The code supports py2exe (most common, Windows only) and tools/freeze
    (portable, not much used).
    """
    return (hasattr(sys, "frozen") or # new py2exe
            hasattr(sys, "importers") or # old py2exe
            imp.is_frozen("__main__")) # tools/freeze
Esempio n. 49
0
def main_is_frozen():
    """
    To determine whether the script is launched from the interpreter or if it
    is an executable compiled with py2exe.
    See http://www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
    """
    return (hasattr(sys, "frozen") # new py2exe
        or hasattr(sys, "importers") # old py2exe
        or imp.is_frozen("__main__")) # tools/freeze
Esempio n. 50
0
def main_is_frozen():
    """
    Returns True/False if Bauble is being run from a py2exe
    executable.  This method duplicates bauble.main_is_frozen in order
    to make paths.py not depend on any other Bauble modules.
    """
    import imp
    return (hasattr(sys, "frozen") or  # new py2exe
            hasattr(sys, "importers") or  # old py2exe
            imp.is_frozen("__main__"))  # tools/freeze
Esempio n. 51
0
def is_frozen_main():
    """Freeze detection Bool

    From www.py2exe.org/index.cgi/HowToDetermineIfRunningFromExe
    ThomasHeller posted to the py2exe mailing list
    :return: bool
    """
    return (hasattr(sys, "frozen") or  # new py2exe
            hasattr(sys, "importers")  # old py2exe
            or is_frozen("__main__"))  # tools/freeze
Esempio n. 52
0
def main_is_frozen():
    """
    Returns True/False if Ghini is being run from a py2exe
    executable.  This method duplicates bauble.main_is_frozen in order
    to make paths.py not depend on any other Ghini modules.
    """
    import imp
    return (hasattr(sys, "frozen") or  # new py2exe
            hasattr(sys, "importers") or  # old py2exe
            imp.is_frozen("__main__"))  # tools/freeze
Esempio n. 53
0
def get_program_path():
    if hasattr(sys, "frozen") or imp.is_frozen("__main__"):
        return os.path.dirname(sys.executable)
    else:
        try:
            # normally, we're in ./overviewer_core/util.py
            # we want ./
            return os.path.dirname(os.path.dirname(__file__))
        except NameError:
            return os.path.dirname(sys.argv[0])
def get_program_path():
    if hasattr(sys, "frozen") or imp.is_frozen("__main__"):
        return os.path.dirname(sys.executable)
    else:
        try:
            # normally, we're in ./overviewer_core/util.py
            # we want ./
            return os.path.dirname(os.path.dirname(__file__))
        except NameError:
            return os.path.dirname(sys.argv[0])
Esempio n. 55
0
def app_is_frozen():
    """
    Checks if the app is stadalone

    @return: True / False
    @rtype: bool
    """
    return (hasattr(sys, "frozen") or  # new py2exe
            hasattr(sys, "importers")  # old py2exe
            or imp.is_frozen("__main__"))  # tools/freeze
Esempio n. 56
0
def program_dir():
    """
    This gets the full pathname of the directory containing the program.
    It is used for referring to other files (binaries, images, etc.).
    """
    if (Win32() and (hasattr(sys, 'frozen') or imp.is_frozen('__main__'))):
        # running from exe generated by py2exe
        return os.path.dirname(sys.executable)
    else:
        return sys.path[0]
Esempio n. 57
0
    def find_module(self, fullname, path=None):
        """Return mpiloader if 'fullname' is in sys.path (and isn't a builtin or
        frozen module)."""

        # Don't override builtin/frozen modules. TODO: Windows registry?
        if (fullname not in sys.builtin_module_names
                and not imp.is_frozen(fullname) and fullname in self._cache):

            return self
        return None