Skip to content

Instantly share code, notes, and snippets.

@jsocol
Created September 26, 2011 15:38
Show Gist options
  • Select an option

  • Save jsocol/1242521 to your computer and use it in GitHub Desktop.

Select an option

Save jsocol/1242521 to your computer and use it in GitHub Desktop.
Moxie report generator
#!/usr/bin/env python
"""Written for Python 2.5. If 2.6, remove the from __future__ import."""
from __future__ import with_statement
import optparse
import os
import stat
import sys
TEMPLATE = """<?php
require_once dirname(dirname(dirname(__FILE__))).'/project.inc.php';
/**
* Report configuration file
* Must extend project class
*/
class sumo%(year)s%(month)s%(day)s extends sumo {
// ID for files and classes
public $reportID = 'sumo%(year)s%(month)s%(day)s';
// Short name for report URL
public $reportName = '%(year)s-%(month)s-%(day)s';
// Pretty name to display for report
public $reportDisplayName = '%(year)s-%(month)s-%(day)s';
// Bugzilla query for the report
public $queryString = 'buglist.cgi?query_format=advanced&product=support.moz illa.com&target_milestone=%(year)s-%(month)s-%(day)s';
// Code freeze date
public $codeFreeze = '2010-08-13';
// Launch date
public $launch = '2010-08-18';
// Summary of release
public $summary = '[Kitsune] Discussion Forum Tweaks';
}
"""
ROOT = os.path.dirname(os.path.abspath(__file__))
path = lambda *a: os.path.join(ROOT, *a)
def dir_name(year, month, day):
return 'sumo%s%s%s' % (year, month, day)
def make_dir(year, month, day):
dir = path(dir_name(year, month, day))
os.mkdir(dir)
os.chmod(dir, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO)
def make_file(year, month, day):
filename = 'report.inc.php'
with open(path(dir_name(year, month, day), filename), 'w') as fp:
fp.write(TEMPLATE % {
'year': year,
'month': month,
'day': day,
})
def usage(argv=None):
if argv is None:
argv = sys.argv
print "USAGE %s <year> <month> <day>" % argv[0]
def main():
parser = optparse.OptionParser()
try:
(_, (year, month, day)) = parser.parse_args()
except ValueError:
usage()
sys.exit(1)
make_dir(year, month, day)
make_file(year, month, day)
if __name__ == '__main__':
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment