From 9264e6e38b7fb482f6b62eaeccd611f179abb9f5 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Sat, 26 Jun 2010 16:08:04 -0400 Subject: [PATCH] Added sc.py, a Because relative imports don't work with $ ./sitecore/prof/export_mysql.py etc. Also a number of syntax fixups and unicode -> ascii translations. --- sc.py | 14 ++++++++++++++ sitecore/__init__.py | 2 +- sitecore/alt_tags.py | 4 ++-- sitecore/prof/__init__.py | 19 ++++++++++--------- sitecore/prof/export_mysql.py | 14 ++++++-------- sitecore/prof/import.py | 7 +++---- 6 files changed, 36 insertions(+), 24 deletions(-) create mode 100755 sc.py diff --git a/sc.py b/sc.py new file mode 100755 index 0000000..22f45c1 --- /dev/null +++ b/sc.py @@ -0,0 +1,14 @@ +#!/usr/bin/python + +import sitecore + +if __name__ == '__main__': + import sys + + command = sys.argv[1] + argv = sys.argv[1:] + + mod_name = 'sitecore.' + command.replace('-', '.') + print mod_name + module = __import__(mod_name) + module.main(argv) diff --git a/sitecore/__init__.py b/sitecore/__init__.py index 72829f8..f34d0cc 100755 --- a/sitecore/__init__.py +++ b/sitecore/__init__.py @@ -37,7 +37,7 @@ try: except ImportError, e: WebDriver = e # allow some functionality without selenium -def get_logger(verbose=0) +def get_logger(verbose=0): verbosities = [ # in order of decreasing severity logging.CRITICAL, logging.ERROR, diff --git a/sitecore/alt_tags.py b/sitecore/alt_tags.py index 0948f43..a8cf1e8 100644 --- a/sitecore/alt_tags.py +++ b/sitecore/alt_tags.py @@ -51,7 +51,7 @@ def add_headshot_alt_tags(s): s.publish_section('Added alt tag for %s' % name) -if __name__ == '__main__': +def main(argv) import optparse usage = """%prog [options] @@ -59,7 +59,7 @@ Example setup before running: Xvfb :99 > /dev/null 2>&1 & export DISPLAY=:99 java -jar selenium-server-1.0.2-SNAPSHOT-standalone.jar > /dev/null 2>&1 & - ./sitecore/alt_tags.py + ./sc alt_tags """ p = optparse.OptionParser(usage) p.add_option('-u', '--url', metavar='URL', dest='url', diff --git a/sitecore/prof/__init__.py b/sitecore/prof/__init__.py index fd91f36..32bd679 100644 --- a/sitecore/prof/__init__.py +++ b/sitecore/prof/__init__.py @@ -40,9 +40,9 @@ First Name* First Name / Middle Name Last Name* Last Name Bio Brief Bio/Profile/Blurb Short Bio Presentations (If applicable) -Headshot* Photograph – Size should be width: 125px height: 150px +Headshot* Photograph - Size should be width: 125px height: 150px Email* Email -Phone* Phone # ‐ Please use this format: (111) 111‐1111 +Phone* Phone # - Please use this format: (111) 111-1111 Fax Lab Name, Lab Phone (If applicable, please use "Lab Name, Lab Phone" format) CV Resume @@ -56,7 +56,8 @@ Yearbook Advisor, etc. """ class AttributeHolder (object): - self.fields = [] + fields = [] + def __init__(self, *args, **kwargs): for field in self.fields: setattr(self, field, None) @@ -68,16 +69,16 @@ class AttributeHolder (object): class Name (AttributeHolder): - self.fields = ['first_middle', 'last'] + fields = ['first_middle', 'last'] class Graduation (AttributeHolder): - self.fields = ['college', 'title', 'year'] + fields = ['college', 'title', 'year'] class Contact (AttributeHolder): - self.fields = ['office', 'website', 'phone', 'lab', 'lab_phone'] + fields = ['office', 'website', 'phone', 'lab', 'lab_phone'] class Bio (AttributeHolder): - self.fields = ['specialization', 'publications', 'profile', 'cv'] + fields = ['specialization', 'publications', 'profile', 'cv'] -class Professor (object): - self.fields = ['name', 'graduations', 'contact', 'bio'] +class Professor (AttributeHolder): + fields = ['name', 'graduations', 'contact', 'bio'] diff --git a/sitecore/prof/export_mysql.py b/sitecore/prof/export_mysql.py index 88871de..6c1297a 100644 --- a/sitecore/prof/export_mysql.py +++ b/sitecore/prof/export_mysql.py @@ -59,7 +59,7 @@ class SimpleDB (object): self.table = table def add_entry(self, dict, table=None): - if table = None: + if table == None: table = self.table dict = self._clean_dict(dict) keys = dict.keys() @@ -69,7 +69,7 @@ class SimpleDB (object): # error checking def list_entries(self, dict=None, table=None): - if table = None: + if table == None: table = self.table where = self._where_string(dict) self.cursor.execute('SELECT * FROM %s%s' % (table, where)) @@ -80,7 +80,7 @@ class SimpleDB (object): print '\t'.join(['%s' % x for x in row]) def delete_entries(self, dict, table=None): - if table = None: + if table == None: table = self.table where = self._where_string(dict) self.cursor.execute('DELETE FROM %s%s' % (table, where)) @@ -152,26 +152,24 @@ Where the relevant categories are yield p -if __name__ == '__main__': +def main(argv): import optparse usage = """%prog [options] PROF_FILE Where PROF_FILE is the output YAML file receiving professor data. Example: - ./sitecore/prof/export_mysql.py profs.yaml + ./sc prof-export_mysql profs.yaml """ p = optparse.OptionParser(usage) p.add_option('-d', '--database', metavar='NAME', dest='database', help='Name of the MySQL database (%default)', default='directory') - p.add_option( p.add_option('-v', '--verbose', dest='verbose', action='count', help='increment verbosity (%default)', default=0) - options,args = p.parse_args() - ] + options,args = p.parse_args(argv) prof_file = args[0] db = SimpleDB(verbose=options.verbose) diff --git a/sitecore/prof/import.py b/sitecore/prof/import.py index d9110c8..ebe4c3b 100644 --- a/sitecore/prof/import.py +++ b/sitecore/prof/import.py @@ -46,7 +46,7 @@ class ProfessorAdder (object): s.open_nav_section(raw_name) TODO -if __name__ == '__main__': +def main(argv): import optparse usage = """%prog [options] PROF_FILE @@ -56,7 +56,7 @@ Example setup before running: Xvfb :99 > /dev/null 2>&1 & export DISPLAY=:99 java -jar selenium-server-1.0.2-SNAPSHOT-standalone.jar > /dev/null 2>&1 & - ./sitecore/prof/import.py profs.yaml + ./sc prof-import profs.yaml """ p = optparse.OptionParser(usage) p.add_option('-u', '--url', metavar='URL', dest='url', @@ -66,8 +66,7 @@ Example setup before running: help='increment verbosity (%default)', default=0) - options,args = p.parse_args() - ] + options,args = p.parse_args(argv) prof_file = args[0] profs = yaml.load(prof_file) -- 2.26.2