sys._getframe.f_code.co_filename

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

22 Examples 7

Example 1

Project: scratch
Source File: ae-routinglib.py
View license
def ae_main(app):
    from google.appengine.ext.webapp import util
    import __main__ as mod
    # "if caller is main"
    if sys._getframe(1).f_code.co_filename == mod.__file__:
        mod.main = lambda: util.run_wsgi_app(app)
        mod.main()

Example 2

Project: SwiftKitten
Source File: verifier.py
View license
def _caller_dir_pycache():
    if _TMPDIR:
        return _TMPDIR
    result = os.environ.get('CFFI_TMPDIR')
    if result:
        return result
    filename = sys._getframe(2).f_code.co_filename
    return os.path.abspath(os.path.join(os.path.dirname(filename),
                           '__pycache__'))

Example 3

Project: SwiftKitten
Source File: verifier.py
View license
def _caller_dir_pycache():
    if _TMPDIR:
        return _TMPDIR
    result = os.environ.get('CFFI_TMPDIR')
    if result:
        return result
    filename = sys._getframe(2).f_code.co_filename
    return os.path.abspath(os.path.join(os.path.dirname(filename),
                           '__pycache__'))

Example 4

Project: django-dowser
Source File: reftree.py
View license
    def __init__(self, obj):
        self.seen = {}
        self.maxdepth = None
        self.obj = obj
        self.filename = sys._getframe().f_code.co_filename
        self._ignore = {}

Example 5

Project: django-dowser
Source File: reftree.py
View license
    def __init__(self, obj):
        self.seen = {}
        self.maxdepth = None
        self.obj = obj
        self.filename = sys._getframe().f_code.co_filename
        self._ignore = {}

Example 6

Project: dpAutoRigSystem
Source File: dpUtils.py
View license
def findPath(filename):
    """ Find and return the absolute path of the fileName.
    """
    stringPath   = str(os.path.join(os.path.dirname(sys._getframe(1).f_code.co_filename), filename))
    correctPath  = stringPath.replace("\\", "/")
    if os.name == "posix":
        absolutePath = stringPath[0:stringPath.rfind("/")]
    else:
        absolutePath = correctPath[correctPath.find("/")-2:correctPath.rfind("/")]
    return absolutePath

Example 7

Project: dpAutoRigSystem
Source File: dpUtils.py
View license
def findPath(filename):
    """ Find and return the absolute path of the fileName.
    """
    stringPath   = str(os.path.join(os.path.dirname(sys._getframe(1).f_code.co_filename), filename))
    correctPath  = stringPath.replace("\\", "/")
    if os.name == "posix":
        absolutePath = stringPath[0:stringPath.rfind("/")]
    else:
        absolutePath = correctPath[correctPath.find("/")-2:correctPath.rfind("/")]
    return absolutePath

Example 8

Project: eve-central.com
Source File: reftree.py
View license
    def __init__(self, obj):
        self.obj = obj
        self.filename = sys._getframe().f_code.co_filename
        self._ignore = {}

Example 9

Project: eve-central.com
Source File: __init__.py
View license
    def _gen(self, obj, depth=0):
        if self.maxdepth and depth >= self.maxdepth:
            yield depth, 0, "---- Max depth reached ----"
            raise StopIteration
        
        if isinstance(obj, ModuleType) and self.ignore_modules:
            raise StopIteration
        
        refs = gc.get_referrers(obj)
        refiter = iter(refs)
        self.ignore(refs, refiter)
        thisfile = sys._getframe().f_code.co_filename
        for ref in refiter:
            # Exclude all frames that are from this module or reftree.
            if (isinstance(ref, FrameType)
                and ref.f_code.co_filename in (thisfile, self.filename)):
                continue
            
            # Exclude all functions and classes from this module or reftree.
            mod = getattr(ref, "__module__", "")
            if "dowser" in mod or "reftree" in mod or mod == '__main__':
                continue
            
            # Exclude all parents in our ignore list.
            if id(ref) in self._ignore:
                continue
            
            # Yield the (depth, id, repr) of our object.
            yield depth, 0, '%s<div class="branch">' % (" " * depth)
            if id(ref) in self.seen:
                yield depth, id(ref), "see %s above" % id(ref)
            else:
                self.seen[id(ref)] = None
                yield depth, id(ref), self.get_repr(ref, obj)
                
                for parent in self._gen(ref, depth + 1):
                    yield parent
            yield depth, 0, '%s</div>' % (" " * depth)

