sys.frozen

Here are the examples of the python api sys.frozen taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

95 Examples 7

Example 1

Project: odoo
Source File: utils.py
View license
def get_resource_path():
    try:
        if sys.frozen:
            path = _call_dir
            path = os.path.join(path, "resources", "faces", "gui")
        else:
            raise AttributeError()
    except AttributeError:
        path = get_installation_path()
        path = os.path.join(path, "gui", "resources")

    path = os.path.normcase(path)
    return path

Example 2

Project: comtypes
Source File: test_findgendir.py
View license
    def test_frozen_console_exe(self):
        sys.frozen = "console_exe"
        # %TEMP%\comtypes_cache\<imagebasename>-25
        path = os.path.join(tempfile.gettempdir(),
                            r"comtypes_cache\%s-%d%d" % (
            imgbase, sys.version_info[0], sys.version_info[1]))
        gen_dir = comtypes.client._find_gen_dir()
        self.failUnlessEqual(path, gen_dir)

Example 3

Project: FixZeroHandles
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys #, site
	sys.frozen = 'macosx_plugin'
	base = os.environ[ 'RESOURCEPATH' ]
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join( base, script )
		__file__ = path
		execfile( path, globals(), globals() )

Example 4

Project: ShowAngledHandles
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys# , site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 5

Project: GlyphsPlugins
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys# , site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 6

Project: MakerDroid
Source File: threading.py
View license
def is_multiprocessing_available():
    if (pycam.Utils.get_platform() == pycam.Utils.PLATFORM_WINDOWS) and \
            hasattr(sys, "frozen") and sys.frozen:
        return False
    try:
        import multiprocessing
        return True
    except ImportError:
        return False

Example 7

Project: BubbleKern
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys# , site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 8

Project: comtypes
Source File: test_findgendir.py
View license
    def test_frozen_dll(self):
        sys.frozen = "dll"
        sys.frozendllhandle = sys.dllhandle
        ma, mi = sys.version_info[:2]
        # %TEMP%\comtypes_cache\<imagebasename>-25
        # the image is python25.dll
        path = os.path.join(tempfile.gettempdir(),
                            r"comtypes_cache\%s%d%d-%d%d" % (imgbase, ma, mi, ma, mi))
        gen_dir = comtypes.client._find_gen_dir()
        self.failUnlessEqual(path, gen_dir)

Example 9

Project: robothon
Source File: __boot__.py
View license
def _run(*scripts):
    global __file__
    import os, sys, site
    sys.frozen = 'macosx_app'
    base = os.environ['RESOURCEPATH']
    site.addsitedir(base)
    site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
    if not scripts:
        import __main__
    for script in scripts:
        path = os.path.join(base, script)
        sys.argv[0] = __file__ = path
        execfile(path, globals(), globals())

Example 10

Project: freemix-glyphsapp
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys# , site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 11

Project: cgstudiomap
Source File: utils.py
View license
def get_template_path():
    try:
        if sys.frozen:
            path = _call_dir
            path = os.path.join(path, "resources", "faces", "templates")
        else:
            raise AttributeError()
    except AttributeError:
        path = get_installation_path()
        path = os.path.join(path, "templates")
        
    path = os.path.normcase(path)
    return path

Example 12

Project: Kernkraft
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys #, site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 13

Project: ShowAngledHandles
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys# , site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 14

Project: odoo
Source File: plocale.py
View license
def _get_translation():
    try:
        return gettext.translation("faces")
    except:
        try:
            if sys.frozen:
                path = os.path.dirname(sys.argv[0])
                path = os.path.join(path, "resources", "faces", "locale")
            else:
                path = os.path.split(__file__)[0]
                path = os.path.join(path, "locale")

            return gettext.translation("faces", path)
        except Exception, e:
            return None

Example 15

Project: Noodler
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys #, site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 16

Project: odoo
Source File: utils.py
View license
def get_howtos_path():
    try:
        if sys.frozen:
            path = _call_dir
        else:
            raise AttributeError()
    except AttributeError:
        path = get_installation_path()

    path = os.path.join(path, "howtos")
    path = os.path.normcase(path)
    return path

