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 -> *
27 from selenium.common.exceptions import NoSuchElementException
29 from . import SiteCoreConnection
32 def add_headshot_alt_tags(s):
33 s.expand_nav_section('Media Library')
34 s.expand_nav_section('Images')
35 s.expand_nav_section('physics')
36 s.expand_nav_section('headshots')
37 div,img,link = s.find_nav_section('headshots')
38 for child_link in div.find_elements_by_tag_name('a'):
39 if child_link.get_text() == link.get_text():
41 raw_name = child_link.get_text()
42 name = ' '.join([x.capitalize() for x in raw_name.split('_')])
43 s.logger.info('setting alt tag "%s" for %s' % (name, raw_name))
44 s.open_nav_section(raw_name)
47 except NoSuchElementException, e:
48 s.logger.info("can't lock %s (already locked?), skipping" % raw_name)
50 alt_granddad,alt_tag = s.find_field(
51 re.compile('.*Alt:.*', re.DOTALL), 'Alt')
53 alt_tag.send_keys(name)
54 s.publish_section('Added alt tag for %s' % name)
59 usage = """%prog [options]
61 Example setup before running:
62 Xvfb :99 > /dev/null 2>&1 &
64 java -jar selenium-server-1.0.2-SNAPSHOT-standalone.jar > /dev/null 2>&1 &
67 p = optparse.OptionParser(usage)
68 p.add_option('-u', '--url', metavar='URL', dest='url',
69 help='set the website URL (%default)',
70 default='https://webedit.drexel.edu/sitecore/login')
71 p.add_option('-v', '--verbose', dest='verbose', action='count',
72 help='increment verbosity (%default)',
75 options,args = p.parse_args(argv[1:])
77 s = SiteCoreConnection(options.url, options.verbose)
81 add_headshot_alt_tags(s)