Example 10

Project: fixofx
Source File: fakeofx.py
View license
def fixpath(filename):
    mypath = os.path.dirname(sys._getframe(1).f_code.co_filename)
    return os.path.normpath(os.path.join(mypath, filename))

Example 11

Project: fixofx
Source File: fixofx.py
View license
def fixpath(filename):
    mypath = os.path.dirname(sys._getframe(1).f_code.co_filename)
    return os.path.normpath(os.path.join(mypath, filename))

Example 12

Project: gmvault
Source File: reftree.py
View license
    def __init__(self, obj):
        self.obj = obj
        self.filename = sys._getframe().f_code.co_filename
        self._ignore = {}

Example 13

Project: gmvault
Source File: __init__.py
View license
    def _gen(self, obj, depth=0):
        if self.maxdepth and depth >= self.maxdepth:
            yield depth, 0, "---- Max depth reached ----"
            raise StopIteration
        
        if isinstance(obj, ModuleType) and self.ignore_modules:
            raise StopIteration
        
        refs = gc.get_referrers(obj)
        refiter = iter(refs)
        self.ignore(refs, refiter)
        thisfile = sys._getframe().f_code.co_filename
        for ref in refiter:
            # Exclude all frames that are from this module or reftree.
            if (isinstance(ref, FrameType)
                and ref.f_code.co_filename in (thisfile, self.filename)):
                continue
            
            # Exclude all functions and classes from this module or reftree.
            mod = getattr(ref, "__module__", "")
            if "dowser" in mod or "reftree" in mod or mod == '__main__':
                continue
            
            # Exclude all parents in our ignore list.
            if id(ref) in self._ignore:
                continue
            
            # Yield the (depth, id, repr) of our object.
            yield depth, 0, '%s<div class="branch">' % (" " * depth)
            if id(ref) in self.seen:
                yield depth, id(ref), "see %s above" % id(ref)
            else:
                self.seen[id(ref)] = None
                yield depth, id(ref), self.get_repr(ref, obj)
                
                for parent in self._gen(ref, depth + 1):
                    yield parent
            yield depth, 0, '%s</div>' % (" " * depth)

Example 14

Project: gramps
Source File: configmanager.py
View license
    def register_manager(self, name, override="", use_plugins_path=True,
                         use_config_path=False):
        """
        Register a plugin manager.

        :param name: is used as the key of the config manager singleton. It is
                     also be used as the base filename (unless an override is
                     given, or use_config_path or use_plugins_path is True).
        :param override: is used to override the default location of the .ini
                         file.
        :param use_config_path: if True, use this ConfigManager's path as the
                                new manager's path, ignoring any path given in
                                override.

        Override is either:

        - a full path+filename ending in .ini
        - a filename ending in .ini
        - a dir path to put ini file into
        - a full path+filename to get dir to put ini file into
        - a ConfigManager instance

        Examples::

          >>> config.register_manager("Simple", use_plugins_path=False)
          # will use the calling programs directory, and "Simple.ini"
          >>> config.register_manager("Simple", __file__,
                                      use_plugins_path=False)
          # will use the __file__'s directory, and "Simple.ini"
          >>> config.register_manager("Simple", "c:\\temp",
                                      use_plugins_path=False)
          # will use the given directory, "c:\\temp\\Simple.ini"
          >>> config.register_manager("Simple", use_config_path=True)
          # will use config's path: ~/.gramps/gramps32/Simple.ini
          >>> config.register_manager("Simple", "Other.ini")
          # will use config + plugins path: ~/.gramps/gramps32/plugins/Other.ini
          >>> config.register_manager("Simple", "/tmp/Other.ini",
                                      use_plugins_path=False)
          # will use /tmp/Other.ini
        """
        if isinstance(override, str): # directory or filename
            if override:
                path, ininame = os.path.split(os.path.abspath(override))
            else:
                path, ininame = os.path.split(sys._getframe(1).f_code.co_filename)
            if not ininame.endswith(".ini"):
                ininame = "%s.ini" % name
            if use_config_path:
                path = self.config_path
            elif use_plugins_path:
                path = os.path.join(self.config_path, self.plugins)
            filename = os.path.join(path, ininame)
            plugin = ConfigManager(filename)
        elif isinstance(override, ConfigManager):
            plugin = override
        else:
            raise AttributeError("plugin needs to be a file or ConfigManager")
        ConfigManager.PLUGINS[name] = plugin
        return ConfigManager.PLUGINS[name]