Example 17

Project: InsertInflections
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys #, site
	sys.frozen = 'macosx_plugin'
	base = os.environ[ 'RESOURCEPATH' ]
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join( base, script )
		__file__ = path
		execfile( path, globals(), globals() )

Example 18

Project: FixZeroHandles
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys #, site
	sys.frozen = 'macosx_plugin'
	base = os.environ[ 'RESOURCEPATH' ]
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join( base, script )
		__file__ = path
		execfile( path, globals(), globals() )

Example 19

Project: comtypes
Source File: test_findgendir.py
View license
    def test_frozen_windows_exe(self):
        sys.frozen = "windows_exe"
        # %TEMP%\comtypes_cache\<imagebasename>-25
        path = os.path.join(tempfile.gettempdir(),
                            r"comtypes_cache\%s-%d%d" % (
            imgbase, sys.version_info[0], sys.version_info[1]))
        gen_dir = comtypes.client._find_gen_dir()
        self.failUnlessEqual(path, gen_dir)

Example 20

Project: GlyphsPlugins
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys #, site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 21

Project: EDMarketConnector
Source File: update.py
View license
        def __init__(self, master):
            try:
                sys.frozen	# don't want to try updating python.exe
                self.updater = ctypes.cdll.WinSparkle
                self.updater.win_sparkle_set_appcast_url(update_feed)	# py2exe won't let us embed this in resources

                # set up shutdown callback
                global root
                root = master
                self.callback_t = ctypes.CFUNCTYPE(None)	# keep reference
                self.callback_fn = self.callback_t(shutdown_request)
                self.updater.win_sparkle_set_shutdown_request_callback(self.callback_fn)

                self.updater.win_sparkle_init()

            except:
                from traceback import print_exc
                print_exc()
                self.updater = None

Example 22

Project: MongoApp
Source File: __boot__.py
View license
def _run():
    global __file__
    import os, sys, site
    sys.frozen = 'macosx_app'
    base = os.environ['RESOURCEPATH']

    argv0 = os.path.basename(os.environ['ARGVZERO'])
    script = SCRIPT_MAP.get(argv0, DEFAULT_SCRIPT)

    path = os.path.join(base, script)
    sys.argv[0] = __file__ = path
    with open(path, 'rU') as fp:
        source = fp.read() + "\n"
    exec(compile(source, path, 'exec'), globals(), globals())

Example 23

Project: EDMarketConnector
Source File: update.py
View license
        def __init__(self, master):
            try:
                sys.frozen	# don't want to try updating python.exe
                self.updater = ctypes.cdll.WinSparkle
                self.updater.win_sparkle_set_appcast_url(update_feed)	# py2exe won't let us embed this in resources

                # set up shutdown callback
                global root
                root = master
                self.callback_t = ctypes.CFUNCTYPE(None)	# keep reference
                self.callback_fn = self.callback_t(shutdown_request)
                self.updater.win_sparkle_set_shutdown_request_callback(self.callback_fn)

                self.updater.win_sparkle_init()

            except:
                from traceback import print_exc
                print_exc()
                self.updater = None

Example 24

Project: geofront-cli
Source File: test_utils.py
View license
    def setUp(self):
        """SetUp to mimic frozen darwin."""
        super(DarwinPkgdTestCase, self).setUp()
        self.patch(sys, "platform", "darwin")
        sys.frozen = True

        self.darwin_app_names = {"foo": "Foo.app"}

Example 25

Project: pyafipws
Source File: utils.py
View license
def get_install_dir():
    if not hasattr(sys, "frozen"): 
        basepath = __file__
    elif sys.frozen=='dll':
        import win32api
        basepath = win32api.GetModuleFileName(sys.frozendllhandle)
    else:
        basepath = sys.executable

    if hasattr(sys, "frozen"): 
        # we are running as py2exe-packed executable
        import pythoncom
        pythoncom.frozen = 1
        sys.argv[0] = sys.executable

    return os.path.dirname(os.path.abspath(basepath))

