ac = ApacheConfig.File() # Instantiate a config file ac.read('test.conf') # Read test.conf ac.fid = 'test.out.conf' # Change the file so we don't overwrite on write() cmds = [ # Define sample commands: # Change ServerName at the global level 'update ServerName value www.mysite.com', # Change ServerName at all nested levels 'update ... ServerName value www.mysite.com', # Remove the global ItsABoy directive (case doesn't matter) 'delete itsAboy', # Add a Listen 8080 directive to any directive list applicable to /var/www/vhost/html; # add the directive after any AllowOverride directive 'insert ... <Directory "/var/www/vhost/html"> after AllowOverride Listen value 8080' ] ac.command(cmds) # Modify the configuration with the commands ac.dump() # Write the results to the console ac.write() # Write the results to 'test.out.conf'
Text commands resemble SQL operations: delete, insert, replace, update Argument to the command is a string if the form: command (<scope>|...)* [(BEFORE|AFTER) directive] [directive] [WHERE oldvalue] [(APPEND|PREPEND|VALUE) value] (uppercase designates keywords, not a case requirement) Commands delete Remove the specified directive. Before/after ignored; No value is required. insert Add the directive. replace Insert the directive if it does not exist; update it if it does. Before/after ignored on update. update Change the value of the directive only if it exists. Before/after ignored. Examples: replace <directory /var/www/localhost/htdocs> AllowOverride value All update <directory /var/www/localhost/htdocs> DirectoryIndex prepend index.php delete <directory /var/www/oldhost/htdocs> delete listen insert listen value 80 replace listen where 8080 value 80 insert before ServerRoot User value apache replace ... LogFormat value common Scopes are ..., Directory, DirectoryMatch, File, FileMatch, IfDef, IfModule, Location, LocationMatch, and VirtualHost. The operator (...) represents an arbitrary path.
This is still in early stages of development. The intent is to make it easy to add multiple lines to the configuration with one command. The final format will support multiple commands per file, multiple files, and possibly multiple applications and patch formats...