Example 15

Project: gramps
Source File: glade.py
View license
    def __init__(self, filename=None, dirname=None, toplevel=None):
        """
        Class Constructor: Returns a new instance of the Glade class

        :type  filename: string
        :param filename: The name of the glade file to be used. Defaults to None
        :type  dirname: string
        :param dirname: The directory to search for the glade file. Defaults to
                    None which will cause a search for the file in the default
                    directory followed by the directory of the calling module.
        :type  toplevel: toplevel
        :param toplevel: The toplevel object to search for in the glade file.
                     Defaults to None, which will cause a search for a toplevel
                     matching the file name.
        :rtype:   object reference
        :returns:  reference to the newly-created Glade instance
        """
        Gtk.Builder.__init__(self)
        self.set_translation_domain(glocale.get_localedomain())

        filename_given = filename is not None
        dirname_given = dirname is not None

        # if filename not given, use module name to derive it

        if not filename_given:
            filename = sys._getframe(1).f_code.co_filename
            filename = os.path.basename(filename)
            filename = filename.rpartition('.')[0] + '.glade'
            filename = filename.lstrip('_').lower()

        # if dirname not given, use current directory

        if not dirname_given:
            dirname = sys._getframe(1).f_code.co_filename
            dirname = os.path.dirname(dirname)

        # try to find the glade file

        if filename_given and dirname_given:    # both given -- use them
            path = os.path.join(dirname, filename)

        elif filename_given:                    # try default directory first
            path = os.path.join(GLADE_DIR, filename)
            if not os.path.exists(path):        # then module directory
                path = os.path.join(dirname, filename)

        elif dirname_given:                     # dirname given -- use it
            path = os.path.join(dirname, filename)

        # neither filename nor dirname given.  Try:
        # 1. derived filename in default directory
        # 2. derived filename in module directory

        else:
            path = os.path.join(GLADE_DIR, filename)
            if not os.path.exists(path):
                path = os.path.join(dirname, filename)

        # try to build Gtk objects from glade file.  Let exceptions happen

        self.add_from_file(path)
        self.__dirname, self.__filename = os.path.split(path)

        # try to find the toplevel widget

        if toplevel:                            # toplevel is given
            self.__toplevel = self.get_object(toplevel)
        else:                                   # toplevel not given
            # first, use filename as possible toplevel widget name
            self.__toplevel = self.get_object(filename.rpartition('.')[0])

            # next try lowercase filename as possible widget name
            if not self.__toplevel:
                self.__toplevel = self.get_object(
                                        filename.rpartition('.')[0].lower())

                if not self.__toplevel:
                    # if no match found, search for first toplevel widget
                    for obj in self.get_objects():
                        if hasattr(obj, 'get_toplevel'):
                            self.__toplevel = obj.get_toplevel()
                            break
                    else:
                        self.__toplevel = None

Example 16