Example 26

Project: cgstudiomap
Source File: utils.py
View license
def get_resource_path():
    try:
        if sys.frozen:
            path = _call_dir
            path = os.path.join(path, "resources", "faces", "gui")
        else:
            raise AttributeError()
    except AttributeError:
        path = get_installation_path()
        path = os.path.join(path, "gui", "resources")

    path = os.path.normcase(path)
    return path

Example 27

Project: cgstudiomap
Source File: plocale.py
View license
def _get_translation():
    try:
        return gettext.translation("faces")
    except:
        try:
            if sys.frozen:
                path = os.path.dirname(sys.argv[0])
                path = os.path.join(path, "resources", "faces", "locale")
            else:
                path = os.path.split(__file__)[0]
                path = os.path.join(path, "locale")

            return gettext.translation("faces", path)
        except Exception, e:
            return None

Example 28

Project: ShowAngledHandles
Source File: __boot__.py
View license
def _run(*scripts):
    global __file__
    import os, sys #, site
    sys.frozen = 'macosx_plugin'
    base = os.environ['RESOURCEPATH']
    # site.addsitedir(base)
    # site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
    for script in scripts:
        path = os.path.join(base, script)
        __file__ = path
        execfile( path, globals(), globals() )

Example 29

Project: cgstudiomap
Source File: utils.py
View license
def get_howtos_path():
    try:
        if sys.frozen:
            path = _call_dir
        else:
            raise AttributeError()
    except AttributeError:
        path = get_installation_path()

    path = os.path.join(path, "howtos")
    path = os.path.normcase(path)
    return path

Example 30

Project: ShowAngledHandles
Source File: __boot__.py
View license
def _run(*scripts):
    global __file__
    import os, sys #, site
    sys.frozen = 'macosx_plugin'
    base = os.environ['RESOURCEPATH']
    # site.addsitedir(base)
    # site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
    for script in scripts:
        path = os.path.join(base, script)
        __file__ = path
        execfile( path, globals(), globals() )

Example 31

Project: nvpy
Source File: nvpy.py
View license
def main():
    # setup appdir
    if hasattr(sys, 'frozen') and sys.frozen:
        appdir, _ = os.path.split(sys.executable)

    else:
        dirname, _ = os.path.split(os.path.realpath(__file__))
        if dirname and dirname != os.curdir:
            appdir = dirname
        else:
            appdir = os.getcwd()

    # make sure it's the full path
    appdir_full_path = os.path.abspath(appdir)

    config = Config(appdir_full_path)

    controller = Controller(config)
    controller.main_loop()

Example 32

Project: GlyphsPlugins
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys #, site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 33

Project: odoo
Source File: utils.py
View license
def get_installation_path():
    try:
        if sys.frozen:
            path = _call_dir
        else:
            raise AttributeError()
    except AttributeError:
        path = os.path.abspath(observer.__file__)
        path = os.path.split(path)[0]
        
    path = os.path.normcase(path)
    return path

Example 34

Project: freemix-glyphsapp
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys# , site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 35

Project: odoo
Source File: utils.py
View license
def get_template_path():
    try:
        if sys.frozen:
            path = _call_dir
            path = os.path.join(path, "resources", "faces", "templates")
        else:
            raise AttributeError()
    except AttributeError:
        path = get_installation_path()
        path = os.path.join(path, "templates")
        
    path = os.path.normcase(path)
    return path

Example 36

Project: MakerDroid
Source File: threading.py
View license
def is_server_mode_available():
    # the following definition should be kept in sync with the wiki:
    # http://sf.net/apps/mediawiki/pycam/?title=Parallel_Processing_on_different_Platforms
    if pycam.Utils.get_platform() == pycam.Utils.PLATFORM_WINDOWS:
        if hasattr(sys, "frozen") and sys.frozen:
            return False
        else:
            return True
    else:
        try:
            import multiprocessing
            return True
        except ImportError:
            return False

Example 37

Project: GlyphsPlugins
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys# , site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 38

