ebe4c3b3a51f9fcbb9c401c602b7db17ea090c96
[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         s.expand_nav_section('Media Library')
40         s.expand_nav_section('Images')
41         s.expand_nav_section('physics')
42         s.expand_nav_section('headshots')
43
44     def __call__(self, prof):
45         raw_name = TODO
46         s.open_nav_section(raw_name)
47         TODO
48
49 def main(argv):
50     import optparse
51     usage = """%prog [options] PROF_FILE
52
53 Where PROF_FILE is a YAML file containing professor data.
54
55 Example setup before running:
56   Xvfb :99 > /dev/null 2>&1 &
57   export DISPLAY=:99
58   java -jar selenium-server-1.0.2-SNAPSHOT-standalone.jar > /dev/null 2>&1 &
59   ./sc prof-import profs.yaml
60 """
61     p = optparse.OptionParser(usage)
62     p.add_option('-u', '--url', metavar='URL', dest='url',
63                  help='set the website URL (%default)',
64                  default='https://webedit.drexel.edu/sitecore/login')
65     p.add_option('-v', '--verbose', dest='verbose', action='count',
66                  help='increment verbosity (%default)',
67                  default=0)
68
69     options,args = p.parse_args(argv)
70     prof_file = args[0]
71     profs = yaml.load(prof_file)
72
73     s = SiteCoreConnection(options.url, options.verbose)
74     s.start()
75     try:
76         s.login()
77         a = ProfessorAdder(s)
78         a.setup()
79         for prof in profs:
80             a.aadd_profs(s, profs)
81     finally:
82         s.stop()