Example #1
0
def LoadDialogs(rc_name = "dialogs.rc"):
    base_name = os.path.splitext(rc_name)[0]
    mod_name = "dialogs.resources." + base_name

    # I18N
    # Loads a foreign language dialogs.py file, assuming that sys.path
    # already points to one with the foreign language resources.
    try:
        mod = __import__("i18n_" + base_name)
    except ImportError:
        mod = None

    # If we are running from source code, check the .py file is up to date
    # wrt the .rc file passed in.
    # If we are running from binaries, the rc name is not used at all - we
    # assume someone running from source previously generated the .py!
    if not hasattr(sys, "frozen") and not mod:
        from resources import rc2py
        rc_path = os.path.dirname( rc2py.__file__ )
        if not os.path.isabs(rc_name):
            rc_name = os.path.join( rc_path, rc_name)
        py_name = os.path.join(rc_path, base_name + ".py")
        mtime = size = None
        if os.path.exists(py_name):
            try:
                mod = __import__(mod_name)
                mod = sys.modules[mod_name]
                mtime = mod._rc_mtime_
                size = mod._rc_size_
            except (ImportError, AttributeError):
                mtime = None
        try:
            stat_data = os.stat(rc_name)
            rc_mtime = stat_data[stat.ST_MTIME]
            rc_size = stat_data[stat.ST_SIZE]
        except OSError:
            rc_mtime = rc_size = None
        if rc_mtime!=mtime or rc_size!=size:
            # Need to generate the dialog.
            print "Generating %s from %s" % (py_name, rc_name)
            rc2py.convert(rc_name, py_name)
            if mod is not None:
                reload(mod)
    if mod is None:
        mod = __import__(mod_name)
        mod = sys.modules[mod_name]
    return mod.FakeParser()
Example #2
0
def LoadDialogs(rc_name="dialogs.rc"):
    base_name = os.path.splitext(rc_name)[0]
    mod_name = "dialogs.resources." + base_name

    # I18N
    # Loads a foreign language dialogs.py file, assuming that sys.path
    # already points to one with the foreign language resources.
    try:
        mod = __import__("i18n_" + base_name)
    except ImportError:
        mod = None

    # If we are running from source code, check the .py file is up to date
    # wrt the .rc file passed in.
    # If we are running from binaries, the rc name is not used at all - we
    # assume someone running from source previously generated the .py!
    if not hasattr(sys, "frozen") and not mod:
        from resources import rc2py
        rc_path = os.path.dirname(rc2py.__file__)
        if not os.path.isabs(rc_name):
            rc_name = os.path.join(rc_path, rc_name)
        py_name = os.path.join(rc_path, base_name + ".py")
        mtime = size = None
        if os.path.exists(py_name):
            try:
                mod = __import__(mod_name)
                mod = sys.modules[mod_name]
                mtime = mod._rc_mtime_
                size = mod._rc_size_
            except (ImportError, AttributeError):
                mtime = None
        try:
            stat_data = os.stat(rc_name)
            rc_mtime = stat_data[stat.ST_MTIME]
            rc_size = stat_data[stat.ST_SIZE]
        except OSError:
            rc_mtime = rc_size = None
        if rc_mtime != mtime or rc_size != size:
            # Need to generate the dialog.
            print "Generating %s from %s" % (py_name, rc_name)
            rc2py.convert(rc_name, py_name)
            if mod is not None:
                reload(mod)
    if mod is None:
        mod = __import__(mod_name)
        mod = sys.modules[mod_name]
    return mod.FakeParser()
Example #3
0
def LoadDialogs(rc_name = "dialogs.rc"):

    base_name = os.path.splitext(rc_name)[0]

    mod_name = "dialogs.resources." + base_name

    try:

        mod = __import__("i18n_" + base_name)

    except ImportError:

        mod = None

    if not hasattr(sys, "frozen") and not mod:

        from resources import rc2py

        rc_path = os.path.dirname( rc2py.__file__ )

        if not os.path.isabs(rc_name):

            rc_name = os.path.join( rc_path, rc_name)

        py_name = os.path.join(rc_path, base_name + ".py")

        mtime = size = None

        if os.path.exists(py_name):

            try:

                mod = __import__(mod_name)

                mod = sys.modules[mod_name]

                mtime = mod._rc_mtime_

                size = mod._rc_size_

            except (ImportError, AttributeError):

                mtime = None

        try:

            stat_data = os.stat(rc_name)

            rc_mtime = stat_data[stat.ST_MTIME]

            rc_size = stat_data[stat.ST_SIZE]

        except OSError:

            rc_mtime = rc_size = None

        if rc_mtime!=mtime or rc_size!=size:

            print "Generating %s from %s" % (py_name, rc_name)

            rc2py.convert(rc_name, py_name)

            if mod is not None:

                reload(mod)

    if mod is None:

        mod = __import__(mod_name)

        mod = sys.modules[mod_name]

    return mod.FakeParser()