Project: InsertInflections
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys #, site
	sys.frozen = 'macosx_plugin'
	base = os.environ[ 'RESOURCEPATH' ]
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join( base, script )
		__file__ = path
		execfile( path, globals(), globals() )

Example 39

Project: GlyphsPlugins
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys# , site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 40

Project: Noodler
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys #, site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 41

Project: BroadNibber
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys #, site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 42

Project: GaugeTool
Source File: __boot__.py
View license
def _run(*scripts):
	global __file__
	import os, sys #, site
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	# site.addsitedir(base)
	# site.addsitedir(os.path.join(base, 'Python', 'site-packages'))
	for script in scripts:
		path = os.path.join(base, script)
		__file__ = path
		execfile(path, globals(), globals())

Example 43

Project: DrawBotGlyphsPlugin
Source File: __boot__.py
View license
def _run(script):
	global __file__
	import os, sys
	sys.frozen = 'macosx_plugin'
	base = os.environ['RESOURCEPATH']
	path = os.path.join(base, script)
	__file__ = path
	execfile(path, globals(), globals())

Example 44

Project: cgstudiomap
Source File: utils.py
View license
def get_installation_path():
    try:
        if sys.frozen:
            path = _call_dir
        else:
            raise AttributeError()
    except AttributeError:
        path = os.path.abspath(observer.__file__)
        path = os.path.split(path)[0]
        
    path = os.path.normcase(path)
    return path

Example 45

