Fix sitecore.prof_import.__doc__
[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
27 from . import SiteCoreConnection
28 import yaml
29
30
31 class AttributeHolder (object):
32     self.fields = []
33     def __init__(self, *args, **kwargs):
34         for field in self.fields:
35             setattr(self, field, None)
36         for field,arg in zip(self.fields, args):
37             setattr(self, field, arg)
38         for field,value in kwargs.items():
39             assert field in self.fields, '%s not in %s' % (field, self.fields)
40             setattr(self, field, value)
41
42
43 class Name (AttributeHolder):
44     self.fields = ['first_middle', 'last']
45
46 class Graduation (AttributeHolder):
47     self.fields = ['college', 'title', 'year']
48
49 class Contact (AttributeHolder):
50     self.fields = ['office', 'website', 'phone', 'lab', 'lab_phone']
51
52 class Bio (AttributeHolder):
53     self.fields = ['specialization', 'publications', 'profile', 'cv']
54
55 class Professor (object):
56     self.fields = ['name', 'graduations', 'contact', 'bio']
57
58
59 class ProfessorAdder (object):
60     """See doc/faculty.txt for Drexel's field/format policy.
61     """
62     def __init__(self, sitecore_connection):
63         self.s = sitecore_connection
64
65     def setup(self):
66         s.expand_nav_section('Media Library')
67         s.expand_nav_section('Images')
68         s.expand_nav_section('physics')
69         s.expand_nav_section('headshots')
70
71     def __call__(self, prof):
72         raw_name = TODO
73         s.open_nav_section(raw_name)
74         TODO
75
76 if __name__ == '__main__':
77     import optparse
78     usage = """%prog [options] PROF_FILE
79
80 Where PROF_FILE is a YAML file containing professor data.
81
82 Example setup before running:
83   Xvfb :99 > /dev/null 2>&1 &
84   export DISPLAY=:99
85   java -jar selenium-server-1.0.2-SNAPSHOT-standalone.jar > /dev/null 2>&1 &
86   ./sitecore/prof_import.py profs.yaml
87 """
88     p = optparse.OptionParser(usage)
89     p.add_option('-u', '--url', metavar='URL', dest='url',
90                  help='set the website URL (%default)',
91                  default='https://webedit.drexel.edu/sitecore/login')
92     p.add_option('-v', '--verbose', dest='verbose', action='count',
93                  help='increment verbosity (%default)',
94                  default=0)
95
96     options,args = p.parse_args()
97                    ]
98     prof_file = args[0]
99     profs = yaml.load(prof_file)
100
101     s = SiteCoreConnection(options.url, options.verbose)
102     s.start()
103     try:
104         s.login()
105         a = ProfessorAdder(s)
106         a.setup()
107         for prof in profs:
108             a.aadd_profs(s, profs)
109     finally:
110         s.stop()