def importCSV(self, csvdata, termtype=DEFAULT_VOCABULARY_ITEM, titlerow=False, silentignore=False): """ imports given csv data as the given vocabularytype csv is a string or a file-like object in the style: "Data 1.1", "Data 1.2" "Data 2.1", "Data 2.2" "Data 3.1", "Data 3.2" vocabularytype is the terms portal-type, like SimpleVocabularyTerm which is also the default. It uses column 1 as key=id and column 2 as value=title. If titlerow is True the first line will be skipped. """ if type(csvdata) == type(''): csvdata = StringIO(csvdata) csvreader = csv.reader(csvdata) firstline = True for rec in csvreader: if firstline: firstline = False if titlerow: continue if rec: value=unicode(rec[1], IMPORT_ENCODING) key =rec[0] or make_uuid(value) self.addTerm(key,value,termtype=termtype,silentignore=silentignore)
def test_uuid(self): uids = {} loop_length = 10 ** 5 # about 1.5 seconds on a fast cpu for i in xrange(loop_length): uid = make_uuid() uids[uid] = 1 self.assertEqual(len(uids), loop_length)
def createDocument(self, docid=None): """ Invoke PlominoDocument factory. Returns a new empty document. """ if not docid: docid = make_uuid() self.documents[docid] = addPlominoDocument(docid) doc = self.documents.get(docid) return doc
def image_feed(self, tag, attrs): """Handle image """ for name, value in attrs: if name == 'src': new_id = make_uuid() self.images.append((new_id, value)) break else: return self.data.write(u'<img src="%s" />' % new_id)
def importCSV(self, csvdata, termtype=DEFAULT_VOCABULARY_ITEM, titlerow=False, silentignore=False): """ imports given csv data as the given vocabularytype csv is a string or a file-like object in the style: "Data 1.1", "Data 1.2" "Data 2.1", "Data 2.2" "Data 3.1", "Data 3.2" vocabularytype is the terms portal-type, like SimpleVocabularyTerm which is also the default. It uses column 1 as key=id and column 2 as value=title. If titlerow is True the first line will be skipped. """ qi = getToolByName(self, 'portal_quickinstaller') lp = qi.isProductInstalled('LinguaPlone') if type(csvdata) == type(''): csvdata = StringIO(csvdata) csvreader = csv.reader(csvdata) languages = [] for row in csvreader: if titlerow: # If LinguaPlone is installed, it's assumed the title row is # used to define language columns if lp: for n in range(1, len(row)): languages.append(row[n]) titlerow = False else: value = unicode(row[1], IMPORT_ENCODING) key = row[0] or make_uuid(value) self.addTerm(key, value, termtype=termtype, silentignore=silentignore) if len(languages) > 0: terms = [] self[key].setLanguage(languages[0]) if len(row) > 2: for col in range(2, len(row)): self[key].addTranslation(languages[col-1], title=row[col])
def uploadFile(self, file): """Form post handler to create file. If created successfully then redirect to it's Edit form, otherwise to it's Add form with validation errors. Parameter: @file - data to upload File title is taken from file as filename. """ # check it's post request if self.request.method != 'POST' or not file or not file.filename: raise Exception(u'Invalid request.') context = aq_inner(self.context) id = make_uuid('temp-id') # make sure our id is unique id = context.invokeFactory(id=id, type_name='File') obj = getattr(context, id) obj.update(title=file.filename, file=file) obj._renameAfterCreation() if obj.checkCreationFlag(): obj.unmarkCreationFlag() obj._renameAfterCreation() obj.reindexObject() notify(ObjectInitializedEvent(obj)) # if file is not there then it haven't got over validation process, # notify user about this issue if not obj.get_size(): IStatusMessage(self.request).addStatusMessage(_(u"Attached file is " "invalid, please, try to upload another one."), type="error") # if posted by javascript then no redirect if self.request.form.get('ajax_call'): return '%s/edit' % obj.absolute_url() else: return self.request.response.redirect('%s/edit' % obj.absolute_url())
def cloneHandler(ob, event): """ """ ob.uid = make_uuid(id) return
def _getUUIDFor(self, object): """generate and attach a new uid to the object returning it""" uuid = make_uuid(object.getId()) setattr(object, UUID_ATTR, uuid) return uuid
def _makeName(self, *args): """get a uuid""" name = make_uuid(*args) return name
def _makeName(self, *args): # Get a uuid. name = make_uuid(*args) return name
def twmigrate(self, twpath='/home/audbjorg/work-gunnar/tutor-web/twdata'): # for publishing new content workflow_tool = getToolByName(self, 'portal_workflow') container = self dep = 'The deps are: ' for i in filter(isdep,listdir(twpath)): #depid = 'newdep' #container.invokeFactory('Department', depid) depid = i # the title should be found in the dep.info.txt try: titlefile = open(twpath + '/' + i + '/dep.info.txt', 'r') title = titlefile.read() title = title.split('%')[0] titlefile.close() except: title = 'depid' container.invokeFactory('Department', depid) DepObj = getattr(container, depid) DepObj.setTitle(unicode(title, 'latin-1')) comment = 'Publishing department content' action = 'publish' try: workflow_tool.doActionFor(DepObj, action, comment=comment) except: raise TypeError('Unsupported workflow action %s for object %s.' % (repr(action), repr(DepObj))) DepObj.reindexObject() #next set the tutorials for j in filter(istut,listdir(twpath+'/'+i)): # set id, title, author, lang, courseno, reference and trailer tutorialpath = twpath+'/'+i+'/'+j+'/' try: titlefile = open(tutorialpath+'/course/titleline.txt', 'r') title = titlefile.read() title = title.strip() titlefile.close() except: title = 'no title found' tutid = j DepObj.invokeFactory('Tutorial', tutid) TutObj = getattr(DepObj, tutid) TutObj.setTitle(unicode(title, 'latin-1')) try: authorfile = open(tutorialpath+'course/author.txt', 'r') author = authorfile.read() author = author.strip() author = unicode(author,'latin-1') authorfile.close() except: author = '' TutObj.setAuthor(author) info = '' try: infofile = open(tutorialpath+'course/tutorial.info.txt', 'r') info = infofile.read() info = info.split("%") lang = info[0] coursename = info[2] infofile.close() except: lang = 'NN' coursename = 'NN' courseno=tutid[0:3] + '.' + tutid[3] coursename = coursename + courseno TutObj.setTutorialLanguage(lang) TutObj.setTutorialCode(coursename) try: trailerfile = open(tutorialpath+'course/trailer.tex', 'r') trailer = trailerfile.read() trailer = trailer.strip() trailerfile.close() except: trailer = '' TutObj.setTrailer(trailer, mimetype='text/x-tex') try: referencefile = open(tutorialpath+'course/reference.txt', 'r') reference = referencefile.read() reference = reference.strip() referencefile.close() except: reference = '' TutObj.setTutReference(reference, mimetype='text/plain') comment = 'Publishing tutorial content' action = 'publish' try: workflow_tool.doActionFor(TutObj, action, comment=comment) except: raise TypeError('Unsupported workflow action %s for object %s.' % (repr(action), repr(TutObj))) TutObj.reindexObject() for k in filter(islect,listdir(twpath+'/'+i+'/'+j)): # set id, title, reference lecturepath = twpath+'/'+i+'/'+j+'/'+k+'/' try: titlefile = open(lecturepath+'general/titleline.txt', 'r') title = titlefile.read() title = title.strip() titlefile.close() except: title = 'no title found for lecture' lecid = k TutObj.invokeFactory('Lecture', lecid) LecObj = getattr(TutObj, lecid) LecObj.setTitle(unicode(title, 'latin-1')) try: referencefile = open(lecturepath+'general/reference.txt', 'r') reference = referencefile.read() reference = reference.strip() referencefile.close() except: reference = '' LecObj.setLecReference(reference, mimetype='text/plain') comment = 'Publishing lecture content' action = 'publish' try: workflow_tool.doActionFor(LecObj, action, comment=comment) except: raise TypeError('Unsupported workflow action %s for object %s.' % (repr(action), repr(LecObj))) LecObj.reindexObject() # set the slides for l in filter(isslide, listdir(twpath+'/'+i+'/'+j+'/'+k)): # set id, title, main, explanation text and images, reference # and Details, Examples, Alternative and Handout slidepath = twpath+'/'+i+'/'+j+'/'+k+'/'+l+'/' try: titlefile = open(slidepath+'titleline.txt', 'r') title = titlefile.read() title = title.strip() titlefile.close() except: title = 'no title found for slide' slid = l LecObj.invokeFactory('Slide', slid) SlObj = getattr(LecObj, slid) SlObj.setTitle(unicode(title, 'latin-1')) maintexttype = 'text/plain' explanationtexttype = 'text/plain' maintext = '' explanationtext = '' try: maintextfile = open(slidepath+'text.tex', 'r') maintext = maintextfile.read() maintexttype = 'text/x-tex' maintextfile.close() except: try: maintextfile = open(slidepath+'text.txt', 'r') maintext = maintextfile.read() maintexttype = 'text/plain' maintextfile.close() except: maintext = '' SlObj.setMain_text(maintext, mimetype=maintexttype) try: explanationtextfile = open(slidepath+'expln.tex', 'r') explanationtext = explanationtextfile.read() explanationtexttype = 'text/x-tex' explanationtextfile.close() except: try: explanationtextfile = open(slidepath+'expln.txt', 'r') explanationtext = explanationtextfile.read() explanationtexttype = 'text/plain' explanationtextfile.close() except: explanationtext = '' ## maintext = '' SlObj.setExplanation_text(explanationtext, mimetype=explanationtexttype) # now set the images if any im, extension, imtype = hasImage(listdir(slidepath), 'base.') if (im): if (imtype == 'text'): #has base image with format: plt, fig, r, gnuplot # imagetype: fig,gnuplot, r SlObj.setMain_imagetype(extension) mainimagefile = open(slidepath+im, 'r') mainimage = mainimagefile.read() SlObj.setText_main_image_body(mainimage, mimetype='text/plain') mainimagefile.close() else: # has a base image with format: png, gif or jpg #extension = im.split('.')[1] mime = 'image/'+extension mainimagefile = open(slidepath+im, 'r') mainimage = mainimagefile.read() SlObj.setMain_upload_image(mainimage, mimetype=mime) SlObj.setMain_imagetype('image') mainimagefile.close() im, extension, imtype = hasImage(listdir(slidepath), 'expln.') if (im): if (imtype == 'text'): #has base image with format: plt, fig, r, gnuplot # imagetype: fig,gnuplot, r SlObj.setExplanation_imagetype(extension) mainimagefile = open(slidepath+im, 'r') mainimage = mainimagefile.read() SlObj.setText_explanation_image_body(mainimage, mimetype='text/plain') mainimagefile.close() else: # has a base image with format: png, gif or jpg #extension = im.split('.')[1] mime = 'image/'+extension mainimagefile = open(slidepath+im, 'r') mainimage = mainimagefile.read() SlObj.setExplanation_upload_image(mainimage, mimetype=mime) SlObj.setExplanation_imagetype('image') mainimagefile.close() # now set the extra material: details, examples, homework/handout, alternative for m in listdir(slidepath): if (m == 'D'): extra = 'detail' elif (m == 'E'): extra = 'example' elif (m == 'H'): extra = 'homework' elif (m == 'A'): extra = 'alternative' else: extra = 'noextra' if (not(extra == 'noextra')): setText(slidepath+m+'/', extra, SlObj) #at last set the slide reference if any texttype = 'text/plain' text = '' try: textfile = open(slidepath+'reference.tex', 'r') text = textfile.read() texttype = 'text/x-tex' textfile.close() SlObj.setSlideReference(text, mimetype=texttype) except: try: textfile = open(slidepath+'reference.txt', 'r') text = textfile.read() texttype = 'text/plain' textfile.close() SlObj.setSlideReference(text, mimetype=texttype) except: text = '' comment = 'Publishing slide content' action = 'publish' try: workflow_tool.doActionFor(SlObj, action, comment=comment) except: raise TypeError('Unsupported workflow action %s for object %s.' % (repr(action), repr(SlObj))) SlObj.reindexObject() #set the questions - r questions not implemented yet for q in filter(isquestion, listdir(twpath+'/'+i+'/'+j+'/'+k)): # set id, title, main, explanation text and images, reference # and Details, Examples, Alternative and Handout questionpath = twpath+'/'+i+'/'+j+'/'+k+'/'+q+'/' question = q LecObj.invokeFactory('TutorWebQuestion', question) QueObj = getattr(LecObj, question) maintexttype = 'text/plain' explanationtexttype = 'text/plain' maintext = '' try: maintextfile = open(questionpath+'question.tex', 'r') maintext = maintextfile.read() maintexttype = 'text/x-tex' maintextfile.close() except: try: maintextfile = open(questionpath+'question.txt', 'r') maintext = maintextfile.read() maintexttype = 'text/plain' maintextfile.close() except: try: maintextfile = open(questionpath+'question.r', 'r') maintext = maintextfile.read() maintexttype = 'text/r' maintextfile.close() except: maintext = '' QueObj.setQuestion(maintext, mimetype=maintexttype) QueObj.setPoints(1) ### forgot the points and reindex???? comment = 'Publishing question content' action = 'publish' try: workflow_tool.doActionFor(QueObj, action, comment=comment) except: raise TypeError('Unsupported workflow action %s for object %s.' % (repr(action), repr(QueObj))) QueObj.reindexObject() # Now must set the answers - presuming they are text # Always have three answers (a, b, c and a i correct) answers = [questionpath+'a', questionpath+'b', questionpath+'c'] for a in answers: ans = make_uuid() QueObj.invokeFactory('TutorWebAnswer', ans) AnsObj = getattr(QueObj, ans) answertext = '' answertexttype = 'text/plain' try: answertextfile = open(a, 'r') answertext = answertextfile.read() answertexttype = 'text/plain' answertextfile.close() except: answertext = 'No answer found' answertextype = 'text/plain' AnsObj.setAnswer(answertext, mimetype=answertexttype) if (a == (questionpath+'a')): AnsObj.setCorrect(True) comment = 'Publishing answer content' action = 'publish' try: workflow_tool.doActionFor(AnsObj, action, comment=comment) except: raise TypeError('Unsupported workflow action %s for object %s.' % (repr(action), repr(AnsObj))) AnsObj.reindexObject() dep = dep + i return 'the path is: ' + twpath + 'and ' + dep
def __init__(self, id): """__init__(self, id)""" #PlonePopoll.inheritedAttribute('__init__')(self) super(PlonePopoll, self).__init__(id) self.id = id self.uid = make_uuid(id)
def updateversion(): thesite = getSite() portal_quickinstaller = getToolByName(thesite, 'portal_quickinstaller') versionstring = '' try: objProduct = portal_quickinstaller._getOb('ubify.policy') except: return if objProduct <> None: versionstring = objProduct.getInstalledVersion() ##########Version Check ################## portal_properties = getToolByName(thesite, 'portal_properties') is_update_check_enabled = portal_properties.site_properties.enable_update_check update_check_url = portal_properties.site_properties.update_check_url newversionavailable = False if is_update_check_enabled: site = thesite.portal_url.getPortalObject() if not site.hasProperty('siteuid'): from Products.Archetypes.utils import make_uuid newuid = make_uuid() site.manage_addProperty('siteuid',newuid,'string') siteuid = newuid else: siteuid = site.getProperty('siteuid') if site.hasProperty('lastupdatecheck'): slastcheck = site.getProperty('lastupdatecheck') lastcheck = DateTime(slastcheck) else: lastcheck = DateTime() - 30 # Since last update check date time was not found, let's make it 30 days earlier if lastcheck < DateTime() - 1: #If it's been more than 1 day since last check print 'Last update check was at %s, shouldcheck = %s, now-1=%s' % (lastcheck, (lastcheck < DateTime() - 1),DateTime() -1) from lxml import etree import socket timeout = 10 # timeout in seconds socket.setdefaulttimeout(timeout) editionname,editioncode = CyninEdition(thesite) updateroot = None #try: updateroot = etree.parse(update_check_url % (versionstring,siteuid,editioncode)) #except: # updateroot = None if updateroot is not None: lastcheck=DateTime() #Update the lastcheck date time to now. ce = updateroot.find('communityedition') if ce is not None: current = ce.find('current') if current is not None: ver = current.find('versionstring') if ver is not None: verstring = ver.text if versioncheck(updateroot,versionstring): #We have a new version!! newversionavailable = True newversionstring = verstring changelog = current.find('changelogurl') if changelog is not None: changelogurl = changelog.text download = current.find('downloadurl') if download is not None: downloadurl = download.text if site.hasProperty('lastupdatecheck'): site._updateProperty('lastupdatecheck',lastcheck) else: site.manage_addProperty('lastupdatecheck',lastcheck,'string') else: if site.hasProperty('lastupdatecheck'): site._updateProperty('lastupdatecheck',lastcheck) else: site.manage_addProperty('lastupdatecheck',lastcheck,'string') if site.hasProperty('newversionstring'): site._delProperty('newversionstring') if site.hasProperty('changelogurl'): site._delProperty('changelogurl') if site.hasProperty('downloadurl'): site._delProperty('downloadurl') else: print 'version node not found' else: print 'current node not found' else: print 'CE node not found' else: print 'Empty parse, updateroot is None!' if newversionavailable: #The update check figured out a new version so let's cache it. if site.hasProperty('newversionstring'): site._updateProperty('newversionstring',newversionstring) else: site.manage_addProperty('newversionstring',newversionstring,'string') if site.hasProperty('changelogurl'): site._updateProperty('changelogurl',changelogurl) else: site.manage_addProperty('changelogurl',changelogurl,'string') if site.hasProperty('downloadurl'): site._updateProperty('downloadurl',downloadurl) else: site.manage_addProperty('downloadurl',downloadurl,'string') else: ## Finally check if we have saved newversion data in properties and use it. if site.hasProperty('newversionstring'): newversionavailable = True newversionstring = site.getProperty('newversionstring') changelogurl = site.getProperty('changelogurl') downloadurl = site.getProperty('downloadurl')
def twmigrate(self, twpath='/home/audbjorg/work-gunnar/tutor-web/twdata'): # for publishing new content workflow_tool = getToolByName(self, 'portal_workflow') container = self dep = 'The deps are: ' for i in filter(isdep, listdir(twpath)): #depid = 'newdep' #container.invokeFactory('Department', depid) depid = i # the title should be found in the dep.info.txt try: titlefile = open(twpath + '/' + i + '/dep.info.txt', 'r') title = titlefile.read() title = title.split('%')[0] titlefile.close() except: title = 'depid' container.invokeFactory('Department', depid) DepObj = getattr(container, depid) DepObj.setTitle(unicode(title, 'latin-1')) comment = 'Publishing department content' action = 'publish' try: workflow_tool.doActionFor(DepObj, action, comment=comment) except: raise TypeError('Unsupported workflow action %s for object %s.' % (repr(action), repr(DepObj))) DepObj.reindexObject() #next set the tutorials for j in filter(istut, listdir(twpath + '/' + i)): # set id, title, author, lang, courseno, reference and trailer tutorialpath = twpath + '/' + i + '/' + j + '/' try: titlefile = open(tutorialpath + '/course/titleline.txt', 'r') title = titlefile.read() title = title.strip() titlefile.close() except: title = 'no title found' tutid = j DepObj.invokeFactory('Tutorial', tutid) TutObj = getattr(DepObj, tutid) TutObj.setTitle(unicode(title, 'latin-1')) try: authorfile = open(tutorialpath + 'course/author.txt', 'r') author = authorfile.read() author = author.strip() author = unicode(author, 'latin-1') authorfile.close() except: author = '' TutObj.setAuthor(author) info = '' try: infofile = open(tutorialpath + 'course/tutorial.info.txt', 'r') info = infofile.read() info = info.split("%") lang = info[0] coursename = info[2] infofile.close() except: lang = 'NN' coursename = 'NN' courseno = tutid[0:3] + '.' + tutid[3] coursename = coursename + courseno TutObj.setTutorialLanguage(lang) TutObj.setTutorialCode(coursename) try: trailerfile = open(tutorialpath + 'course/trailer.tex', 'r') trailer = trailerfile.read() trailer = trailer.strip() trailerfile.close() except: trailer = '' TutObj.setTrailer(trailer, mimetype='text/x-tex') try: referencefile = open(tutorialpath + 'course/reference.txt', 'r') reference = referencefile.read() reference = reference.strip() referencefile.close() except: reference = '' TutObj.setTutReference(reference, mimetype='text/plain') comment = 'Publishing tutorial content' action = 'publish' try: workflow_tool.doActionFor(TutObj, action, comment=comment) except: raise TypeError( 'Unsupported workflow action %s for object %s.' % (repr(action), repr(TutObj))) TutObj.reindexObject() for k in filter(islect, listdir(twpath + '/' + i + '/' + j)): # set id, title, reference lecturepath = twpath + '/' + i + '/' + j + '/' + k + '/' try: titlefile = open(lecturepath + 'general/titleline.txt', 'r') title = titlefile.read() title = title.strip() titlefile.close() except: title = 'no title found for lecture' lecid = k TutObj.invokeFactory('Lecture', lecid) LecObj = getattr(TutObj, lecid) LecObj.setTitle(unicode(title, 'latin-1')) try: referencefile = open(lecturepath + 'general/reference.txt', 'r') reference = referencefile.read() reference = reference.strip() referencefile.close() except: reference = '' LecObj.setLecReference(reference, mimetype='text/plain') comment = 'Publishing lecture content' action = 'publish' try: workflow_tool.doActionFor(LecObj, action, comment=comment) except: raise TypeError( 'Unsupported workflow action %s for object %s.' % (repr(action), repr(LecObj))) LecObj.reindexObject() # set the slides for l in filter(isslide, listdir(twpath + '/' + i + '/' + j + '/' + k)): # set id, title, main, explanation text and images, reference # and Details, Examples, Alternative and Handout slidepath = twpath + '/' + i + '/' + j + '/' + k + '/' + l + '/' try: titlefile = open(slidepath + 'titleline.txt', 'r') title = titlefile.read() title = title.strip() titlefile.close() except: title = 'no title found for slide' slid = l LecObj.invokeFactory('Slide', slid) SlObj = getattr(LecObj, slid) SlObj.setTitle(unicode(title, 'latin-1')) maintexttype = 'text/plain' explanationtexttype = 'text/plain' maintext = '' explanationtext = '' try: maintextfile = open(slidepath + 'text.tex', 'r') maintext = maintextfile.read() maintexttype = 'text/x-tex' maintextfile.close() except: try: maintextfile = open(slidepath + 'text.txt', 'r') maintext = maintextfile.read() maintexttype = 'text/plain' maintextfile.close() except: maintext = '' SlObj.setMain_text(maintext, mimetype=maintexttype) try: explanationtextfile = open(slidepath + 'expln.tex', 'r') explanationtext = explanationtextfile.read() explanationtexttype = 'text/x-tex' explanationtextfile.close() except: try: explanationtextfile = open(slidepath + 'expln.txt', 'r') explanationtext = explanationtextfile.read() explanationtexttype = 'text/plain' explanationtextfile.close() except: explanationtext = '' ## maintext = '' SlObj.setExplanation_text(explanationtext, mimetype=explanationtexttype) # now set the images if any im, extension, imtype = hasImage(listdir(slidepath), 'base.') if (im): if (imtype == 'text'): #has base image with format: plt, fig, r, gnuplot # imagetype: fig,gnuplot, r SlObj.setMain_imagetype(extension) mainimagefile = open(slidepath + im, 'r') mainimage = mainimagefile.read() SlObj.setText_main_image_body( mainimage, mimetype='text/plain') mainimagefile.close() else: # has a base image with format: png, gif or jpg #extension = im.split('.')[1] mime = 'image/' + extension mainimagefile = open(slidepath + im, 'r') mainimage = mainimagefile.read() SlObj.setMain_upload_image(mainimage, mimetype=mime) SlObj.setMain_imagetype('image') mainimagefile.close() im, extension, imtype = hasImage(listdir(slidepath), 'expln.') if (im): if (imtype == 'text'): #has base image with format: plt, fig, r, gnuplot # imagetype: fig,gnuplot, r SlObj.setExplanation_imagetype(extension) mainimagefile = open(slidepath + im, 'r') mainimage = mainimagefile.read() SlObj.setText_explanation_image_body( mainimage, mimetype='text/plain') mainimagefile.close() else: # has a base image with format: png, gif or jpg #extension = im.split('.')[1] mime = 'image/' + extension mainimagefile = open(slidepath + im, 'r') mainimage = mainimagefile.read() SlObj.setExplanation_upload_image(mainimage, mimetype=mime) SlObj.setExplanation_imagetype('image') mainimagefile.close() # now set the extra material: details, examples, homework/handout, alternative for m in listdir(slidepath): if (m == 'D'): extra = 'detail' elif (m == 'E'): extra = 'example' elif (m == 'H'): extra = 'homework' elif (m == 'A'): extra = 'alternative' else: extra = 'noextra' if (not (extra == 'noextra')): setText(slidepath + m + '/', extra, SlObj) #at last set the slide reference if any texttype = 'text/plain' text = '' try: textfile = open(slidepath + 'reference.tex', 'r') text = textfile.read() texttype = 'text/x-tex' textfile.close() SlObj.setSlideReference(text, mimetype=texttype) except: try: textfile = open(slidepath + 'reference.txt', 'r') text = textfile.read() texttype = 'text/plain' textfile.close() SlObj.setSlideReference(text, mimetype=texttype) except: text = '' comment = 'Publishing slide content' action = 'publish' try: workflow_tool.doActionFor(SlObj, action, comment=comment) except: raise TypeError( 'Unsupported workflow action %s for object %s.' % (repr(action), repr(SlObj))) SlObj.reindexObject() #set the questions - r questions not implemented yet for q in filter(isquestion, listdir(twpath + '/' + i + '/' + j + '/' + k)): # set id, title, main, explanation text and images, reference # and Details, Examples, Alternative and Handout questionpath = twpath + '/' + i + '/' + j + '/' + k + '/' + q + '/' question = q LecObj.invokeFactory('TutorWebQuestion', question) QueObj = getattr(LecObj, question) maintexttype = 'text/plain' explanationtexttype = 'text/plain' maintext = '' try: maintextfile = open(questionpath + 'question.tex', 'r') maintext = maintextfile.read() maintexttype = 'text/x-tex' maintextfile.close() except: try: maintextfile = open(questionpath + 'question.txt', 'r') maintext = maintextfile.read() maintexttype = 'text/plain' maintextfile.close() except: try: maintextfile = open( questionpath + 'question.r', 'r') maintext = maintextfile.read() maintexttype = 'text/r' maintextfile.close() except: maintext = '' QueObj.setQuestion(maintext, mimetype=maintexttype) QueObj.setPoints(1) ### forgot the points and reindex???? comment = 'Publishing question content' action = 'publish' try: workflow_tool.doActionFor(QueObj, action, comment=comment) except: raise TypeError( 'Unsupported workflow action %s for object %s.' % (repr(action), repr(QueObj))) QueObj.reindexObject() # Now must set the answers - presuming they are text # Always have three answers (a, b, c and a i correct) answers = [ questionpath + 'a', questionpath + 'b', questionpath + 'c' ] for a in answers: ans = make_uuid() QueObj.invokeFactory('TutorWebAnswer', ans) AnsObj = getattr(QueObj, ans) answertext = '' answertexttype = 'text/plain' try: answertextfile = open(a, 'r') answertext = answertextfile.read() answertexttype = 'text/plain' answertextfile.close() except: answertext = 'No answer found' answertextype = 'text/plain' AnsObj.setAnswer(answertext, mimetype=answertexttype) if (a == (questionpath + 'a')): AnsObj.setCorrect(True) comment = 'Publishing answer content' action = 'publish' try: workflow_tool.doActionFor(AnsObj, action, comment=comment) except: raise TypeError( 'Unsupported workflow action %s for object %s.' % (repr(action), repr(AnsObj))) AnsObj.reindexObject() dep = dep + i return 'the path is: ' + twpath + 'and ' + dep
def updateversion(): thesite = getSite() portal_quickinstaller = getToolByName(thesite, 'portal_quickinstaller') versionstring = '' try: objProduct = portal_quickinstaller._getOb('ubify.policy') except: return if objProduct <> None: versionstring = objProduct.getInstalledVersion() ##########Version Check ################## portal_properties = getToolByName(thesite, 'portal_properties') is_update_check_enabled = portal_properties.site_properties.enable_update_check update_check_url = portal_properties.site_properties.update_check_url newversionavailable = False if is_update_check_enabled: site = thesite.portal_url.getPortalObject() if not site.hasProperty('siteuid'): from Products.Archetypes.utils import make_uuid newuid = make_uuid() site.manage_addProperty('siteuid', newuid, 'string') siteuid = newuid else: siteuid = site.getProperty('siteuid') if site.hasProperty('lastupdatecheck'): slastcheck = site.getProperty('lastupdatecheck') lastcheck = DateTime(slastcheck) else: lastcheck = DateTime( ) - 30 # Since last update check date time was not found, let's make it 30 days earlier if lastcheck < DateTime( ) - 1: #If it's been more than 1 day since last check print 'Last update check was at %s, shouldcheck = %s, now-1=%s' % ( lastcheck, (lastcheck < DateTime() - 1), DateTime() - 1) from lxml import etree import socket timeout = 10 # timeout in seconds socket.setdefaulttimeout(timeout) editionname, editioncode = CyninEdition(thesite) updateroot = None #try: updateroot = etree.parse(update_check_url % (versionstring, siteuid, editioncode)) #except: # updateroot = None if updateroot is not None: lastcheck = DateTime() #Update the lastcheck date time to now. ce = updateroot.find('communityedition') if ce is not None: current = ce.find('current') if current is not None: ver = current.find('versionstring') if ver is not None: verstring = ver.text if versioncheck(updateroot, versionstring): #We have a new version!! newversionavailable = True newversionstring = verstring changelog = current.find('changelogurl') if changelog is not None: changelogurl = changelog.text download = current.find('downloadurl') if download is not None: downloadurl = download.text if site.hasProperty('lastupdatecheck'): site._updateProperty( 'lastupdatecheck', lastcheck) else: site.manage_addProperty( 'lastupdatecheck', lastcheck, 'string') else: if site.hasProperty('lastupdatecheck'): site._updateProperty( 'lastupdatecheck', lastcheck) else: site.manage_addProperty( 'lastupdatecheck', lastcheck, 'string') if site.hasProperty('newversionstring'): site._delProperty('newversionstring') if site.hasProperty('changelogurl'): site._delProperty('changelogurl') if site.hasProperty('downloadurl'): site._delProperty('downloadurl') else: print 'version node not found' else: print 'current node not found' else: print 'CE node not found' else: print 'Empty parse, updateroot is None!' if newversionavailable: #The update check figured out a new version so let's cache it. if site.hasProperty('newversionstring'): site._updateProperty('newversionstring', newversionstring) else: site.manage_addProperty('newversionstring', newversionstring, 'string') if site.hasProperty('changelogurl'): site._updateProperty('changelogurl', changelogurl) else: site.manage_addProperty('changelogurl', changelogurl, 'string') if site.hasProperty('downloadurl'): site._updateProperty('downloadurl', downloadurl) else: site.manage_addProperty('downloadurl', downloadurl, 'string') else: ## Finally check if we have saved newversion data in properties and use it. if site.hasProperty('newversionstring'): newversionavailable = True newversionstring = site.getProperty('newversionstring') changelogurl = site.getProperty('changelogurl') downloadurl = site.getProperty('downloadurl')