Project: WAPT
Source File: register.py
View license
def RegisterServer(clsid, 
                   pythonInstString=None, 
                   desc=None,
                   progID=None, verProgID=None,
                   defIcon=None,
                   threadingModel="both",
                   policy=None,
                   catids=[], other={},
                   addPyComCat=None,
                   dispatcher = None,
                   clsctx = None,
                   addnPath = None,
                  ):
  """Registers a Python object as a COM Server.  This enters almost all necessary
     information in the system registry, allowing COM to use the object.

     clsid -- The (unique) CLSID of the server.
     pythonInstString -- A string holding the instance name that will be created
                   whenever COM requests a new object.
     desc -- The description of the COM object.
     progID -- The user name of this object (eg, Word.Document)
     verProgId -- The user name of this version's implementation (eg Word.6.Document)
     defIcon -- The default icon for the object.
     threadingModel -- The threading model this object supports.
     policy -- The policy to use when creating this object.
     catids -- A list of category ID's this object belongs in.
     other -- A dictionary of extra items to be registered.
     addPyComCat -- A flag indicating if the object should be added to the list
              of Python servers installed on the machine.  If None (the default)
              then it will be registered when running from python source, but
              not registered if running in a frozen environment.
     dispatcher -- The dispatcher to use when creating this object.
     clsctx -- One of the CLSCTX_* constants.
     addnPath -- An additional path the COM framework will add to sys.path
                 before attempting to create the object.
  """


  ### backwards-compat check
  ### Certain policies do not require a "class name", just the policy itself.
  if not pythonInstString and not policy:
    raise TypeError('You must specify either the Python Class or Python Policy which implement the COM object.')

  keyNameRoot = "CLSID\\%s" % str(clsid)
  _set_string(keyNameRoot, desc)

  # Also register as an "Application" so DCOM etc all see us.
  _set_string("AppID\\%s" % clsid, progID)
  # Depending on contexts requested, register the specified server type.
  # Set default clsctx.
  if not clsctx:
    clsctx = pythoncom.CLSCTX_INPROC_SERVER | pythoncom.CLSCTX_LOCAL_SERVER
  # And if we are frozen, ignore the ones that don't make sense in this
  # context.
  if pythoncom.frozen:
    assert sys.frozen, "pythoncom is frozen, but sys.frozen is not set - don't know the context!"
    if sys.frozen == "dll":
      clsctx = clsctx & pythoncom.CLSCTX_INPROC_SERVER
    else:
      clsctx = clsctx & pythoncom.CLSCTX_LOCAL_SERVER
  # Now setup based on the clsctx left over.
  if clsctx & pythoncom.CLSCTX_INPROC_SERVER:
    # get the module to use for registration.
    # nod to Gordon's installer - if sys.frozen and sys.frozendllhandle
    # exist, then we are being registered via a DLL - use this DLL as the
    # file name.
    if pythoncom.frozen:
      if hasattr(sys, "frozendllhandle"):
        dllName = win32api.GetModuleFileName(sys.frozendllhandle)
      else:
        raise RuntimeError("We appear to have a frozen DLL, but I don't know the DLL to use")
    else:
      # Normal case - running from .py file, so register pythoncom's DLL.
      # Although now we prefer a 'loader' DLL if it exists to avoid some
      # manifest issues (the 'loader' DLL has a manifest, but pythoncom does not)
      pythoncom_dir = os.path.dirname(pythoncom.__file__)
      if pythoncom.__file__.find("_d") < 0:
        suffix = ""
      else:
        suffix = "_d"
      loadername = "pythoncomloader%d%d%s.dll" % (sys.version_info[0], sys.version_info[1], suffix)
      if os.path.isfile(os.path.join(pythoncom_dir, loadername)):
        dllName = loadername
      else:
        # just use pythoncom.
        dllName = os.path.basename(pythoncom.__file__)

    _set_subkeys(keyNameRoot + "\\InprocServer32",
                 { None : dllName,
                   "ThreadingModel" : threadingModel,
                   })
  else: # Remove any old InProcServer32 registrations
    _remove_key(keyNameRoot + "\\InprocServer32")

  if clsctx & pythoncom.CLSCTX_LOCAL_SERVER:
    if pythoncom.frozen:
      # If we are frozen, we write "{exe} /Automate", just
      # like "normal" .EXEs do
      exeName = win32api.GetShortPathName(sys.executable)
      command = '%s /Automate' % (exeName,)
    else:
      # Running from .py sources - we need to write
      # 'python.exe win32com\server\localserver.py {clsid}"
      exeName = _find_localserver_exe(1)
      exeName = win32api.GetShortPathName(exeName)
      pyfile = _find_localserver_module()
      command = '%s "%s" %s' % (exeName, pyfile, str(clsid))
    _set_string(keyNameRoot + '\\LocalServer32', command)
  else: # Remove any old LocalServer32 registrations
    _remove_key(keyNameRoot + "\\LocalServer32")

  if pythonInstString:
    _set_string(keyNameRoot + '\\PythonCOM', pythonInstString)
  else:
    _remove_key(keyNameRoot + '\\PythonCOM')
  if policy:
    _set_string(keyNameRoot + '\\PythonCOMPolicy', policy)
  else:
    _remove_key(keyNameRoot + '\\PythonCOMPolicy')

  if dispatcher:
    _set_string(keyNameRoot + '\\PythonCOMDispatcher', dispatcher)
  else:
    _remove_key(keyNameRoot + '\\PythonCOMDispatcher')

  if defIcon:
    _set_string(keyNameRoot + '\\DefaultIcon', defIcon)
  else:
    _remove_key(keyNameRoot + '\\DefaultIcon')

  if addnPath:
    _set_string(keyNameRoot + "\\PythonCOMPath", addnPath)
  else:
    _remove_key(keyNameRoot + "\\PythonCOMPath")

  if addPyComCat is None:
    addPyComCat = pythoncom.frozen == 0
  if addPyComCat:
    catids = catids + [ CATID_PythonCOMServer ]

  # Set up the implemented categories
  if catids:
    regCat = _cat_registrar()
    regCat.RegisterClassImplCategories(clsid, catids)

  # set up any other reg values they might have
  if other:
    for key, value in other.iteritems():
      _set_string(keyNameRoot + '\\' + key, value)

  if progID:
    # set the progID as the most specific that was given to us
    if verProgID:
      _set_string(keyNameRoot + '\\ProgID', verProgID)
    else:
      _set_string(keyNameRoot + '\\ProgID', progID)

    # Set up the root entries - version independent.
    if desc:
      _set_string(progID, desc)
    _set_string(progID + '\\CLSID', str(clsid))

    # Set up the root entries - version dependent.
    if verProgID:
      # point from independent to the current version
      _set_string(progID + '\\CurVer', verProgID)

      # point to the version-independent one
      _set_string(keyNameRoot + '\\VersionIndependentProgID', progID)

      # set up the versioned progID
      if desc:
        _set_string(verProgID, desc)
      _set_string(verProgID + '\\CLSID', str(clsid))

Example 46

Project: TrustRouter
Source File: register.py
View license
def RegisterServer(clsid, 
                   pythonInstString=None, 
                   desc=None,
                   progID=None, verProgID=None,
                   defIcon=None,
                   threadingModel="both",
                   policy=None,
                   catids=[], other={},
                   addPyComCat=None,
                   dispatcher = None,
                   clsctx = None,
                   addnPath = None,
                  ):
  """Registers a Python object as a COM Server.  This enters almost all necessary
     information in the system registry, allowing COM to use the object.

     clsid -- The (unique) CLSID of the server.
     pythonInstString -- A string holding the instance name that will be created
                   whenever COM requests a new object.
     desc -- The description of the COM object.
     progID -- The user name of this object (eg, Word.Document)
     verProgId -- The user name of this version's implementation (eg Word.6.Document)
     defIcon -- The default icon for the object.
     threadingModel -- The threading model this object supports.
     policy -- The policy to use when creating this object.
     catids -- A list of category ID's this object belongs in.
     other -- A dictionary of extra items to be registered.
     addPyComCat -- A flag indicating if the object should be added to the list
              of Python servers installed on the machine.  If None (the default)
              then it will be registered when running from python source, but
              not registered if running in a frozen environment.
     dispatcher -- The dispatcher to use when creating this object.
     clsctx -- One of the CLSCTX_* constants.
     addnPath -- An additional path the COM framework will add to sys.path
                 before attempting to create the object.
  """


  ### backwards-compat check
  ### Certain policies do not require a "class name", just the policy itself.
  if not pythonInstString and not policy:
    raise TypeError('You must specify either the Python Class or Python Policy which implement the COM object.')

  keyNameRoot = "CLSID\\%s" % str(clsid)
  _set_string(keyNameRoot, desc)

  # Also register as an "Application" so DCOM etc all see us.
  _set_string("AppID\\%s" % clsid, progID)
  # Depending on contexts requested, register the specified server type.
  # Set default clsctx.
  if not clsctx:
    clsctx = pythoncom.CLSCTX_INPROC_SERVER | pythoncom.CLSCTX_LOCAL_SERVER
  # And if we are frozen, ignore the ones that don't make sense in this
  # context.
  if pythoncom.frozen:
    assert sys.frozen, "pythoncom is frozen, but sys.frozen is not set - don't know the context!"
    if sys.frozen == "dll":
      clsctx = clsctx & pythoncom.CLSCTX_INPROC_SERVER
    else:
      clsctx = clsctx & pythoncom.CLSCTX_LOCAL_SERVER
  # Now setup based on the clsctx left over.
  if clsctx & pythoncom.CLSCTX_INPROC_SERVER:
    # get the module to use for registration.
    # nod to Gordon's installer - if sys.frozen and sys.frozendllhandle
    # exist, then we are being registered via a DLL - use this DLL as the
    # file name.
    if pythoncom.frozen:
      if hasattr(sys, "frozendllhandle"):
        dllName = win32api.GetModuleFileName(sys.frozendllhandle)
      else:
        raise RuntimeError("We appear to have a frozen DLL, but I don't know the DLL to use")
    else:
      # Normal case - running from .py file, so register pythoncom's DLL.
      # Although now we prefer a 'loader' DLL if it exists to avoid some
      # manifest issues (the 'loader' DLL has a manifest, but pythoncom does not)
      pythoncom_dir = os.path.dirname(pythoncom.__file__)
      if pythoncom.__file__.find("_d") < 0:
        suffix = ""
      else:
        suffix = "_d"
      loadername = "pythoncomloader%d%d%s.dll" % (sys.version_info[0], sys.version_info[1], suffix)
      if os.path.isfile(os.path.join(pythoncom_dir, loadername)):
        dllName = loadername
      else:
        # just use pythoncom.
        dllName = os.path.basename(pythoncom.__file__)

    _set_subkeys(keyNameRoot + "\\InprocServer32",
                 { None : dllName,
                   "ThreadingModel" : threadingModel,
                   })
  else: # Remove any old InProcServer32 registrations
    _remove_key(keyNameRoot + "\\InprocServer32")

  if clsctx & pythoncom.CLSCTX_LOCAL_SERVER:
    if pythoncom.frozen:
      # If we are frozen, we write "{exe} /Automate", just
      # like "normal" .EXEs do
      exeName = win32api.GetShortPathName(sys.executable)
      command = '%s /Automate' % (exeName,)
    else:
      # Running from .py sources - we need to write
      # 'python.exe win32com\server\localserver.py {clsid}"
      exeName = _find_localserver_exe(1)
      exeName = win32api.GetShortPathName(exeName)
      pyfile = _find_localserver_module()
      command = '%s "%s" %s' % (exeName, pyfile, str(clsid))
    _set_string(keyNameRoot + '\\LocalServer32', command)
  else: # Remove any old LocalServer32 registrations
    _remove_key(keyNameRoot + "\\LocalServer32")

  if pythonInstString:
    _set_string(keyNameRoot + '\\PythonCOM', pythonInstString)
  else:
    _remove_key(keyNameRoot + '\\PythonCOM')
  if policy:
    _set_string(keyNameRoot + '\\PythonCOMPolicy', policy)
  else:
    _remove_key(keyNameRoot + '\\PythonCOMPolicy')

  if dispatcher:
    _set_string(keyNameRoot + '\\PythonCOMDispatcher', dispatcher)
  else:
    _remove_key(keyNameRoot + '\\PythonCOMDispatcher')

  if defIcon:
    _set_string(keyNameRoot + '\\DefaultIcon', defIcon)
  else:
    _remove_key(keyNameRoot + '\\DefaultIcon')

  if addnPath:
    _set_string(keyNameRoot + "\\PythonCOMPath", addnPath)
  else:
    _remove_key(keyNameRoot + "\\PythonCOMPath")

  if addPyComCat is None:
    addPyComCat = pythoncom.frozen == 0
  if addPyComCat:
    catids = catids + [ CATID_PythonCOMServer ]

  # Set up the implemented categories
  if catids:
    regCat = _cat_registrar()
    regCat.RegisterClassImplCategories(clsid, catids)

  # set up any other reg values they might have
  if other:
    for key, value in other.items():
      _set_string(keyNameRoot + '\\' + key, value)

  if progID:
    # set the progID as the most specific that was given to us
    if verProgID:
      _set_string(keyNameRoot + '\\ProgID', verProgID)
    else:
      _set_string(keyNameRoot + '\\ProgID', progID)

    # Set up the root entries - version independent.
    if desc:
      _set_string(progID, desc)
    _set_string(progID + '\\CLSID', str(clsid))

    # Set up the root entries - version dependent.
    if verProgID:
      # point from independent to the current version
      _set_string(progID + '\\CurVer', verProgID)

      # point to the version-independent one
      _set_string(keyNameRoot + '\\VersionIndependentProgID', progID)

      # set up the versioned progID
      if desc:
        _set_string(verProgID, desc)
      _set_string(verProgID + '\\CLSID', str(clsid))

