I think i'm pretty close to understanding.  I still have a few questions 
here:

*1. You need to upload the files to the server, then parse them to get each 
dict. *

The code I have to generate my dictionaries follows this format (let's 
assume there are 3 different config formats):

parse.config_type_A(file)  ####where parse is the class, config_type_A is 
the method, and file is the file I want to parse
parse.config_type_B(file)  ####where parse is the class, config_type_B is 
the method, and file is the file I want to parse
parse.config_type_C(file)  ####where parse is the class, config_type_C is 
the method, and file is the file I want to parse

The resulting dictionary looks something like this (this is the default 
dict before the data is pulled):

self.settings = {
'filepath': 'Not Available', #File path.
'filename': 'Not Available', #Name of the file being processed.
'hostname': 'Not Available', #What is the hostname?
'model': 'Not Available', #What type of device are we looking at?
'enable': 'Not Available', #Is there an enable password?  Is it using md5 
encryption?
'domain-name': 'Not Available', #Domain name.
'username': 'Not Available', #Are user accounts using strong encryption 
(non-Cisco 7)?
'logging': 'Not Available', #Are security and event logs being collected?
'log-server': 'Not Available', #Log Servers for centralized log correlation 
and SIEM.
'aaa': 'Not Available', #AAA is advanced radius or tacacs+ based 
authentication.
'sshv2': 'Not Available', #SSHv2 is the current protocol.
'port-security':'Not Available', #SSHv2 is the current protocol.
'intf-inside': 'Not Available', #Inside Interface: Connects to the LAN.
'intf-outside': 'Not Available', #Outside Interface: Connects to the WAN.
'any-any': 'Not Available', #Any-Any Rules can allow overly permissive 
traffic.
'access-group': 'Not Available' #The access-group line ties an ACL to an 
interface.
}

What I end up with is dictionary for each config file that has all the 
relevant settings I am interested in.  I'd like to use a class to parse, 
but I'm not sure if the class should be defined in a  model, controller or 
module.

   1. Where should I define the class?
   2. If I want to insert the self.settings dict (above) is this the 
   correct syntax I need to follow (from your link)?
   
db.config_settings.bulk_insert([{'name':'Alex'}, {'name':'John'}, 
{'name':'Tim'}])

     
      3. Is there a different insert statement that would let me say 
something like..... db.config_settings.insert(self.settings) ?




*2. My feeling that you may be having issues with parsing the uploaded 
file.*

Why doesn't the following controller code work? (it gives me the following 
error: <type 'exceptions.TypeError'>(coercing to Unicode: need string or 
buffer, Row found))  What should I be using to open the files?

def showconfig():
    files = db().select(db.config_file.ALL)
    for file in files:
        if 'ASA Version' in open(file).read():
            return dict(file=file)
        else:
            return dict("Not a Firewall")









On Friday, December 27, 2013 3:07:07 PM UTC-8, Simon Ashley wrote:
>
> A little difficult to share to code (done for a client, its similar and 
> but not exactly what you're doing i.e. maybe a lot more complicated than 
> what you need), but I think you're almost there. 
>
> You need to upload the files to the server, then parse them to get each 
> dict. My understanding is that you don't have issues generating the dict 
> and there it should be a simple bulk_insert ...  
> http://web2py.com/books/default/chapter/29/06/the-database-abstraction-layer?search=bulk_insert
> .
>
> My feeling that you may be having issues with parsing the uploaded file 
> and you should be able to get the file name/ location for parsing routines 
> by following 
> http://web2py.com/books/default/chapter/29/07/forms-and-validators?search=upload#SQLFORM-and-uploads<http://www.google.com/url?q=http%3A%2F%2Fweb2py.com%2Fbooks%2Fdefault%2Fchapter%2F29%2F07%2Fforms-and-validators%3Fsearch%3Dupload%23SQLFORM-and-uploads&sa=D&sntz=1&usg=AFQjCNGXDIOqfpU4LwSIlWV5tY9VvdvhEw>
>

-- 
Resources:
- http://web2py.com
- http://web2py.com/book (Documentation)
- http://github.com/web2py/web2py (Source code)
- https://code.google.com/p/web2py/issues/list (Report Issues)
--- 
You received this message because you are subscribed to the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to