Project: pytools
Source File: debug.py
View license
def refdebug(obj, top_level=True, exclude=[]):
    from types import FrameType

    def is_excluded(o):
        for ex in exclude:
            if o is ex:
                return True

        from sys import _getframe
        if isinstance(o, FrameType) and \
                o.f_code.co_filename == _getframe().f_code.co_filename:
            return True

        return False

    if top_level:
        try:
            refdebug(obj, top_level=False, exclude=exclude)
        except RefDebugQuit:
            pass
    else:
        import gc
        print_head = True
        print("-------------->")
        try:
            reflist = [x for x in gc.get_referrers(obj)
                    if not is_excluded(x)]

            idx = 0
            while True:
                if print_head:
                    print("referring to", id(obj), type(obj), obj)
                    print("----------------------")
                    print_head = False
                r = reflist[idx]

                if isinstance(r, FrameType):
                    s = str(r.f_code)
                else:
                    s = str(r)

                print("%d/%d: " % (idx, len(reflist)), id(r), type(r), s)

                if isinstance(r, dict):
                    for k, v in six.iteritems(r):
                        if v is obj:
                            print("...referred to from key", k)

                print("[d]ig, [n]ext, [p]rev, [e]val, [r]eturn, [q]uit?")

                response = input()

                if response == "d":
                    refdebug(r, top_level=False, exclude=exclude+[reflist])
                    print_head = True
                elif response == "n":
                    if idx + 1 < len(reflist):
                        idx += 1
                elif response == "p":
                    if idx - 1 >= 0:
                        idx -= 1
                elif response == "e":
                    print("type expression, obj is your object:")
                    expr_str = input()
                    try:
                        res = eval(expr_str, {"obj": r})
                    except:
                        from traceback import print_exc
                        print_exc()
                    print(res)
                elif response == "r":
                    return
                elif response == "q":
                    raise RefDebugQuit()
                else:
                    print("WHAT YOU SAY!!! (invalid choice)")

        finally:
            print("<--------------")

Example 17

Project: python-mapnik
Source File: utilities.py
View license
def execution_path(filename):
    return os.path.join(os.path.dirname(
        sys._getframe(1).f_code.co_filename), filename)

Example 18

Project: python-mapnik
Source File: utilities.py
View license
def execution_path(filename):
    return os.path.join(os.path.dirname(
        sys._getframe(1).f_code.co_filename), filename)

Example 19

View license
def _tidy_stacktrace():
    """
    Tidy the stack_trace
    """
    socketserver_path = os.path.realpath(os.path.dirname(SocketServer.__file__))
    pymongo_path = os.path.realpath(os.path.dirname(pymongo.__file__))
    paths = ['/site-packages/', '/flaskext/', socketserver_path, pymongo_path]
    internal = False

    # Check html templates
    fnames = []
    for i in range(100):
        try:
            fname = sys._getframe(i).f_code.co_filename
            if '.html' in fname:
                fnames.append(fname)
        except:
            break
    fnames = list(set(fnames))
    trace = []

    for path in fnames:
        if 'flask_debugtoolbar' in path:
            internal = True
        trace.append((path, '?', '?', '?', False))

    if trace:
        return trace, internal

    stack = inspect.stack()
    reversed(stack)

    trace = []
    for frame, path, line_no, func_name, text in (f[:5] for f in stack):
        s_path = os.path.realpath(path)
        # Support hiding of frames -- used in various utilities that provide
        # inspection.
        if '__traceback_hide__' in frame.f_locals:
            continue
        hidden = False
        if func_name == "<genexpr>":
            hidden = True
        if any([p for p in paths if p in s_path]):
            hidden = True
        if not text:
            text = ''
        else:
            if sys.version_info >= (3, 0):
                text = ''.join(text).strip()
            else:
                try:
                    text = unicode(''.join(text).strip())
                except:
                    pass
        trace.append((path, line_no, func_name, text, hidden))
    return trace, internal

Example 20