Example 47

Project: geofront-cli
Source File: test_utils.py
View license
    def setUp(self):
        """SetUp to mimic frozen windows."""
        super(Win32PkgdTestCase, self).setUp()
        self.patch(sys, "platform", "win32")
        sys.frozen = True

Example 48

Project: flappy-bird-py
Source File: lib.py
View license
    def find_library(self, path):
        '''Implements the dylib search as specified in Apple documentation:

        http://developer.apple.com/documentation/DeveloperTools/Conceptual/DynamicLibraries/Articles/DynamicLibraryUsageGuidelines.html

        Before commencing the standard search, the method first checks
        the bundle's ``Frameworks`` directory if the application is running
        within a bundle (OS X .app).
        '''

        libname = os.path.basename(path)
        search_path = []

        if hasattr(sys, 'frozen') and sys.frozen == 'macosx_app':
            search_path.append(os.path.join(
                os.environ['RESOURCEPATH'],
                '..',
                'Frameworks',
                libname))

        if '/' in path:
            search_path.extend(
                [os.path.join(p, libname) \
                    for p in self.dyld_library_path])
            search_path.append(path)
            search_path.extend(
                [os.path.join(p, libname) \
                    for p in self.dyld_fallback_library_path])
        else:
            search_path.extend(
                [os.path.join(p, libname) \
                    for p in self.ld_library_path])
            search_path.extend(
                [os.path.join(p, libname) \
                    for p in self.dyld_library_path])
            search_path.append(path)
            search_path.extend(
                [os.path.join(p, libname) \
                    for p in self.dyld_fallback_library_path])

        for path in search_path:
            if os.path.exists(path):
                return path

        return None

