Example #1
0
def module_path (module) :
    """Returns path where `module` resides"""
    # print ">>> sys.path = %s" % sys.path #AGO
    # print ">>> dir () = %s" % dir () #AGO
    if module not in _module_pathes :
        if frozen () :
            _path = script_path ()
        elif (   module in sys.modules
             and hasattr (sys.modules [module], "__file__")
             ) :
            p     = sys.modules [module].__file__
            _path = sos.path.dirname (p) or sos.getcwd ()
        else :
            try: #AGO
                (f, p, d) = imp.find_module (module)
            except ImportError:
                # Should check here if there is a reference in sys.path to an
                # archive, and then if the module is really in this archive ...
                # But which path should then be returned?
                # Maybe the files looked for are also
                # compressed/packed/frozen.
                _path = script_path ()
            else: #AGO
                _path = sos.path.dirname (p) or sos.getcwd ()
        if _path == sos.curdir :
            _path = sos.getcwd ()
        _module_pathes [module] = _path
    return _module_pathes [module]
Example #2
0
def module_path(module):
    """Returns path where `module` resides"""
    # print ">>> sys.path = %s" % sys.path #AGO
    # print ">>> dir () = %s" % dir () #AGO
    if module not in _module_pathes:
        if frozen():
            _path = script_path()
        elif (module in sys.modules
              and hasattr(sys.modules[module], "__file__")):
            p = sys.modules[module].__file__
            _path = sos.path.dirname(p) or sos.getcwd()
        else:
            try:  #AGO
                (f, p, d) = imp.find_module(module)
            except ImportError:
                # Should check here if there is a reference in sys.path to an
                # archive, and then if the module is really in this archive ...
                # But which path should then be returned?
                # Maybe the files looked for are also
                # compressed/packed/frozen.
                _path = script_path()
            else:  #AGO
                _path = sos.path.dirname(p) or sos.getcwd()
        if _path == sos.curdir:
            _path = sos.getcwd()
        _module_pathes[module] = _path
    return _module_pathes[module]
Example #3
0
 def _gen_base_dirs(self, bds):
     cwd = sos.getcwd()
     for bd in bds:
         if isinstance(bd, pyk.string_types) and bd.startswith("$"):
             h, _, t = split_hst(bd, "/")
             h = getattr(self.cmd, h[1:])
             if h == "":
                 h = cwd
             bd = "/".join((h, t)) if t else h
         if bd is not None:
             yield bd
Example #4
0
 def _gen_base_dirs (self, bds) :
     cwd = sos.getcwd ()
     for bd in bds :
         if isinstance (bd, pyk.string_types) and bd.startswith ("$") :
             h, _, t = split_hst (bd, "/")
             h       = getattr (self.cmd, h [1:])
             if h == "" :
                 h   = cwd
             bd = "/".join ((h, t)) if t else h
         if bd is not None :
             yield bd
Example #5
0
 def _update_dependencies(self, filename=None):
     if filename is None:
         filename = self.parameter_file.name
     self.parameter_files[os.path.abspath(filename)].add(self)
     new_dir = TFL.Filename(filename).directory
     if new_dir:
         old_dir = os.getcwd()
         os.chdir(new_dir)
     if self.polling:
         self.p_m_time = os.stat(filename)[stat.ST_MTIME]
     execfile \
          ( filename
          , dict
              ( R       = TFL.Record
              , include = self._update_dependencies
              )
          , self.pdict
          )
     if new_dir:
         os.chdir(old_dir)
Example #6
0
 def _update_dependencies (self, filename = None) :
     if filename is None :
         filename = self.parameter_file.name
     self.parameter_files [os.path.abspath (filename)].add (self)
     new_dir = TFL.Filename (filename).directory
     if new_dir :
         old_dir = os.getcwd ()
         os.chdir (new_dir)
     if self.polling :
         self.p_m_time = os.stat (filename) [stat.ST_MTIME]
     execfile \
          ( filename
          , dict
              ( R       = TFL.Record
              , include = self._update_dependencies
              )
          , self.pdict
          )
     if new_dir :
         os.chdir (old_dir)
Example #7
0
 def abs_directory(self):
     """Return the directory name converted to absolute path string."""
     result = sos.path.abspath(self.directory)
     if not result:
         result = sos.getcwd()
     return result
Example #8
0
 def abs_directory(self):
     """Return the directory name converted to absolute path string."""
     result = sos.path.abspath(self.directory)
     if (not result):
         result = sos.getcwd()
     return result
Example #9
0
#    21-Aug-2007 (CED) practically_infinite introduced
#    27-Apr-2010 (CT) `exec_python_startup` added
#    21-Jun-2010 (CT) `py_shell` added
#    28-May-2013 (CT) Use `in`, not `has_key`
#    12-Oct-2014 (CT) Change `exec_python_startup` to `open` with flags `rb`
#    ««revision-date»»···
#--

from   _TFL      import TFL
from   _TFL      import sos

import imp
import re
import sys

default_dir = sos.getcwd       ()
home_dir    = sos.environ.get  ("HOME")
if home_dir is None :
    home_dir = sos.environ.get ("USERPROFILE")
    if home_dir is None :
        home_dir = default_dir

if   sos.name == "posix"                         :
    username = sos.environ.get ("USER",         "")
    hostname = sos.environ.get ("HOSTNAME",     "")
    system   = "posix"
elif (sos.name == "nt") or (sos.name == "win32") :
    username = sos.environ.get ("USERNAME",     "")
    hostname = sos.environ.get ("COMPUTERNAME", "")
    system   = "win32"
elif sos.name == "mac"                           :
Example #10
0
#    27-Apr-2010 (CT) `exec_python_startup` added
#    21-Jun-2010 (CT) `py_shell` added
#    28-May-2013 (CT) Use `in`, not `has_key`
#    12-Oct-2014 (CT) Change `exec_python_startup` to `open` with flags `rb`
#    10-Sep-2018 (CT) Add optional argument `depth` to `py_shell`
#    20-Apr-2020 (CT) Remove `module_path`
#    ««revision-date»»···
#--

from _TFL import TFL
from _TFL import sos

import re
import sys

default_dir = sos.getcwd()
home_dir = sos.environ.get("HOME")
if home_dir is None:
    home_dir = sos.environ.get("USERPROFILE")
    if home_dir is None:
        home_dir = default_dir

if sos.name == "posix":
    username = sos.environ.get("USER", "")
    hostname = sos.environ.get("HOSTNAME", "")
    system = "posix"
elif (sos.name == "nt") or (sos.name == "win32"):
    username = sos.environ.get("USERNAME", "")
    hostname = sos.environ.get("COMPUTERNAME", "")
    system = "win32"
elif sos.name == "mac":