コード例 #1
0
def initialize():
    if (Initialize.startInitialization(__name__)):
        return
    
    # initialization code
    global _iconprefix
    _iconprefix = os.path.dirname(os.path.abspath(sys.argv[0]))
    _iconprefix = os.sep.join(_iconprefix.split(os.sep)[:-1] + ["src"])
        # Note: for developers, this is .../cad/src and also contains the
        # toplevel python modules or packages (as of 080111 anyway);
        # within built releases, it may not be the same directory as that
        # even though it ends with "src". [bruce comment 080111]

    if EndUser.getAlternateSourcePath() != None:
        new_iconprefix = EndUser.getAlternateSourcePath()
        print "ALTERNATE_CAD_SRC_PATH: setting _iconprefix to %r rather than %r" % \
              ( new_iconprefix, _iconprefix )
        _iconprefix = new_iconprefix

    Initialize.endInitialization(__name__)
    return
コード例 #2
0
import numpy.oldnumeric

# these are used only by the test code at the bottom;
# if these ever cause an import cycle, move that code to a separate module.
from OpenGL.GL import glPopMatrix
from OpenGL.GL import glPushMatrix
from OpenGL.GL import glTranslate
from utilities.Log import redmsg
from utilities.debug import print_compact_stack

# ==

# Machinery to load the C renderer, from either of two places,
# one for developers and one for end users.

if EndUser.getAlternateSourcePath() != None:
    sys.path.append(os.path.join( EndUser.getAlternateSourcePath(),
                                  "experimental/pyrex-opengl"))
else:
    sys.path.append("./experimental/pyrex-opengl")

binPath = os.path.normpath(os.path.dirname(os.path.abspath(sys.argv[0]))
                           + '/../bin')
if binPath not in sys.path:
    sys.path.append(binPath)

quux_module_import_succeeded = False

try:
    import quux # can't be toplevel
    quux_module_import_succeeded = True
コード例 #3
0
_USE_bsddb3 = NE1_Build_Constants.NE1_USE_bsddb3

try:
    if _USE_bsddb3:
        import bsddb3 as _junk
    else:
        import bsddb as _junk
    _junk  # try to tell pylint we need this import [bruce 071023]
except:
    dbname = "somedb"
    print """\

Warning: import bsddb failed; using some other db format for preferences file;
 giving it a different name in case that uses an incompatible binary format;
 this means, when you upgrade to bsddb, you'll lose your preferences."""
    if EndUser.getAlternateSourcePath() != None:
        # [bruce 070704]
        print "(Note: as of 070704 this is a common side-effect of using the"
        print "ALTERNATE_CAD_SRC_PATH feature, since the built release has a"
        print "patch to use bsddb3 which is not present in cvs code."
        print "This situation will probably be fixed soon.)"
    print
else:
    dbname = "bsddb"

# And this module requires shelve. We assume without checking that if bsddb is available,
# shelve will use it. (I don't know any straightforward way to check this. But the
# docs for shelve say it will use it, I think. #k check this ###@@@)

if _USE_bsddb3:
    from bsddb3 import dbshelve as shelve
コード例 #4
0
import numpy.oldnumeric

# these are used only by the test code at the bottom;
# if these ever cause an import cycle, move that code to a separate module.
from OpenGL.GL import glPopMatrix
from OpenGL.GL import glPushMatrix
from OpenGL.GL import glTranslate
from utilities.Log import redmsg
from utilities.debug import print_compact_stack

# ==

# Machinery to load the C renderer, from either of two places,
# one for developers and one for end users.

if EndUser.getAlternateSourcePath() != None:
    sys.path.append(
        os.path.join(EndUser.getAlternateSourcePath(),
                     "experimental/pyrex-opengl"))
else:
    sys.path.append("./experimental/pyrex-opengl")

binPath = os.path.normpath(
    os.path.dirname(os.path.abspath(sys.argv[0])) + '/../bin')
if binPath not in sys.path:
    sys.path.append(binPath)

quux_module_import_succeeded = False

try:
    import quux  # can't be toplevel
