bc5440bb88d7ac2f2e9669a110ddabbbbfa81206
[sitecorepy.git] / sitecore / prof / import.py
1 #!/usr/bin/env python
2 # Copyright (C) 2010 W. Trevor King <wking@drexel.edu>
3 #
4 # This file is part of SiteCorePy.
5 #
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.
10 #
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.
15 #
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/>.
18
19 """Move Professors from YAML -> Sitecore.
20
21 Professors will be created in:
22   Content -> Drexel -> ? -> physics -> ?
23 """
24
25 from selenium.common.exceptions import NoSuchElementException
26 import yaml
27
28 from .. import SiteCoreConnection
29 from . import Name, Graduation, Contact, Bio, Professor
30
31
32 class ProfessorAdder (object):
33     """See doc/faculty.txt for Drexel's field/format policy.
34     """
35     def __init__(self, sitecore_connection):
36         self.s = sitecore_connection
37
38     def setup(self):
39         #self.s.expand_nav_section('sitecore')
40         #self.s.expand_nav_section('Content')
41         self.s.expand_nav_section('Home')
42         self.s.expand_nav_section('physics')
43         self.s.expand_nav_section('contact')
44         self.s.expand_nav_section('facultyDirectory')
45
46     def __call__(self, prof):
47         self.create_prof_page(prof)
48         self.s.open_nav_section(raw_name)
49         TODO
50
51     def create_prof_page(self, prof):
52         self.s.open_nav_section('Copy of Shyamalendu Bose')
53         self.s.w.find_element_by_link_text('Copy To').click()
54         time.sleep(self.s.wait_time)
55         windows = self.w.get_window_handles()
56         current_window = self.w.get_current_window_handle()
57         self.logger.info('handling copy popup %s (from %s)'
58                          % (current_window, windows))
59         name = self.s.find_element_by_id('Filename')
60         name.clear()
61         name.send_keys(
62             '/sitecore/content/Home/physics/contact/facultyDirectory/%s %s'
63             % (prof.name.first, prof.name.last))
64         self.s.w.find_element_by_link_text('Copy').click()
65         time.sleep(self.s.wait_time)
66
67
68 def main(argv):
69     import optparse
70     usage = """%prog [options] PROF_FILE
71
72 Where PROF_FILE is a YAML file containing professor data.
73
74 Example setup before running:
75   Xvfb :99 > /dev/null 2>&1 &
76   export DISPLAY=:99
77   java -jar selenium-server-1.0.2-SNAPSHOT-standalone.jar > /dev/null 2>&1 &
78   ./sc.py prof-import profs.yaml
79 """
80     p = optparse.OptionParser(usage)
81     p.add_option('-u', '--url', metavar='URL', dest='url',
82                  help='set the website URL (%default)',
83                  default='https://webedit.drexel.edu/sitecore/login')
84     p.add_option('-v', '--verbose', dest='verbose', action='count',
85                  help='increment verbosity (%default)',
86                  default=0)
87
88     options,args = p.parse_args(argv[1:])
89     prof_file = args[0]
90     profs = yaml.load(prof_file)
91
92     s = SiteCoreConnection(options.url, options.verbose)
93     s.start()
94     try:
95         s.login()
96         a = ProfessorAdder(s)
97         a.setup()
98         for prof in profs:
99             a.add_profs(s, profs)
100     finally:
101         s.stop()