Back to index

enigmail  1.4.3
Public Member Functions | Public Attributes
build.xpccheck.srcManifestParser Class Reference
Inheritance diagram for build.xpccheck.srcManifestParser:
Inheritance graph
[legend]
Collaboration diagram for build.xpccheck.srcManifestParser:
Collaboration graph
[legend]

List of all members.

Public Member Functions

def __init__
def getRelativeRoot
def read
def query
 methods for querying manifests
def get
def missing
def manifests
def write
 methods for outputting from manifests
def copy
def update

Public Attributes

 testroot
 tests
 strict
 rootdir
 relativeRoot

Detailed Description

Definition at line 49 of file xpccheck.py.


Constructor & Destructor Documentation

def build.xpccheck.srcManifestParser.__init__ (   self,
  manifests = (),
  defaults = None,
  strict = True,
  testroot = None 
)

Definition at line 50 of file xpccheck.py.

00050 
00051   def __init__(self, manifests=(), defaults=None, strict=True, testroot=None):
00052     self.testroot = testroot
00053     manifestparser.ManifestParser.__init__(self, manifests, defaults, strict)


Member Function Documentation

def build.manifestparser.ManifestParser.copy (   self,
  directory,
  rootdir = None,
  tags,
  kwargs 
) [inherited]
copy the manifests and associated tests
- directory : directory to copy to
- rootdir : root directory to copy to (if not given from manifests)
- tags : keywords the tests must have
- kwargs : key, values the tests must match

Definition at line 639 of file manifestparser.py.

00639 
00640     def copy(self, directory, rootdir=None, *tags, **kwargs):
00641         """
00642         copy the manifests and associated tests
00643         - directory : directory to copy to
00644         - rootdir : root directory to copy to (if not given from manifests)
00645         - tags : keywords the tests must have
00646         - kwargs : key, values the tests must match
00647         """
00648         # XXX note that copy does *not* filter the tests out of the
00649         # resulting manifest; it just stupidly copies them over.
00650         # ideally, it would reread the manifests and filter out the
00651         # tests that don't match *tags and **kwargs
00652         
00653         # destination
00654         if not os.path.exists(directory):
00655             os.path.makedirs(directory)
00656         else:
00657             # sanity check
00658             assert os.path.isdir(directory)
00659 
00660         # tests to copy
00661         tests = self.get(tags=tags, **kwargs)
00662         if not tests:
00663             return # nothing to do!
00664 
00665         # root directory
00666         if rootdir is None:
00667             rootdir = self.rootdir
00668 
00669         # copy the manifests + tests
00670         manifests = [relpath(manifest, rootdir) for manifest in self.manifests()]
00671         for manifest in manifests:
00672             destination = os.path.join(directory, manifest)
00673             dirname = os.path.dirname(destination)
00674             if not os.path.exists(dirname):
00675                 os.makedirs(dirname)
00676             else:
00677                 # sanity check
00678                 assert os.path.isdir(dirname)
00679             shutil.copy(os.path.join(rootdir, manifest), destination)
00680         for test in tests:
00681             if os.path.isabs(test['name']):
00682                 continue
00683             source = test['path']
00684             if not os.path.exists(source):
00685                 print >> sys.stderr, "Missing test: '%s' does not exist!" % source
00686                 continue
00687                 # TODO: should err on strict
00688             destination = os.path.join(directory, relpath(test['path'], rootdir))
00689             shutil.copy(source, destination)
00690             # TODO: ensure that all of the tests are below the from_dir

Here is the call graph for this function:

def build.manifestparser.ManifestParser.get (   self,
  _key = None,
  inverse = False,
  tags = None,
  tests = None,
  kwargs 
) [inherited]

Definition at line 515 of file manifestparser.py.

00515 
00516     def get(self, _key=None, inverse=False, tags=None, tests=None, **kwargs):
00517         # TODO: pass a dict instead of kwargs since you might hav
00518         # e.g. 'inverse' as a key in the dict
00519 
00520         # TODO: tags should just be part of kwargs with None values
00521         # (None == any is kinda weird, but probably still better)
00522 
00523         # fix up tags
00524         if tags:
00525             tags = set(tags)
00526         else:
00527             tags = set()
00528 
00529         # make some check functions
00530         if inverse:
00531             has_tags = lambda test: not tags.intersection(test.keys())
00532             def dict_query(test):
00533                 for key, value in kwargs.items():
00534                     if test.get(key) == value:
00535                         return False
00536                 return True
00537         else:
00538             has_tags = lambda test: tags.issubset(test.keys())
00539             def dict_query(test):
00540                 for key, value in kwargs.items():
00541                     if test.get(key) != value:
00542                         return False
00543                 return True
00544 
00545         # query the tests
00546         tests = self.query(has_tags, dict_query, tests=tests)
00547 
00548         # if a key is given, return only a list of that key
00549         # useful for keys like 'name' or 'path'
00550         if _key:
00551             return [test[_key] for test in tests]
00552 
00553         # return the tests
00554         return tests

