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 -> ?
25 from selenium.common.exceptions import NoSuchElementException
27 from . import SiteCoreConnection
31 class AttributeHolder (object):
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)
43 class Name (AttributeHolder):
44 self.fields = ['first_middle', 'last']
46 class Graduation (AttributeHolder):
47 self.fields = ['college', 'title', 'year']
49 class Contact (AttributeHolder):
50 self.fields = ['office', 'website', 'phone', 'lab', 'lab_phone']
52 class Bio (AttributeHolder):
53 self.fields = ['specialization', 'publications', 'profile', 'cv']
55 class Professor (object):
56 self.fields = ['name', 'graduations', 'contact', 'bio']
59 class ProfessorAdder (object):
60 """See doc/faculty.txt for Drexel's field/format policy.
62 def __init__(self, sitecore_connection):
63 self.s = sitecore_connection
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')
71 def __call__(self, prof):
73 s.open_nav_section(raw_name)
76 if __name__ == '__main__':
78 usage = """%prog [options] PROF_FILE
80 Where PROF_FILE is a YAML file containing professor data.
82 Example setup before running:
83 Xvfb :99 > /dev/null 2>&1 &
85 java -jar selenium-server-1.0.2-SNAPSHOT-standalone.jar > /dev/null 2>&1 &
86 ./sitecore/prof_import.py profs.yaml
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)',
96 options,args = p.parse_args()
99 profs = yaml.load(prof_file)
101 s = SiteCoreConnection(options.url, options.verbose)
105 a = ProfessorAdder(s)
108 a.aadd_profs(s, profs)