コード例 #5
0
def before_most_imports( main_globals ):
    """
    Do things that should be done before most imports occur.
    main_globals should be the value of globals() in the __main__ module.
    """

    # user-specific debug code to be run before any other imports [bruce 040903]

    # gpl_only check at startup [bruce 041217]
    try:
        import platform_dependent.gpl_only as _gpl_only
            # if this module is there, this lets it verify it should be there,
            # and if not, complain (to developers) whenever the program starts
        print "(running a GPL distribution)" #e retain or zap this?
    except ImportError:
        print "(running a non-GPL distribution)" #e retain or zap this? [should never happen for Qt4, as of 070425]
        pass # this is normal for non-GPL distributions
    try:
        rc = "~/.atom-debug-rc"
        rc = os.path.expanduser(rc)
        if os.path.exists(rc):
            ## execfile(rc) -- not allowed!
            import utilities.debug as _debug
            _debug.legally_execfile_in_globals(rc, main_globals, error_exception = False)
                # might fail in non-GPL versions; prints error message but
                # does not raise an exception.
                # (doing it like this is required by our licenses for Qt/PyQt)
    except:
        print """exception in execfile(%r); traceback printed to stderr or console; exiting""" % (rc,)
        raise

    # Figure out whether we're run by a developer from cvs sources
    # (EndUser.enableDeveloperFeatures() returns True), or by an
    # end-user from an installer-created program (it returns False).
    # Use two methods, warn if they disagree, and if either one
    # think's we're an end user, assume we are (so as to turn off
    # certain code it might not be safe for end-users to run).
    # [bruce 050902 new feature; revised 051006 to work in Windows
    # built packages]
    # [Russ 080905: Fixed after this file moved into ne1_startup.
    #  bruce 080905 slightly revised that fix.
    #  Note: see also NE1_Build_Constants.py, which has constants
    #  that might be useable for this.]
    _OUR_PACKAGE = "ne1_startup" # should be this file's package inside cad/src
        # todo: this could be derived entirely from __name__.
    our_basename = __name__.split('.')[-1] # e.g. startup_before_most_imports
    assert _OUR_PACKAGE == __name__.split('.')[-2], \
           "need to revise this code for moved file"
        # this will fail if _OUR_PACKAGE has more than one component, or no
        # components; that's intentional, since some of the code below would
        # also fail in that case. If it fails, generalize this and that code.

    # Method 1. As of 050902, package builders on all platforms reportedly move main.py
    # (the __main__ script) into a higher directory than the compiled python files.
    # But developers running from cvs leave them all in cad/src.
    # So we compare the directories.
    endUser = True # conservative initial assumption (might be changed below)
    import __main__
    ourdir = None # hack for print statement test in except clause
        # this is still being imported, but we only need its __file__ attribute, which should be already defined [but see below]
    try:
        # It turns out that for Windows (at least) package builds, __main__.__file__ is either never defined or not yet
        # defined at this point, so we have no choice but to silently guess endUser = True in that case. I don't know whether
        # this module's __file__ is defined, whether this problem is Windows-specific, etc. What's worse, this problem disables
        # *both* guessing methods, so on an exception we just have to skip the whole thing. Further study might show that there is
        # no problem with ourdir, only with maindir, but I won't force us to test that right now. [bruce 051006]
        # REVIEW: is this still correct now that this code is in a non-toplevel module? [bruce 080111 question]
        ourdir = os.path.split(__file__)[0]
        maindir = os.path.split(__main__.__file__)[0]
    except:
        # unfortunately it's not ok to print the exception or any error message, in case endUser = True is correct...
        # but maybe I can get away with printing something cryptic (since our code is known to print things sometimes anyway)?
        # And I can make it depend on whether ourdir was set, so we have a chance of finding out whether this module defined __file__.
        # [bruce 051006]
        if ourdir is not None:
            print "end-user build"
        else:
            print "end user build" # different text -- no '-'
    else:
        # we set maindir and ourdir; try both guess-methods, etc
        def canon(path):
            #bruce 050908 bugfix in case developer runs python with relative (or other non-canonical) path as argument
            return os.path.normcase(os.path.abspath(path))
        maindir = canon(maindir)
        ourdir = canon(ourdir)
        guess1 = (os.path.join(maindir, _OUR_PACKAGE) != ourdir) # Russ 080905: Loaded from package subdirectory.

        # Method 2. As of 050902, package builders on all platforms remove the .py files, leaving only .pyc files.
        guess2 = not os.path.exists(os.path.join(ourdir, our_basename + ".py"))

        endUser = guess1 or guess2
        if EndUser.getAlternateSourcePath() != None:
            # special case when using ALTERNATE_CAD_SRC_PATH feature
            # (which can cause these guesses to differ or be incorrect):
            # assume anyone using it is a developer [bruce 070704]
            endUser = False
        else:
            if guess1 != guess2:
                print "Warning: two methods of guessing whether we're being run by an end-user disagreed (%r and %r)." % (guess1, guess2)
                print "To be safe, assuming we are (disabling some developer-only features)."
                print "If this ever happens, it's a bug, and the methods need to be updated."
                if guess1:
                    print "(debug info: guess1 is true because %r != %r)" % (maindir, ourdir)
                        #bruce 050908 to debug Linux bug in guess1 reported by Ninad (it's True (i.e. wrong) when he runs nE-1 from source)
                print
        pass

    EndUser.setDeveloperFeatures(not endUser)
    if EndUser.enableDeveloperFeatures():
        print "enabling developer features"
        # The actual enabling is done by other code which checks the value of EndUser.enableDeveloperFeatures().
        # Note: most code should NOT behave differently based on that value!
        # (Doing so might cause bugs to exist in the end-user version but not the developer version,
        #  which would make them very hard to notice or debug. This risk is only justified in a few
        #  special cases.)
    
    return # from before_most_imports
