import time
from selenium.firefox.webdriver import WebDriver
-from selenium.common.exceptions import NoSuchElementException
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()
--- /dev/null
+#!/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()