Back to index

enigmail  1.4.3
Classes | Functions | Variables
build.manifestparser Namespace Reference

Classes

class  ident_token
class  literal_token
class  eq_op_token
class  neq_op_token
class  not_op_token
class  and_op_token
class  or_op_token
class  lparen_token
class  rparen_token
class  end_token
class  bool_token
class  int_token
class  string_token
class  ParseError
class  ExpressionParser
class  ManifestParser
 objects for parsing manifests More...
class  TestManifest
class  ParserError
 command line attributes More...
class  CLICommand
 classes for subcommands More...
class  Copy
class  CreateCLI
class  WriteCLI
class  HelpCLI
class  SetupCLI
class  UpdateCLI

Functions

def relpath
def parse
def normalize_path
def denormalize_path
def read_ini
def convert
def parse_args
def main

Variables

list __all__
string version = '0.5.3'
 setup = None
 relpath = os.path.relpath
list precedence
dictionary commands

Class Documentation

class build::manifestparser::rparen_token

Definition at line 170 of file manifestparser.py.

class build::manifestparser::end_token
always ends parsing

Definition at line 173 of file manifestparser.py.

class build::manifestparser::ParseError
errror parsing conditional expression

Definition at line 201 of file manifestparser.py.

class build::manifestparser::ParserError

command line attributes

error for exceptions while parsing the command line

Definition at line 848 of file manifestparser.py.


Function Documentation

def build.manifestparser.convert (   directories,
  pattern = None,
  ignore = (),
  write = None 
)
convert directories to a simple manifest

Definition at line 798 of file manifestparser.py.

00798 
00799 def convert(directories, pattern=None, ignore=(), write=None):
00800     """
00801     convert directories to a simple manifest
00802     """
00803 
00804     retval = []
00805     include = []
00806     for directory in directories:
00807         for dirpath, dirnames, filenames in os.walk(directory):
00808 
00809             # filter out directory names
00810             dirnames = [ i for i in dirnames if i not in ignore ]
00811             dirnames.sort()
00812 
00813             # reference only the subdirectory
00814             _dirpath = dirpath
00815             dirpath = dirpath.split(directory, 1)[-1].strip(os.path.sep)
00816 
00817             if dirpath.split(os.path.sep)[0] in ignore:
00818                 continue
00819 
00820             # filter by glob
00821             if pattern:
00822                 filenames = [filename for filename in filenames
00823                              if fnmatch(filename, pattern)]
00824 
00825             filenames.sort()
00826 
00827             # write a manifest for each directory
00828             if write and (dirnames or filenames):
00829                 manifest = file(os.path.join(_dirpath, write), 'w')
00830                 for dirname in dirnames:
00831                     print >> manifest, '[include:%s]' % os.path.join(dirname, write)
00832                 for filename in filenames:
00833                     print >> manifest, '[%s]' % filename
00834                 manifest.close()
00835 
00836             # add to the list
00837             retval.extend([denormalize_path(os.path.join(dirpath, filename))
00838                            for filename in filenames])
00839 
00840     if write:
00841         return # the manifests have already been written!
00842   
00843     retval.sort()
00844     retval = ['[%s]' % filename for filename in retval]
00845     return '\n'.join(retval)

Here is the call graph for this function:

Here is the caller graph for this function:

denormalize a relative path

Definition at line 312 of file manifestparser.py.

00312 
00313 def denormalize_path(path):
00314     """denormalize a relative path"""
00315     if sys.platform.startswith('win'):
00316         return path.replace(os.path.sep, '/')
00317     return path
00318     

Here is the call graph for this function:

Here is the caller graph for this function:

def build.manifestparser.main (   args = sys.argv[1:])
console_script entry point

Definition at line 1085 of file manifestparser.py.

01085 
01086 def main(args=sys.argv[1:]):
01087     """console_script entry point"""
01088 
01089     # set up an option parser
01090     usage = '%prog [options] [command] ...'
01091     description = __doc__
01092     parser = OptionParser(usage=usage, description=description)
01093     parser.add_option('-s', '--strict', dest='strict',
01094                       action='store_true', default=False,
01095                       help='adhere strictly to errors')
01096     parser.disable_interspersed_args()
01097 
01098     options, args = parser.parse_args(args)
01099 
01100     if not args:
01101         HelpCLI(parser)(options, args)
01102         parser.exit()
01103 
01104     # get the command
01105     command = args[0]
01106     if command not in commands:
01107         parser.error("Command must be one of %s (you gave '%s')" % (', '.join(sorted(commands.keys())), command))
01108 
01109     handler = commands[command](parser)
01110     handler(options, args[1:])

normalize a relative path

Definition at line 306 of file manifestparser.py.

00306 
00307 def normalize_path(path):
00308     """normalize a relative path"""
00309     if sys.platform.startswith('win'):
00310         return path.replace('/', os.path.sep)
00311     return path

Here is the caller graph for this function:

def build.manifestparser.parse (   text,
  values 
)
Parse and evaluate a boolean expression in |text|. Use |values| to look
up the value of identifiers referenced in the expression. Returns the final
value of the expression. A ParseError will be raised if parsing fails.

Definition at line 298 of file manifestparser.py.

00298 
00299 def parse(text, **values):
00300     """
00301     Parse and evaluate a boolean expression in |text|. Use |values| to look
00302     up the value of identifiers referenced in the expression. Returns the final
00303     value of the expression. A ParseError will be raised if parsing fails.
00304     """
00305     return ExpressionParser(text, values).parse()

Here is the caller graph for this function:

parse and return:
--keys=value (or --key value)
-tags
args

Definition at line 851 of file manifestparser.py.

00851 
00852 def parse_args(_args):
00853     """
00854     parse and return:
00855     --keys=value (or --key value)
00856     -tags
00857     args
00858     """
00859 
00860     # return values
00861     _dict = {}
00862     tags = []
00863     args = []
00864 
00865     # parse the arguments
00866     key = None
00867     for arg in _args:
00868         if arg.startswith('---'):
00869             raise ParserError("arguments should start with '-' or '--' only")
00870         elif arg.startswith('--'):
00871             if key:
00872                 raise ParserError("Key %s still open" % key)
00873             key = arg[2:]
00874             if '=' in key:
00875                 key, value = key.split('=', 1)
00876                 _dict[key] = value
00877                 key = None
00878                 continue
00879         elif arg.startswith('-'):
00880             if key:
00881                 raise ParserError("Key %s still open" % key)
00882             tags.append(arg[1:])
00883             continue
00884         else:
00885             if key:
00886                 _dict[key] = arg
00887                 continue
00888             args.append(arg)
00889 
00890     # return values
00891     return (_dict, tags, args)
00892 

Here is the caller graph for this function:

def build.manifestparser.read_ini (   fp,
  variables = None,
  default = 'DEFAULT',
  comments = ';#',
  separators = ('=', ':',
  strict = True 
)
read an .ini file and return a list of [(section, values)]
- fp : file pointer or path to read
- variables : default set of variables
- default : name of the section for the default section
- comments : characters that if they start a line denote a comment
- separators : strings that denote key, value separation in order
- strict : whether to be strict about parsing

Definition at line 321 of file manifestparser.py.

00321 
00322              strict=True):
00323     """
00324     read an .ini file and return a list of [(section, values)]
00325     - fp : file pointer or path to read
00326     - variables : default set of variables
00327     - default : name of the section for the default section
00328     - comments : characters that if they start a line denote a comment
00329     - separators : strings that denote key, value separation in order
00330     - strict : whether to be strict about parsing
00331     """
00332 
00333     if variables is None:
00334         variables = {}
00335 
00336     if isinstance(fp, basestring):
00337         fp = file(fp)
00338 
00339     sections = []
00340     key = value = None
00341     section_names = set([])
00342 
00343     # read the lines
00344     for line in fp.readlines():
00345 
00346         stripped = line.strip()
00347 
00348         # ignore blank lines
00349         if not stripped:
00350             # reset key and value to avoid continuation lines
00351             key = value = None
00352             continue
00353 
00354         # ignore comment lines
00355         if stripped[0] in comments:
00356             continue
00357 
00358         # check for a new section
00359         if len(stripped) > 2 and stripped[0] == '[' and stripped[-1] == ']':
00360             section = stripped[1:-1].strip()
00361             key = value = None
00362 
00363             # deal with DEFAULT section
00364             if section.lower() == default.lower():
00365                 if strict:
00366                     assert default not in section_names
00367                 section_names.add(default)
00368                 current_section = variables
00369                 continue
00370 
00371             if strict:
00372                 # make sure this section doesn't already exist
00373                 assert section not in section_names
00374 
00375             section_names.add(section)
00376             current_section = {}
00377             sections.append((section, current_section))
00378             continue
00379 
00380         # if there aren't any sections yet, something bad happen
00381         if not section_names:
00382             raise Exception('No sections found')
00383 
00384         # (key, value) pair
00385         for separator in separators:
00386             if separator in stripped:
00387                 key, value = stripped.split(separator, 1)
00388                 key = key.strip()
00389                 value = value.strip()
00390 
00391                 if strict:
00392                     # make sure this key isn't already in the section or empty
00393                     assert key
00394                     if current_section is not variables:
00395                         assert key not in current_section
00396 
00397                 current_section[key] = value
00398                 break
00399         else:
00400             # continuation line ?
00401             if line[0].isspace() and key:
00402                 value = '%s%s%s' % (value, os.linesep, stripped)
00403                 current_section[key] = value
00404             else:
00405                 # something bad happen!
00406                 raise Exception("Not sure what you're trying to do")
00407 
00408     # interpret the variables
00409     def interpret_variables(global_dict, local_dict):
00410         variables = global_dict.copy()
00411         variables.update(local_dict)
00412         return variables
00413 
00414     sections = [(i, interpret_variables(variables, j)) for i, j in sections]
00415     return sections
00416 

Here is the caller graph for this function:

def build.manifestparser.relpath (   path,
  start 
)
Return a relative version of a path
from /usr/lib/python2.6/posixpath.py

Definition at line 69 of file manifestparser.py.

00069 
00070     def relpath(path, start):
00071         """
00072         Return a relative version of a path
00073         from /usr/lib/python2.6/posixpath.py
00074         """
00075 
00076         if not path:
00077             raise ValueError("no path specified")
00078 
00079         start_list = os.path.abspath(start).split(os.path.sep)
00080         path_list = os.path.abspath(path).split(os.path.sep)
00081 
00082         # Work out how much of the filepath is shared by start and path.
00083         i = len(os.path.commonprefix([start_list, path_list]))
00084 
00085         rel_list = [os.path.pardir] * (len(start_list)-i) + path_list[i:]
00086         if not rel_list:
00087             return start
00088         return os.path.join(*rel_list)
00089 
00090 # expr.py
00091 # from:
00092 # http://k0s.org/mozilla/hg/expressionparser
00093 # http://hg.mozilla.org/users/tmielczarek_mozilla.com/expressionparser
00094 
00095 # Implements a top-down parser/evaluator for simple boolean expressions.
00096 # ideas taken from http://effbot.org/zone/simple-top-down-parsing.htm
00097 #
00098 # Rough grammar:
00099 # expr := literal
00100 #       | '(' expr ')'
00101 #       | expr '&&' expr
00102 #       | expr '||' expr
00103 #       | expr '==' expr
00104 #       | expr '!=' expr
00105 # literal := BOOL
00106 #          | INT
00107 #          | STRING
00108 #          | IDENT
00109 # BOOL   := true|false
00110 # INT    := [0-9]+
00111 # STRING := "[^"]*"
00112 # IDENT  := [A-Za-z_]\w*
00113 
00114 # Identifiers take their values from a mapping dictionary passed as the second
00115 # argument.
00116 
00117 # Glossary (see above URL for details):
00118 # - nud: null denotation
00119 # - led: left detonation
00120 # - lbp: left binding power
00121 # - rbp: right binding power


Variable Documentation

Initial value:
00001 ['read_ini', # .ini reader
00002            'ManifestParser', 'TestManifest', 'convert', # manifest handling
00003            'parse', 'ParseError', 'ExpressionParser']

Definition at line 47 of file manifestparser.py.

Initial value:
00001 { 'create': CreateCLI,
00002              'help': HelpCLI,
00003              'update': UpdateCLI,
00004              'write': WriteCLI }

Definition at line 1078 of file manifestparser.py.

Initial value:
00001 [(end_token, rparen_token),
00002               (or_op_token,),
00003               (and_op_token,),
00004               (eq_op_token, neq_op_token),
00005               (lparen_token,),
00006               ]

Definition at line 191 of file manifestparser.py.

build.manifestparser.relpath = os.path.relpath

Definition at line 67 of file manifestparser.py.

Definition at line 62 of file manifestparser.py.

string build.manifestparser.version = '0.5.3'

Definition at line 58 of file manifestparser.py.