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 """Move Professors from YAML -> Sitecore.
21 Professors will be created in:
22 Content -> Drexel -> ? -> physics -> ?
27 from selenium.common.exceptions import NoSuchElementException
30 from .. import SiteCoreConnection
31 from . import Name, Graduation, Contact, Bio, Professor
34 class ProfessorAdder (object):
35 """See doc/faculty.txt for Drexel's field/format policy.
37 def __init__(self, sitecore_connection):
38 self.s = sitecore_connection
41 #self.s.expand_nav_section('sitecore')
42 #self.s.expand_nav_section('Content')
43 self.s.expand_nav_section('Home')
44 for i in range(5): # 'physics' takes a while to load
46 self.s.expand_nav_section('physics')
47 except NoSuchElementException, e:
48 time.sleep(self.s.wait_time)
49 self.s.expand_nav_section('contact')
50 self.s.expand_nav_section('facultyDirectory')
52 def __call__(self, prof):
53 self.create_prof_page(prof)
54 self.s.open_nav_section(raw_name)
57 def create_prof_page(self, prof):
58 self.s.open_nav_section('Copy of Shyamalendu Bose')
59 self.s.w.find_element_by_link_text('Copy To').click()
60 time.sleep(self.s.wait_time)
61 windows = self.s.w.get_window_handles()
62 current_window = self.s.w.get_current_window_handle()
63 self.s.logger.info('handling copy popup %s (from %s)'
64 % (current_window, windows))
65 name = self.s.find_element_by_id('Filename')
68 '/sitecore/content/Home/physics/contact/facultyDirectory/%s %s'
69 % (prof.name.first, prof.name.last))
70 self.s.w.find_element_by_link_text('Copy').click()
71 time.sleep(self.s.wait_time)
76 usage = """%prog [options] PROF_FILE
78 Where PROF_FILE is a YAML file containing professor data.
80 Example setup before running:
81 Xvfb :99 > /dev/null 2>&1 &
83 java -jar selenium-server-1.0.2-SNAPSHOT-standalone.jar > /dev/null 2>&1 &
84 ./sc.py prof-import profs.yaml
86 p = optparse.OptionParser(usage)
87 p.add_option('-u', '--url', metavar='URL', dest='url',
88 help='set the website URL (%default)',
89 default='https://webedit.drexel.edu/sitecore/login')
90 p.add_option('-v', '--verbose', dest='verbose', action='count',
91 help='increment verbosity (%default)',
94 options,args = p.parse_args(argv[1:])
96 profs = yaml.load(prof_file)
98 s = SiteCoreConnection(options.url, options.verbose)
102 add = ProfessorAdder(s)