View license
def _tidy_stacktrace():
    """
    Tidy the stack_trace
    """
    socketserver_path = os.path.realpath(os.path.dirname(SocketServer.__file__))
    pymongo_path = os.path.realpath(os.path.dirname(pymongo.__file__))
    paths = ['/site-packages/', '/flaskext/', socketserver_path, pymongo_path]
    internal = False

    # Check html templates
    fnames = []
    for i in range(100):
        try:
            fname = sys._getframe(i).f_code.co_filename
            if '.html' in fname:
                fnames.append(fname)
        except:
            break
    fnames = list(set(fnames))
    trace = []

    for path in fnames:
        if 'flask_debugtoolbar' in path:
            internal = True
        trace.append((path, '?', '?', '?', False))

    if trace:
        return trace, internal

    stack = inspect.stack()
    reversed(stack)

    trace = []
    for frame, path, line_no, func_name, text in (f[:5] for f in stack):
        s_path = os.path.realpath(path)
        # Support hiding of frames -- used in various utilities that provide
        # inspection.
        if '__traceback_hide__' in frame.f_locals:
            continue
        hidden = False
        if func_name == "<genexpr>":
            hidden = True
        if any([p for p in paths if p in s_path]):
            hidden = True
        if not text:
            text = ''
        else:
            if sys.version_info >= (3, 0):
                text = ''.join(text).strip()
            else:
                try:
                    text = unicode(''.join(text).strip())
                except:
                    pass
        trace.append((path, line_no, func_name, text, hidden))
    return trace, internal

Example 21

Project: django-dowser
Source File: views.py
View license
    def _gen(self, obj, depth=0):
        if self.maxdepth and depth >= self.maxdepth:
            yield depth, 0, "---- Max depth reached ----"
            raise StopIteration
        if isinstance(obj, ModuleType) and self.ignore_modules:
            raise StopIteration

        refs = gc.get_referrers(obj)
        refiter = iter(refs)
        self.ignore(refs, refiter)
        thisfile = sys._getframe().f_code.co_filename
        for ref in refiter:
            # Exclude all frames that are from this module or reftree.
            if isinstance(ref, FrameType) and ref.f_code.co_filename in (thisfile, self.filename):
                continue

            # Exclude all functions and classes from this module or reftree.
            mod = getattr(ref, "__module__", "")
            if "django_dowser" in mod or "reftree" in mod or mod == '__main__':
                continue

            # Exclude all parents in our ignore list.
            if id(ref) in self._ignore:
                continue

            # Yield the (depth, id, repr) of our object.
            yield depth, 0, '%s<div class="branch">' % (" " * depth)
            if id(ref) in self.seen:
                yield depth, id(ref), "see %s above" % id(ref)
            else:
                self.seen[id(ref)] = None
                yield depth, id(ref), self.get_repr(ref, obj)

                for parent in self._gen(ref, depth + 1):
                    yield parent
            yield depth, 0, '%s</div>' % (" " * depth)

Example 22

Project: django-dowser
Source File: views.py
View license
    def _gen(self, obj, depth=0):
        if self.maxdepth and depth >= self.maxdepth:
            yield depth, 0, "---- Max depth reached ----"
            raise StopIteration
        if isinstance(obj, ModuleType) and self.ignore_modules:
            raise StopIteration

        refs = gc.get_referrers(obj)
        refiter = iter(refs)
        self.ignore(refs, refiter)
        thisfile = sys._getframe().f_code.co_filename
        for ref in refiter:
            # Exclude all frames that are from this module or reftree.
            if isinstance(ref, FrameType) and ref.f_code.co_filename in (thisfile, self.filename):
                continue

            # Exclude all functions and classes from this module or reftree.
            mod = getattr(ref, "__module__", "")
            if "django_dowser" in mod or "reftree" in mod or mod == '__main__':
                continue

            # Exclude all parents in our ignore list.
            if id(ref) in self._ignore:
                continue

            # Yield the (depth, id, repr) of our object.
            yield depth, 0, '%s<div class="branch">' % (" " * depth)
            if id(ref) in self.seen:
                yield depth, id(ref), "see %s above" % id(ref)
            else:
                self.seen[id(ref)] = None
                yield depth, id(ref), self.get_repr(ref, obj)

                for parent in self._gen(ref, depth + 1):
                    yield parent
            yield depth, 0, '%s</div>' % (" " * depth)