Vega strike Python Modules doc  0.5.1
Documentation of the " Modules " folder of Vega strike
 All Data Structures Namespaces Files Functions Variables
site Namespace Reference

Data Structures

class  _Printer
 
class  _Helper
 

Functions

def makepath
 
def addsitedir
 
def addpackage
 

Variables

list L = []
 
dictionary _dirs_in_sys_path = {}
 
string s = "build/lib.%s-%.3s"
 
list prefixes = [sys.prefix]
 
list sitedirs
 
string exit = 'Use Cmd-Q to quit.'
 
tuple here = os.path.dirname(os.__file__)
 
string encoding = "ascii"
 
tuple loc = locale.getdefaultlocale()
 

Detailed Description

Append module search paths for third-party packages to sys.path.

****************************************************************
* This module is automatically imported during initialization. *
****************************************************************

In earlier versions of Python (up to 1.5a3), scripts or modules that
needed to use site-specific modules would place ``import site''
somewhere near the top of their code.  Because of the automatic
import, this is no longer necessary (but code that does it still
works).

This will append site-specific paths to to the module search path.  On
Unix, it starts with sys.prefix and sys.exec_prefix (if different) and
appends lib/python<version>/site-packages as well as lib/site-python.
On other platforms (mainly Mac and Windows), it uses just sys.prefix
(and sys.exec_prefix, if different, but this is unlikely).  The
resulting directories, if they exist, are appended to sys.path, and
also inspected for path configuration files.

A path configuration file is a file whose name has the form
<package>.pth; its contents are additional directories (one per line)
to be added to sys.path.  Non-existing directories (or
non-directories) are never added to sys.path; no directory is added to
sys.path more than once.  Blank lines and lines beginning with
'#' are skipped. Lines starting with 'import' are executed.

For example, suppose sys.prefix and sys.exec_prefix are set to
/usr/local and there is a directory /usr/local/lib/python1.5/site-packages
with three subdirectories, foo, bar and spam, and two path
configuration files, foo.pth and bar.pth.  Assume foo.pth contains the
following:

  # foo package configuration
  foo
  bar
  bletch

and bar.pth contains:

  # bar package configuration
  bar

Then the following directories are added to sys.path, in this order:

  /usr/local/lib/python1.5/site-packages/bar
  /usr/local/lib/python1.5/site-packages/foo

Note that bletch is omitted because it doesn't exist; bar precedes foo
because bar.pth comes alphabetically before foo.pth; and spam is
omitted because it is not mentioned in either path configuration file.

After these path manipulations, an attempt is made to import a module
named sitecustomize, which can perform arbitrary additional
site-specific customizations.  If this import fails with an
ImportError exception, it is silently ignored.

Function Documentation

def site.addpackage (   sitedir,
  name 
)

Definition at line 132 of file site.py.

References makepath(), and aifc.open().

133 def addpackage(sitedir, name):
134  global _dirs_in_sys_path
135  if _dirs_in_sys_path is None:
136  _init_pathinfo()
137  reset = 1
138  else:
139  reset = 0
140  fullname = os.path.join(sitedir, name)
141  try:
142  f = open(fullname)
143  except IOError:
144  return
145  while 1:
146  dir = f.readline()
147  if not dir:
148  break
149  if dir[0] == '#':
150  continue
151  if dir.startswith("import"):
152  exec dir
153  continue
154  if dir[-1] == '\n':
155  dir = dir[:-1]
156  dir, dircase = makepath(sitedir, dir)
157  if not _dirs_in_sys_path.has_key(dircase) and os.path.exists(dir):
158  sys.path.append(dir)
159  _dirs_in_sys_path[dircase] = 1
160  if reset:
161  _dirs_in_sys_path = None
def site.addsitedir (   sitedir)

Definition at line 111 of file site.py.

References addpackage(), and makepath().

112 def addsitedir(sitedir):
113  global _dirs_in_sys_path
114  if _dirs_in_sys_path is None:
115  _init_pathinfo()
116  reset = 1
117  else:
118  reset = 0
119  sitedir, sitedircase = makepath(sitedir)
120  if not _dirs_in_sys_path.has_key(sitedircase):
121  sys.path.append(sitedir) # Add path component
122  try:
123  names = os.listdir(sitedir)
124  except os.error:
125  return
126  names.sort()
127  for name in names:
128  if name[-4:] == os.extsep + "pth":
129  addpackage(sitedir, name)
130  if reset:
131  _dirs_in_sys_path = None
def site.makepath (   paths)

Definition at line 63 of file site.py.

63 
64 def makepath(*paths):
65  dir = os.path.abspath(os.path.join(*paths))
66  return dir, os.path.normcase(dir)

Variable Documentation

_dirs_in_sys_path = {}

Definition at line 75 of file site.py.

string encoding = "ascii"

Definition at line 288 of file site.py.

string exit = 'Use Cmd-Q to quit.'

Definition at line 185 of file site.py.

tuple here = os.path.dirname(os.__file__)

Definition at line 263 of file site.py.

list L = []

Definition at line 74 of file site.py.

tuple loc = locale.getdefaultlocale()

Definition at line 293 of file site.py.

list prefixes = [sys.prefix]

Definition at line 162 of file site.py.

tuple s = "build/lib.%s-%.3s"

Definition at line 97 of file site.py.

list sitedirs
Initial value:
1 = [os.path.join(prefix,
2  "lib",
3  "python" + sys.version[:3],
4  "site-packages"),
5  os.path.join(prefix, "lib", "site-python")]

Definition at line 168 of file site.py.