Added sc.py, a
authorW. Trevor King <wking@drexel.edu>
Sat, 26 Jun 2010 20:08:04 +0000 (16:08 -0400)
committerW. Trevor King <wking@drexel.edu>
Sat, 26 Jun 2010 20:10:07 +0000 (16:10 -0400)
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 [new file with mode: 0755]
sitecore/__init__.py
sitecore/alt_tags.py
sitecore/prof/__init__.py
sitecore/prof/export_mysql.py
sitecore/prof/import.py

diff --git a/sc.py b/sc.py
new file mode 100755 (executable)
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)
index 72829f8d96c3be8fea7594dd17ed97a0451d5e69..f34d0cc5b0eddb70de7410cd654d7bcb8ae735da 100755 (executable)
@@ -37,7 +37,7 @@ try:
 except ImportError, e:
     WebDriver = e  # allow some functionality without selenium
 
 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,
     verbosities = [  # in order of decreasing severity
         logging.CRITICAL,
         logging.ERROR,
index 0948f43bc78c0b0b1390614e136da6dad06bc1c6..a8cf1e8ccb2f3e0110e05fb51377a9a1f68a9d83 100644 (file)
@@ -51,7 +51,7 @@ def add_headshot_alt_tags(s):
         s.publish_section('Added alt tag for %s' % name)
 
 
         s.publish_section('Added alt tag for %s' % name)
 
 
-if __name__ == '__main__':
+def main(argv)
     import optparse
     usage = """%prog [options]
 
     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 &
   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',
 """
     p = optparse.OptionParser(usage)
     p.add_option('-u', '--url', metavar='URL', dest='url',
index fd91f36c6aab0fd1601509875efd2aa7394fd76d..32bd67959b18197c6213a598a367679c5a009333 100644 (file)
@@ -40,9 +40,9 @@ First Name*   First Name / Middle Name
 Last Name*     Last Name
 Bio    Brief Bio/Profile/Blurb
 Short Bio      Presentations (If applicable)
 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
 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
 
 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):
 """
 
 class AttributeHolder (object):
-    self.fields = []
+    fields = []
+
     def __init__(self, *args, **kwargs):
         for field in self.fields:
             setattr(self, field, None)
     def __init__(self, *args, **kwargs):
         for field in self.fields:
             setattr(self, field, None)
@@ -68,16 +69,16 @@ class AttributeHolder (object):
 
 
 class Name (AttributeHolder):
 
 
 class Name (AttributeHolder):
-    self.fields = ['first_middle', 'last']
+    fields = ['first_middle', 'last']
 
 class Graduation (AttributeHolder):
 
 class Graduation (AttributeHolder):
-    self.fields = ['college', 'title', 'year']
+    fields = ['college', 'title', 'year']
 
 class Contact (AttributeHolder):
 
 class Contact (AttributeHolder):
-    self.fields = ['office', 'website', 'phone', 'lab', 'lab_phone']
+    fields = ['office', 'website', 'phone', 'lab', 'lab_phone']
 
 class Bio (AttributeHolder):
 
 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']
index 88871deb6f24a3e7b886d510263ba5ca8f54ef7d..6c1297a8e7345fc0efd825ae36b3b9fd060e16c8 100644 (file)
@@ -59,7 +59,7 @@ class SimpleDB (object):
         self.table = table
 
     def add_entry(self, dict, table=None):
         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()
             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):
         # 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))
             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):
             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))
             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
 
 
             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:
     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 = 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)
 
     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)
     prof_file = args[0]
 
     db = SimpleDB(verbose=options.verbose)
index d9110c8f19da8bd486aa31f3a8abe0e3d469ee59..ebe4c3b3a51f9fcbb9c401c602b7db17ea090c96 100644 (file)
@@ -46,7 +46,7 @@ class ProfessorAdder (object):
         s.open_nav_section(raw_name)
         TODO
 
         s.open_nav_section(raw_name)
         TODO
 
-if __name__ == '__main__':
+def main(argv):
     import optparse
     usage = """%prog [options] PROF_FILE
 
     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 &
   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',
 """
     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)
 
                  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)
 
     prof_file = args[0]
     profs = yaml.load(prof_file)