コード例 #6
0
ファイル: preferences.py プロジェクト: pmetzger/nanoengineer
_USE_bsddb3 = NE1_Build_Constants.NE1_USE_bsddb3

try:
    if _USE_bsddb3:
        import bsddb3 as _junk
    else:
        import bsddb as _junk
    _junk # try to tell pylint we need this import [bruce 071023]
except:
    dbname = "somedb"
    print """\

Warning: import bsddb failed; using some other db format for preferences file;
 giving it a different name in case that uses an incompatible binary format;
 this means, when you upgrade to bsddb, you'll lose your preferences."""
    if EndUser.getAlternateSourcePath() != None:
        # [bruce 070704]
        print "(Note: as of 070704 this is a common side-effect of using the"
        print "ALTERNATE_CAD_SRC_PATH feature, since the built release has a"
        print "patch to use bsddb3 which is not present in cvs code."
        print "This situation will probably be fixed soon.)"
    print
else:
    dbname = "bsddb"

# And this module requires shelve. We assume without checking that if bsddb is available,
# shelve will use it. (I don't know any straightforward way to check this. But the
# docs for shelve say it will use it, I think. #k check this ###@@@)

if _USE_bsddb3:
    from bsddb3 import dbshelve as shelve
コード例 #7
0
def before_most_imports( main_globals ):
    """
    Do things that should be done before most imports occur.
    main_globals should be the value of globals() in the __main__ module.
    """

    # user-specific debug code to be run before any other imports [bruce 040903]

    # gpl_only check at startup [bruce 041217]
    try:
        import platform_dependent.gpl_only as _gpl_only
            # if this module is there, this lets it verify it should be there,
            # and if not, complain (to developers) whenever the program starts
        print "(running a GPL distribution)" #e retain or zap this?
    except ImportError:
        print "(running a non-GPL distribution)" #e retain or zap this? [should never happen for Qt4, as of 070425]
        pass # this is normal for non-GPL distributions
    try:
        rc = "~/.atom-debug-rc"
        rc = os.path.expanduser(rc)
        if os.path.exists(rc):
            ## execfile(rc) -- not allowed!
            import utilities.debug as _debug
            _debug.legally_execfile_in_globals(rc, main_globals, error_exception = False)
                # might fail in non-GPL versions; prints error message but
                # does not raise an exception.
                # (doing it like this is required by our licenses for Qt/PyQt)
    except:
        print """exception in execfile(%r); traceback printed to stderr or console; exiting""" % (rc,)
        raise

    # Figure out whether we're run by a developer from cvs sources
    # (EndUser.enableDeveloperFeatures() returns True), or by an
    # end-user from an installer-created program (it returns False).
    # Use two methods, warn if they disagree, and if either one
    # think's we're an end user, assume we are (so as to turn off
    # certain code it might not be safe for end-users to run).
    # [bruce 050902 new feature; revised 051006 to work in Windows
    # built packages]
    # [Russ 080905: Fixed after this file moved into ne1_startup.
    #  bruce 080905 slightly revised that fix.
    #  Note: see also NE1_Build_Constants.py, which has constants
    #  that might be useable for this.]
    _OUR_PACKAGE = "ne1_startup" # should be this file's package inside cad/src
        # todo: this could be derived entirely from __name__.
    our_basename = __name__.split('.')[-1] # e.g. startup_before_most_imports
    assert _OUR_PACKAGE == __name__.split('.')[-2], \
           "need to revise this code for moved file"
        # this will fail if _OUR_PACKAGE has more than one component, or no
        # components; that's intentional, since some of the code below would
        # also fail in that case. If it fails, generalize this and that code.

    # Method 1. As of 050902, package builders on all platforms reportedly move main.py
    # (the __main__ script) into a higher directory than the compiled python files.
    # But developers running from cvs leave them all in cad/src.
    # So we compare the directories.
    endUser = True # conservative initial assumption (might be changed below)
    import __main__
    ourdir = None # hack for print statement test in except clause
        # this is still being imported, but we only need its __file__ attribute, which should be already defined [but see below]
    try:
        # It turns out that for Windows (at least) package builds, __main__.__file__ is either never defined or not yet
        # defined at this point, so we have no choice but to silently guess endUser = True in that case. I don't know whether
        # this module's __file__ is defined, whether this problem is Windows-specific, etc. What's worse, this problem disables
        # *both* guessing methods, so on an exception we just have to skip the whole thing. Further study might show that there is
        # no problem with ourdir, only with maindir, but I won't force us to test that right now. [bruce 051006]
        # REVIEW: is this still correct now that this code is in a non-toplevel module? [bruce 080111 question]
        ourdir = os.path.split(__file__)[0]
        maindir = os.path.split(__main__.__file__)[0]
    except:
        # unfortunately it's not ok to print the exception or any error message, in case endUser = True is correct...
        # but maybe I can get away with printing something cryptic (since our code is known to print things sometimes anyway)?
        # And I can make it depend on whether ourdir was set, so we have a chance of finding out whether this module defined __file__.
        # [bruce 051006]
        if ourdir is not None:
            print "end-user build"
        else:
            print "end user build" # different text -- no '-'
    else:
        # we set maindir and ourdir; try both guess-methods, etc
        def canon(path):
            #bruce 050908 bugfix in case developer runs python with relative (or other non-canonical) path as argument
            return os.path.normcase(os.path.abspath(path))
        maindir = canon(maindir)
        ourdir = canon(ourdir)
        guess1 = (os.path.join(maindir, _OUR_PACKAGE) != ourdir) # Russ 080905: Loaded from package subdirectory.

        # Method 2. As of 050902, package builders on all platforms remove the .py files, leaving only .pyc files.
        guess2 = not os.path.exists(os.path.join(ourdir, our_basename + ".py"))

        endUser = guess1 or guess2
        if EndUser.getAlternateSourcePath() != None:
            # special case when using ALTERNATE_CAD_SRC_PATH feature
            # (which can cause these guesses to differ or be incorrect):
            # assume anyone using it is a developer [bruce 070704]
            endUser = False
        else:
            if guess1 != guess2:
                print "Warning: two methods of guessing whether we're being run by an end-user disagreed (%r and %r)." % (guess1, guess2)
                print "To be safe, assuming we are (disabling some developer-only features)."
                print "If this ever happens, it's a bug, and the methods need to be updated."
                if guess1:
                    print "(debug info: guess1 is true because %r != %r)" % (maindir, ourdir)
                        #bruce 050908 to debug Linux bug in guess1 reported by Ninad (it's True (i.e. wrong) when he runs nE-1 from source)
                print
        pass

    EndUser.setDeveloperFeatures(not endUser)
    if EndUser.enableDeveloperFeatures():
        print "enabling developer features"
        # The actual enabling is done by other code which checks the value of EndUser.enableDeveloperFeatures().
        # Note: most code should NOT behave differently based on that value!
        # (Doing so might cause bugs to exist in the end-user version but not the developer version,
        #  which would make them very hard to notice or debug. This risk is only justified in a few
        #  special cases.)

    return # from before_most_imports