Analyse an Nginx access log with awk and produce a report
The biggest problem, and the hardest to fix, is calling awk, sort | uniq -c | sort -r, sometimes within a loop, when you could implement all that more efficiently in Python. It's ugly to do this in multiple sub-shells and multiple processes. But that would take a substantial rewrite.



You are not using the class attributes here:


class NginxReporter():

    location = None
    template = 'templates/default.html'
    html = None



So you could just delete these from your class.



The constructor is not well designed. You're trying to do too much, for two very different use cases:


In one use case, you use it just to set a logfile location, and then you call other methods to do the real work
In another use case, the constructor would call the other methods


It's better to decide one of these ways, stick with it, and simplify the code accordingly.



This method is strange:


def scpdownload(self, remotelocation=None):
    if remotelocation:
        check_output(['scp', remotelocation, self.location])



You allow calling it without params, or null param, to do nothing? This is messy and confusing. It would be better to require a param.

Btw, downloading a file with scp doesn't sound like it belongs to the class. It violates the single responsibility principle: a class should have one clear purpose (parse nginx log files), and nothing else.



This could use some reworking:


if out == '' and output.poll() != None:
    break
if out != '':
    block = out



Like this:

if not out:
    if not output.poll():
        break
else:
    block = out




You open a file for reading but you're not closing it:


file = open(self.template)
block = Template(file.read())
print block.substitute(self.html)



The right way to do is using with:

with open(self.template) as fh:
    block = Template(fh.read())
    print block.substitute(self.html)


I also renamed file to fh because file is a class in Python 2.x



If you want to temporarily comment out one line,
it's better to use # instead of """ ... """ which is recommended for multi-line comments and docstrings:

report = NginxReporter('access.log')
#report.scpdownload("sshuser@server.com:/path/to/nginx/access.log")
report.parse()
report.output()