Here is the call graph for this function:

Here is the caller graph for this function:

Reimplemented from build.manifestparser.ManifestParser.

Definition at line 54 of file xpccheck.py.

00054 
00055   def getRelativeRoot(self, here):
00056     if self.testroot is None:
00057         return manifestparser.ManifestParser.getRelativeRoot(self, self.rootdir)
00058     return self.testroot
00059 

def build.manifestparser.ManifestParser.manifests (   self,
  tests = None 
) [inherited]
return manifests in order in which they appear in the tests

Definition at line 562 of file manifestparser.py.

00562 
00563     def manifests(self, tests=None):
00564         """
00565         return manifests in order in which they appear in the tests
00566         """
00567         if tests is None:
00568             tests = self.tests
00569         manifests = []
00570         for test in tests:
00571             manifest = test.get('manifest')
00572             if not manifest:
00573                 continue
00574             if manifest not in manifests:
00575                 manifests.append(manifest)
00576         return manifests

Here is the call graph for this function:

Here is the caller graph for this function:

def build.manifestparser.ManifestParser.missing (   self,
  tests = None 
) [inherited]
return list of tests that do not exist on the filesystem

Definition at line 555 of file manifestparser.py.

00555 
00556     def missing(self, tests=None):
00557         """return list of tests that do not exist on the filesystem"""
00558         if tests is None:
00559             tests = self.tests
00560         return [test for test in tests
00561                 if not os.path.exists(test['path'])]

def build.manifestparser.ManifestParser.query (   self,
  checks,
  kw 
) [inherited]

methods for querying manifests

general query function for tests
- checks : callable conditions to test if the test fulfills the query

Definition at line 498 of file manifestparser.py.

00498 
00499     def query(self, *checks, **kw):
00500         """
00501         general query function for tests
00502         - checks : callable conditions to test if the test fulfills the query
00503         """
00504         tests = kw.get('tests', None)
00505         if tests is None:
00506             tests = self.tests
00507         retval = []
00508         for test in tests:
00509             for check in checks:
00510                 if not check(test):
00511                     break
00512             else:
00513                 retval.append(test)
00514         return retval

Here is the caller graph for this function:

def build.manifestparser.ManifestParser.read (   self,
  filenames,
  defaults 
) [inherited]

Definition at line 436 of file manifestparser.py.

00436 
00437     def read(self, *filenames, **defaults):
00438 
00439         # ensure all files exist
00440         missing = [ filename for filename in filenames
00441                     if not os.path.exists(filename) ]
00442         if missing:
00443             raise IOError('Missing files: %s' % ', '.join(missing))
00444 
00445         # process each file
00446         for filename in filenames:
00447 
00448             # set the per file defaults
00449             defaults = defaults.copy() or self._defaults.copy()
00450             here = os.path.dirname(os.path.abspath(filename))
00451             defaults['here'] = here
00452 
00453             if self.rootdir is None:
00454                 # set the root directory
00455                 # == the directory of the first manifest given
00456                 self.rootdir = here
00457 
00458             # read the configuration
00459             sections = read_ini(fp=filename, variables=defaults, strict=self.strict)
00460 
00461             # get the tests
00462             for section, data in sections:
00463 
00464                 # a file to include
00465                 # TODO: keep track of included file structure:
00466                 # self.manifests = {'manifest.ini': 'relative/path.ini'}
00467                 if section.startswith('include:'):
00468                     include_file = section.split('include:', 1)[-1]
00469                     include_file = normalize_path(include_file)
00470                     if not os.path.isabs(include_file):
00471                         include_file = os.path.join(self.getRelativeRoot(here), include_file)
00472                     if not os.path.exists(include_file):
00473                         if self.strict:
00474                             raise IOError("File '%s' does not exist" % include_file)
00475                         else:
00476                             continue
00477                     include_defaults = data.copy()
00478                     self.read(include_file, **include_defaults)
00479                     continue
00480 
00481                 # otherwise an item
00482                 test = data
00483                 test['name'] = section
00484                 test['manifest'] = os.path.abspath(filename)
00485 
00486                 # determine the path
00487                 path = test.get('path', section)
00488                 if '://' not in path: # don't futz with URLs
00489                     path = normalize_path(path)
00490                     if not os.path.isabs(path):
00491                         path = os.path.join(here, path)
00492                 test['path'] = path
00493 
00494                 # append the item
00495                 self.tests.append(test)

Here is the call graph for this function:

Here is the caller graph for this function:

def build.manifestparser.ManifestParser.update (   self,
  from_dir,
  rootdir = None,
  tags,
  kwargs 
) [inherited]
update the tests as listed in a manifest from a directory
- from_dir : directory where the tests live
- rootdir : root directory to copy to (if not given from manifests)
- tags : keys the tests must have
- kwargs : key, values the tests must match

Definition at line 691 of file manifestparser.py.

00691 
00692     def update(self, from_dir, rootdir=None, *tags, **kwargs):
00693         """
00694         update the tests as listed in a manifest from a directory
00695         - from_dir : directory where the tests live
00696         - rootdir : root directory to copy to (if not given from manifests)
00697         - tags : keys the tests must have
00698         - kwargs : key, values the tests must match
00699         """
00700     
00701         # get the tests
00702         tests = self.get(tags=tags, **kwargs)
00703 
00704         # get the root directory
00705         if not rootdir:
00706             rootdir = self.rootdir
00707 
00708         # copy them!
00709         for test in tests:
00710             if not os.path.isabs(test['name']):
00711                 _relpath = relpath(test['path'], rootdir)
00712                 source = os.path.join(from_dir, _relpath)
00713                 if not os.path.exists(source):
00714                     # TODO err on strict
00715                     print >> sys.stderr, "Missing test: '%s'; skipping" % test['name']
00716                     continue
00717                 destination = os.path.join(rootdir, _relpath)
00718                 shutil.copy(source, destination)
00719 

Here is the call graph for this function:

def build.manifestparser.ManifestParser.write (   self,
  fp = sys.stdout,
  rootdir = None,
  global_tags = None,
  global_kwargs = None,
  local_tags = None,
  local_kwargs = None 
) [inherited]

methods for outputting from manifests

write a manifest given a query
global and local options will be munged to do the query
globals will be written to the top of the file
locals (if given) will be written per test

Definition at line 581 of file manifestparser.py.

00581 
00582               local_tags=None, local_kwargs=None):
00583         """
00584         write a manifest given a query
00585         global and local options will be munged to do the query
00586         globals will be written to the top of the file
00587         locals (if given) will be written per test
00588         """
00589 
00590         # root directory
00591         if rootdir is None:
00592             rootdir = self.rootdir
00593 
00594         # sanitize input
00595         global_tags = global_tags or set()
00596         local_tags = local_tags or set()
00597         global_kwargs = global_kwargs or {}
00598         local_kwargs = local_kwargs or {}
00599         
00600         # create the query
00601         tags = set([])
00602         tags.update(global_tags)
00603         tags.update(local_tags)
00604         kwargs = {}
00605         kwargs.update(global_kwargs)
00606         kwargs.update(local_kwargs)
00607 
00608         # get matching tests
00609         tests = self.get(tags=tags, **kwargs)
00610 
00611         # print the .ini manifest
00612         if global_tags or global_kwargs:
00613             print >> fp, '[DEFAULT]'
00614             for tag in global_tags:
00615                 print >> fp, '%s =' % tag
00616             for key, value in global_kwargs.items():
00617                 print >> fp, '%s = %s' % (key, value)
00618             print >> fp
00619 
00620         for test in tests:
00621             test = test.copy() # don't overwrite
00622 
00623             path = test['name']
00624             if not os.path.isabs(path):
00625                 path = denormalize_path(relpath(test['path'], self.rootdir))
00626             print >> fp, '[%s]' % path
00627           
00628             # reserved keywords:
00629             reserved = ['path', 'name', 'here', 'manifest']
00630             for key in sorted(test.keys()):
00631                 if key in reserved:
00632                     continue
00633                 if key in global_kwargs:
00634                     continue
00635                 if key in global_tags and not test[key]:
00636                     continue
00637                 print >> fp, '%s = %s' % (key, test[key])
00638             print >> fp

Here is the call graph for this function:

Here is the caller graph for this function:


Member Data Documentation

Definition at line 429 of file manifestparser.py.

Definition at line 428 of file manifestparser.py.

Definition at line 427 of file manifestparser.py.

Definition at line 51 of file xpccheck.py.

Definition at line 426 of file manifestparser.py.


The documentation for this class was generated from the following file: