Commits

Lynn Rees committed e483236

- final comments

Comments (0)

Files changed (3)

 
     def __repr__(self):
         '''Represent class as XML'''
-        pprint(self._doc)    
+        return self.tostring()    
 
     def _collection(self, cn, pn=None):
         '''makes a PSI collection element
 __version__ = '0.03-test'
 __author__ = 'L.C. Rees (xanimal@users.sf.net)'
 
-''''''
+'''A command line utility for generating PSI maps. Output can be modified by
+passing different options at the command line.'''
 
-## Import generators
+# Import generators
 from generators import *
-## psyco optimizations
+# psyco optimizations
 try:
+    # psycho is a performance optimizer for pyton
     import psyco
+    # Turns on the psyco Just in Time compiler
     psyco.jit()
     from psyco.classes import psymetaclass, psyobj
+    # psyco is run on key functions in Autogenerator
     pl = (Autogenerator._walkDirectory, Autogenerator._mapNested,
           Autogenerator._mapFlat, Autogenerator._walkFile,
           Autogenerator._walkHttp, Autogenerator._walkHtml,
 def psimake():
     '''Generates PSI map from CLI'''    
 
-    def quit(x):
-        y = x.lower()
-        if y == 'q':
+    def quit(message):
+        '''Quits and prints help message'''
+        # make response lowercase
+        message = message.lower()
+        # If it's time to quit, exit and pring usage message
+        if message == 'q':
             print usage
             sys.exit()
 
-    def sa(x):
-        ## Confirm input is supported
-        if x.find('http') != -1:
+    def issupported(item):
+        '''Verifies an input source is supported'''
+        # Verifies that HTTP is supported
+        if item.find('http') != -1:
             print 'Processing source...'
-            return x
-        elif x.find('ftp') != -1:
+            return item
+        # Verifies that FTP is supported
+        elif item.find('ftp') != -1:
             print 'Processing source...'
-            return x
-        elif os.path.isfile(x) and not isarc(x):
+            return item
+        # Verifies that a file is an archive. If not, it's unsupported
+        elif os.path.isfile(item) and not isarc(item):
             print "Invalid argument: source must be directory or archive"
             quit('q')
+        # Default
         else:
             print 'Processing source...'
-            return x
+            return item
         
     def truepath():
-        ## Ensure msg doesn't display twice
-        try: fc = uv
+        # Ensure usage message doesn't display twice
+        try: flag = usageviews
         except NameError: print msg
-        ## Prompt for archive and destination information
+        # Prompt for archive and destination information
         print 'Invalid argument: no destination specified'
         name2 = raw_input('Make PSI archive? (yes/no): ')
         name2 = name2.lower()
         quit(name2)
+        # Choose archive or raw XML
         if name2 == 'no':
             name2 = raw_input('Enter destination name: ')
             quit(name2)
       -r            recursively scan children of SOURCE
       -x            embed XHTML from SOURCE inside PSI map
       -z            map contents of archives from SOURCE inside PSI map'''
+    # Compression, recursive, archive, and embed HTML flags for autogenerator 
     com, rec, arc, htm = 0, 0, 0, 0
-    msg = 'Press "q" to quit, view online help'
-    ## Iterate over CLI arguments
-    for s in sys.argv:
-        if s != sys.argv[0]:
-            if s.find('-h') != -1: quit('q')
-            elif s.find('-a') != -1: com = 1
-            elif s.find('-r') != -1: rec = 'dorec'
-            elif s.find('-z') != -1: arc = 'doarc'
-            elif s.find('-x') != -1: htm = 'dohtm'
+    # Quitting prompt
+    msg = 'Press "q" to quit and view online help'
+    # Iterate over CLI options passed to makepsi
+    for item in sys.argv:
+        if item != sys.argv[0]:
+            # Quit if found
+            if item.find('-h') != -1: quit('q')
+            # Compress PSI map if fount
+            elif item.find('-a') != -1: com = 1
+            # Do a recursive scan if found
+            elif item.find('-r') != -1: rec = 'dorec'
+            # Scan archive contents if found
+            elif item.find('-z') != -1: arc = 'doarc'
+            # Embed HTML if found
+            elif item.find('-x') != -1: htm = 'dohtm'
+            # Extrace source and destination paths
             else:
                 try:
-                    if dir(name1): name2 = s
-                except NameError: name1 = s
-    ## Assign input if specified at CLI
-    try: src = sa(name1)
-    ## Prompt for input name if not specified at CLI
+                    if dir(name1): name2 = item
+                except NameError: name1 = item
+    # Assign input if specified at CLI
+    try: src = issupported(name1)
+    # Prompt for input name if not specified at CLI
     except NameError:
         print msg
-        uv = 1
+        # Only prompt once for quitting
+        usageviews = 1
         print 'Invalid argument: no source specified'
         name1 = raw_input('Enter source name: ')
         quit(name1)
-        src = sa(name1)
-    ## Check if compressed XML requested at CLI
+        src = issupported(name1)
+    # Check if compressed XML requested at CLI
     if com == 1:
         try: dest = name2
         except NameError:
             print 'Invalid argument: -a: no archive name found'
             dest = truepath()
-    ## If compressed XML was not requested, default to raw XML
+    # If compressed XML was not requested, default to raw XML
     else:
         try:
             if dir(name2): dest = name2
         except NameError: dest = truepath()    
-    ## Make raw or compressed PSI maps as directed
+    # Make raw or compressed PSI maps as directed
     if com == 1:
         print 'Generating PSI archive...'
         psi = Autogenerator(src, dest, rec, arc, htm)
         psi.toxml()
     print 'Processing complete'
 
+# Run
 if __name__ == '__main__': psimake()
+'''Library for PSI maps'''
+
+__title__ = 'test_som'
+__version__ = '0.03-test'
+__author__  = 'L. C. Rees (xanimal@users.sf.net)'
+
+'''Tests SOM functionality in a structured way'''
+
 from som import *
 
 def testSom():
     '''Test if all of SOM is functioning properly'''
-    d = Root()
-    p = Psi()
-    e = Collection('test', 'test', 'test')
-    p.appendChild(e)
-    e.addFilter('test', 'test', 'test')
-    e.filters[0].addAction('read', 'test', 'test')
-    e.filters[0].addAccess('grant', 'test', 'test')
-    e.filters[0].addSort('par', 'test')
-    e.filters[0].acl[0].addRight('read')
-    e.filters[0].actions[0].addIf('test', 'test')
-    e.filters[0].actions[0].setTime('day','5', '10', '11', '5')
-    e.filters[0].addVersion('archive', 'seq')
-    e.filters[0].setTime('week')
-    e.filters[0].versions[0].addChange('name', 'test')
-    e.addCollection('test2', 'thing', 'stuff')
-    e.addField('thing')
-    e.addResource('thing', 'thing', 'thing')
-    e.addFilter('thing', 'thing')
-    e.addCollection('thing3')
-    e.addLink('test')
-    e.addInclude('thing')
-    e.addResource('test')
-    e.resources[0].addResult('test')
-    e.resources[0].setMetadata('planned')
-    e.resources[0].metadata.addLog('read', 'planned', '10', '20', 'dude', 'test')
-    e.resources[0].addFragment('test')
-    e.resources[0].addText('some', 'some', 'some', 'preserve', 'some')
-    e.resources[0].addException('test')
-    e.resources[0].addParameter('test')
-    e.resources[0].addResult('test2')
-    e.resources[0].addFilter('test')
-    e.resources[0].filters[0].addAccess('grant', 'ssl', 'dude')
-    e.resources[0].filters[0].acl[0].addRight('read')
-    e.resources[0].addLink('something')
-    e.resources[0].addParameter('test2')
-    e.resources[0].addField('test')
-    e.resources[0].addFragment('test2')
-    e.resources[0].addField('something')
-    e.resources[0].addException('thing', 'thing', 'thing')
-    e.resources[0].addInclude('test')
-    e.resources[0].addResult('test3')
-    e.setMetadata()
-    e.addCollection('test3')
-    d.appendChild(p)
-    print d       
+    test = Collection('test', 'test', 'test')
+    test.addFilter('test', 'test', 'test')
+    test.filters[0].addAction('read', 'test', 'test')
+    test.filters[0].addAccess('grant', 'test', 'test')
+    test.filters[0].addSort('par', 'test')
+    test.filters[0].acl[0].addRight('read')
+    test.filters[0].actions[0].addIf('test', 'test')
+    test.filters[0].actions[0].setTime('day','5', '10', '11', '5')
+    test.filters[0].addVersion('archive', 'seq')
+    test.filters[0].setTime('week')
+    test.filters[0].versions[0].addChange('name', 'test')
+    test.addCollection('test2', 'thing', 'stuff')
+    test.addField('thing')
+    test.addResource('thing', 'thing', 'thing')
+    test.addFilter('thing', 'thing')
+    test.addCollection('thing3')
+    test.addLink('test')
+    test.addInclude('thing')
+    test.addResource('test')
+    test.resources[0].addResult('test')
+    test.resources[0].setMetadata('planned')
+    test.resources[0].metadata.addLog('read', 'planned', '10', '20', 'dude', 'test')
+    test.resources[0].addFragment('test')
+    test.resources[0].addText('some', 'some', 'some', 'preserve', 'some')
+    test.resources[0].addException('test')
+    test.resources[0].addParameter('test')
+    test.resources[0].addResult('test2')
+    test.resources[0].addFilter('test')
+    test.resources[0].filters[0].addAccess('grant', 'ssl', 'dude')
+    test.resources[0].filters[0].acl[0].addRight('read')
+    test.resources[0].addLink('something')
+    test.resources[0].addParameter('test2')
+    test.resources[0].addField('test')
+    test.resources[0].addFragment('test2')
+    test.resources[0].addField('something')
+    test.resources[0].addException('thing', 'thing', 'thing')
+    test.resources[0].addInclude('test')
+    test.resources[0].addResult('test3')
+    test.setMetadata()
+    test.addCollection('test3')
+    document = Root()
+    psi = Psi()
+    psi.appendChild(test)
+    document.appendChild(psi)
+    print document       
 
 if __name__ == '__main__': testSom()