Content -> Drexel -> ? -> physics -> ?
"""
+import time
+
from selenium.common.exceptions import NoSuchElementException
import yaml
self.s = sitecore_connection
def setup(self):
- s.expand_nav_section('Media Library')
- s.expand_nav_section('Images')
- s.expand_nav_section('physics')
- s.expand_nav_section('headshots')
+ #self.s.expand_nav_section('sitecore')
+ #self.s.expand_nav_section('Content')
+ self.s.expand_nav_section('Home')
+ for i in range(5): # 'physics' takes a while to load
+ try:
+ self.s.expand_nav_section('physics')
+ except NoSuchElementException, e:
+ time.sleep(self.s.wait_time)
+ self.s.expand_nav_section('contact')
+ self.s.expand_nav_section('facultyDirectory')
def __call__(self, prof):
- raw_name = TODO
- s.open_nav_section(raw_name)
- TODO
+ name = '%s %s' % (prof.name.first_middle, prof.name.last)
+ self.create_prof_page(name)
+ self.lock_section(name)
+ settings = [
+ ('Degrees:', prof.degrees()),
+ ('College:', prof.colleges()),
+ ('Program:', prof.program()),
+ ('Office:', prof.contact.office),
+ ('Specialization:', prof.bio.specialization),
+ ('Research Interests:', ''),
+ ('Personal Site:', prof.sites()),
+ ('Title:', prof.title),
+ ('First Name:', prof.name.first_middle),
+ ('Last Name:', prof.name.last),
+ ('Bio:', prof.profile()),
+ ('Headshot:', ('/Images/physics/headshots/%s'
+ % name.lower().replace('.','').replace(' ','_'))),
+ ('Email:', prof.contact.email),
+ ('Phone:', prof.contact.phone),
+ ('Fax:', prof.lab_contact()),
+ ('Page Title - This shows in the tab and title bar of the brower -- Google rates it highly:', name),
+ ("Menu Title - This shows in the menus and navigation blocks -- it's usually a shorted version of the page title:", name),
+ ("Breadcrumb Title - This shows in the breadcrumb trail -- it's usually a very short version of the page title:", name),
+ ("See Also title - Other items that refer to this one will use this text:", name),
+ ]
+ for field_name,value in settings:
+ if value == None:
+ value = ''
+ granddad,field = s.find_field(field_name)
+ field.clear()
+ field.send_keys(value)
+ #granddad,field = s.find_field('Headshot:')
+ #granddad.find_element_by_link_text('Properties')
+ # TODO, set width/height
+ s.publish_section('Added/updated Prof. %s' % prof.name.last)
+
+ def create_prof_page(self, name):
+ self.s.open_nav_section(name)
+ return
+ self.s.open_nav_section('Copy of Shyamalendu Bose')
+ old_windows = self.s.w.get_window_handles()
+ self.s.w.find_element_by_link_text('Copy To').click()
+ time.sleep(self.s.wait_time)
+ windows = self.s.w.get_window_handles()
+ current_window = self.s.w.get_current_window_handle()
+ popup = [w for w in windows if w not in old_windows][0]
+ if current_window != popup:
+ self.s.logger.info('handling copy popup %s (from %s, old %s)'
+ % (popup, windows, current_window))
+ self.s.w.switch_to_window(popup)
+ name = self.s.w.find_element_by_id('Filename')
+ name.clear()
+ name.send_keys(
+ '/sitecore/content/Home/physics/contact/facultyDirectory/%s'
+ % name)
+ self.s.w.find_element_by_id('OK').click()
+ time.sleep(self.s.wait_time)
+ current_window = self.s.w.get_current_window_handle()
+ self.s.logger.info('handled copy popup %s, back to %s'
+ % (popup, current_window))
+ self.s.open_nav_section(name)
+
+ def lock_section(self, name):
+ try:
+ self.s.lock_section()
+ except NoSuchElementException, e:
+ self.s.logger.info("can't lock %s (already locked?), skipping" % name)
+
def main(argv):
import optparse
Xvfb :99 > /dev/null 2>&1 &
export DISPLAY=:99
java -jar selenium-server-1.0.2-SNAPSHOT-standalone.jar > /dev/null 2>&1 &
- ./sc prof-import profs.yaml
+ ./sc.py prof-import profs.yaml
"""
p = optparse.OptionParser(usage)
p.add_option('-u', '--url', metavar='URL', dest='url',
help='increment verbosity (%default)',
default=0)
- options,args = p.parse_args(argv)
+ options,args = p.parse_args(argv[1:])
prof_file = args[0]
- profs = yaml.load(prof_file)
+ profs = yaml.load(open(prof_file, 'r'))
s = SiteCoreConnection(options.url, options.verbose)
s.start()
try:
s.login()
- a = ProfessorAdder(s)
- a.setup()
+ add = ProfessorAdder(s)
+ add.setup()
for prof in profs:
- a.aadd_profs(s, profs)
+ add(prof)
finally:
s.stop()