2 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
4 # This file is part of SiteCorePy.
6 # SiteCorePy is free software; you can redistribute it and/or modify it
7 # under the terms of the GNU General Public License as published by the
8 # Free Software Foundation, either version 2 of the License, or (at your
9 # option) any later version.
11 # SiteCorePy is distributed in the hope that it will be useful, but
12 # WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 # General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with SiteCorePy. If not, see <http://www.gnu.org/licenses/>.
19 """Add 'alt' tags to all images in headshots.
21 The images affected are:
22 Media Library -> Images -> physics -> headshots -> *
25 from selenium.common.exceptions import NoSuchElementException
27 from . import SiteCoreConnection
30 def add_headshot_alt_tags(s):
31 s.expand_nav_section('Media Library')
32 s.expand_nav_section('Images')
33 s.expand_nav_section('physics')
34 s.expand_nav_section('headshots')
35 div,img,link = s.find_nav_section('headshots')
36 for child_link in div.find_elements_by_tag_name('a'):
37 if child_link.get_text() == link.get_text():
39 raw_name = child_link.get_text()
40 name = ' '.join([x.capitalize() for x in raw_name.split('_')])
41 s.logger.info('setting alt tag "%s" for %s' % (name, raw_name))
42 s.open_nav_section(raw_name)
45 except NoSuchElementException, e:
46 s.logger.info("can't lock %s (already locked?), skipping" % raw_name)
48 alt_granddad,alt_tag = s.find_field('Alt:')
50 alt_tag.send_keys(name)
51 s.publish_section('Added alt tag for %s' % name)
56 usage = """%prog [options]
58 Example setup before running:
59 Xvfb :99 > /dev/null 2>&1 &
61 java -jar selenium-server-1.0.2-SNAPSHOT-standalone.jar > /dev/null 2>&1 &
64 p = optparse.OptionParser(usage)
65 p.add_option('-u', '--url', metavar='URL', dest='url',
66 help='set the website URL (%default)',
67 default='https://webedit.drexel.edu/sitecore/login')
68 p.add_option('-v', '--verbose', dest='verbose', action='count',
69 help='increment verbosity (%default)',
72 options,args = p.parse_args()
74 s = SiteCoreConnection(options.url, options.verbose)
78 add_headshot_alt_tags(s)