In answer to your second question: What does this code do?...
This is fairly standard error-checking code for a Python script that accepts command-line arguments.
So the first if
statement translates to: if you haven't passed me an argument, I'm going to tell you how you should pass me an argument in the future, e.g. you'll see this on-screen:
Usage: myscript.py database-name
The next if
statement checks to see if the 'database-name' you passed to the script actually exists on the filesystem. If not, you'll get a message like this:
ERROR: Database database-name was not found!
From the documentation:
argv[0] is the script name (it is
operating system dependent whether
this is a full pathname or not). If
the command was executed using the -c
command line option to the
interpreter, argv[0] is set to the
string '-c'. If no script name was
passed to the Python interpreter,
argv[0] is the empty string.