Example 49

Project: geofront-cli
Source File: test_utils.py
View license
    def tearDown(self):
        """tearDown, Remove frozen attr"""
        del sys.frozen
        super(Win32PkgdTestCase, self).tearDown()

Example 50

Project: coinbox-core
Source File: modules.py
View license
    def run(self):
        """
        Load all modules, taking care of disabled and conflicting ones.
        """
        
        logger.debug('Loading modules...')
        logger.debug('Path ({}): {}'.format(len(self.path), repr(self.path)))
        
        try:
            if not sys.frozen: # if not frozen, sys.frozen raises AttributeError
                raise AttributeError
        except AttributeError:
            pass
        else:
            # Try to find the packages frozen in the executable with PyInstaller
            try:
                import pyi_importers
            except ImportError:
                logger.warn('App is frozen but pyi_importers is not available')
            else:
                # Find FrozenImporter object from sys.meta_path.
                importer = None
                for obj in sys.meta_path:
                    if isinstance(obj, pyi_importers.FrozenImporter):
                        importer = obj
                        break
    
                for name in importer.toc:
                    p = name.split('.')
                    if len(p) == 2 and p[0] == 'cbmod': # Only match the pattern `cbmod.[modname]`
                        self.packages.append((importer, p[1], True)) # The first and 3rd arguments are ignored
        
        # Package with names starting with '_' are ignored
        self.packages += [p for p in pkgutil.walk_packages(self.path) \
                          if not p[1].startswith('_') and p[2]]
        
        for pkg in self.packages:
            wrap = ModuleWrapper(pkg)
            
            self.wrappers[wrap.base_name] = wrap
            
            # Check if disabled
            if wrap.base_name in self.disabled_names:
                logger.debug('Module {} is disabled.'.format(wrap.base_name))
                wrap.disable()
                continue
            
            # Try to load the module
            logger.debug('Loading module {}...'.format(wrap.base_name))
            try:
                wrap.load()
            except ImportError as e:
                logger.warn('Invalid module {}.'.format(wrap.base_name))
                logger.exception(e)
                wrap.disable()
                continue
            except:
                logger.exception('Failed loading {}'.format(wrap.base_name))
                logger.warn('Invalid module {}.'.format(wrap.base_name))
                wrap.disable()
                continue
            
            wrap.set_config_defaults()
        
        self.check_dependencies()
        
        logger.debug('({}) modules found: {}'.format(
                    len(self.ordered_wrappers),
                    ', '.join(w.base_name for w in self.ordered_wrappers))
                     )
        
        logger.debug('({}) modules disabled: {}'.format(
                    len(self.disabled_wrappers),
                    ', '.join(m.base_name for m in self.disabled_wrappers))
                     )
        
        if len(self.missing) > 0:
            logger.warn('({}) modules disabled for missing dependencies: {}'.format(
                        len(self.missing),
                        ', '.join(name for name in self.missing))
                        )