Moved to submodule structure and split out alt_tags
authorW. Trevor King <wking@drexel.edu>
Fri, 25 Jun 2010 19:08:33 +0000 (15:08 -0400)
committerW. Trevor King <wking@drexel.edu>
Fri, 25 Jun 2010 19:08:33 +0000 (15:08 -0400)
sitecore/__init__.py [moved from sitecore.py with 74% similarity]
sitecore/alt_tags.py [new file with mode: 0644]

similarity index 74%
rename from sitecore.py
rename to sitecore/__init__.py
index 6d864fde8d04ffd19bcfc2bf00e5ca1c861a77a3..e6e0ac1827f10aa844d2892a0197d5be80b21457 100755 (executable)
@@ -33,7 +33,6 @@ import logging
 import time
 
 from selenium.firefox.webdriver import WebDriver
-from selenium.common.exceptions import NoSuchElementException
 
 
 class SiteCoreConnection (object):
@@ -162,59 +161,3 @@ class SiteCoreConnection (object):
         if match != True:
             raise KeyError(field)
         return (granddad, f)
-
-
-def add_headshot_alt_tags(s):
-    s.expand_nav_section('Media Library')
-    s.expand_nav_section('Images')
-    s.expand_nav_section('physics')
-    s.expand_nav_section('headshots')
-    div,img,link = s.find_nav_section('headshots')
-    for child_link in div.find_elements_by_tag_name('a'):
-        if child_link.get_text() == link.get_text():
-            continue
-        raw_name = child_link.get_text()
-        name = ' '.join([x.capitalize() for x in raw_name.split('_')])
-        s.logger.info('setting alt tag "%s" for %s' % (name, raw_name))
-        s.open_nav_section(raw_name)
-        try:
-            s.lock_section()
-        except NoSuchElementException, e:
-            s.logger.info("can't lock %s (already locked?), skipping" % raw_name)
-            continue
-        alt_granddad,alt_tag = s.find_field('Alt:')
-        alt_tag.clear()
-        alt_tag.send_keys(name)
-        s.publish_section('Added alt tag for %s' % name)
-
-
-if __name__ == '__main__':
-    import optparse
-    usage = """%prog [options]
-
-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.py
-"""
-    p = optparse.OptionParser(usage)
-    p.add_option('-u', '--url', metavar='URL', dest='url',
-                 help='set the website URL (%default)',
-                 default='https://webedit.drexel.edu/sitecore/login')
-    p.add_option('-r', '--reload', metavar='NUM', dest='reload', type='int',
-                 help='if a page load fails, try again NUM times (%default)',
-                 default=5)
-    p.add_option('-v', '--verbose', dest='verbose', action='count',
-                 help='increment verbosity (%default)',
-                 default=0)
-
-    options,args = p.parse_args()
-
-    s = SiteCoreConnection(options.url, options.verbose)
-    s.start()
-    try:
-        s.login()
-        add_headshot_alt_tags(s)
-    finally:
-        s.stop()
diff --git a/sitecore/alt_tags.py b/sitecore/alt_tags.py
new file mode 100644 (file)
index 0000000..19fac3c
--- /dev/null
@@ -0,0 +1,83 @@
+#!/usr/bin/env python
+# Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
+#
+# This file is part of SiteCorePy.
+#
+# SiteCorePy is free software; you can redistribute it and/or modify it
+# under the terms of the GNU General Public License as published by the
+# Free Software Foundation, either version 2 of the License, or (at your
+# option) any later version.
+#
+# SiteCorePy is distributed in the hope that it will be useful, but
+# WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with SiteCorePy.  If not, see <http://www.gnu.org/licenses/>.
+
+"""Add 'alt' tags to all images in headshots.
+
+The images affected are:
+  Media Library -> Images -> physics -> headshots -> *
+"""
+
+from selenium.common.exceptions import NoSuchElementException
+
+from . import SiteCoreConnection
+
+
+def add_headshot_alt_tags(s):
+    s.expand_nav_section('Media Library')
+    s.expand_nav_section('Images')
+    s.expand_nav_section('physics')
+    s.expand_nav_section('headshots')
+    div,img,link = s.find_nav_section('headshots')
+    for child_link in div.find_elements_by_tag_name('a'):
+        if child_link.get_text() == link.get_text():
+            continue
+        raw_name = child_link.get_text()
+        name = ' '.join([x.capitalize() for x in raw_name.split('_')])
+        s.logger.info('setting alt tag "%s" for %s' % (name, raw_name))
+        s.open_nav_section(raw_name)
+        try:
+            s.lock_section()
+        except NoSuchElementException, e:
+            s.logger.info("can't lock %s (already locked?), skipping" % raw_name)
+            continue
+        alt_granddad,alt_tag = s.find_field('Alt:')
+        alt_tag.clear()
+        alt_tag.send_keys(name)
+        s.publish_section('Added alt tag for %s' % name)
+
+
+if __name__ == '__main__':
+    import optparse
+    usage = """%prog [options]
+
+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.py
+"""
+    p = optparse.OptionParser(usage)
+    p.add_option('-u', '--url', metavar='URL', dest='url',
+                 help='set the website URL (%default)',
+                 default='https://webedit.drexel.edu/sitecore/login')
+    p.add_option('-r', '--reload', metavar='NUM', dest='reload', type='int',
+                 help='if a page load fails, try again NUM times (%default)',
+                 default=5)
+    p.add_option('-v', '--verbose', dest='verbose', action='count',
+                 help='increment verbosity (%default)',
+                 default=0)
+
+    options,args = p.parse_args()
+
+    s = SiteCoreConnection(options.url, options.verbose)
+    s.start()
+    try:
+        s.login()
+        add_headshot_alt_tags(s)
+    finally:
+        s.stop()