def loadSites(filename): '''Create a new dictionary of sites by passing in a file name to the section properties file.''' sem = Semaphore(semname) sem.put() parser = PropertyDataParser(filename) sem.remove() sites = SiteDict() for i in range(0, len(parser.getPropertyAsList('site'))): attrs = parser.getPropertyAttrsAsList('site')[i] site = Site() site.domain = parser.getPropertyAsList('site')[i] site.id = int(attrs['id']) site.contactEmail = attrs['contactEmail'] site.webmasterUsername = attrs['webmasterUsername'] site.webmasterFirst = attrs['webmasterFirst'] site.webmasterLast = attrs['webmasterLast'] site.dateCreated = attrs['dateCreated'] site.activated = (attrs['activated'] in TRUE) site.activationCode = attrs['activationCode'] site.inviteCode = attrs['inviteCode'] site.status = attrs['status'] site.rootWWWDir = attrs['rootWWWDir'] site.rootAdminDir = attrs['rootAdminDir'] sites[site.domain] = site return sites
def loadInfoPages(filename): '''Create an InfoPages object by passing in a file name to the style properties file.''' sem = Semaphore(semname) sem.put() parser = PropertyDataParser(filename) sem.remove() pages = InfoPages() for propList in parser: prop = propList[0] ip = InfoPage() ip.name = prop.name ip.content = prop.content ip.order = int(prop.attrs['order']) ip.isVisible = (prop.attrs['visible'] in TRUE) ip.title = str(prop.attrs['title']) ip.subtitle = str(prop.attrs['subtitle']) if ('menuName' in prop.attrs): ip.menuName = str(prop.attrs['menuName']) if ('filename' in prop.attrs): ip.filename = str(prop.attrs['filename']) pages.add(ip) return pages
def loadNewsItemList(pageName, fileDir=APPLICATION.dataDirectory): '''Load a NewsItem list. Return None if the file did not exist.''' #raise Exception('DEPRECATED') if (pageName not in NEWSITEMLIST_DICT): fileName = fileDir + pageName + '-data.xml' sem = Semaphore(fileDir + pageName + '_') sem.put() newsItems = None if (fileExists(fileName)): try: #log('loadNewsItemList: loading data for ' + pageName) f = file(fileName) data = f.read() f.close() #log('loadNewsItemList: parsing data for ' + pageName) newsItems = NewsItemList("data/rss2_properties.xml", APPLICATION.attachURL) newsItems.parse(data) #log('loadNewsItemList: sorting data for ' + pageName) newsItems.sort() #log('loadNewsItemList: done handling data for ' + pageName) except Exception, e: sem.remove() raise str('Unexpected exception attempting to load: ' + fileName + ' ' + str(e)) sem.remove() NEWSITEMLIST_DICT[pageName] = newsItems
def writeNewsItemList(pageName, niList): #raise Exception('DEPRECATED') fileName = APPLICATION.dataDirectory + \ pageName + '-data.xml' sem = Semaphore(APPLICATION.newsFileLocation + pageName + '_') sem.put() try: nwslst = itemListToNewsItemListXML(niList) #Parse the XML to make sure it works ok newsItemParser = xml.parsers.expat.ParserCreate() newsItemParser.Parse(nwslst) #Write the new news item to the appropriate file f = file(fileName, 'w') f.write(nwslst) f.flush() f.close() except: sem.remove() raise sem.remove()
def loadSectionList(filename): '''Create a new dictionary of news sections by passing in a file name to the section properties file.''' sem = Semaphore(semname) sem.put() parser = PropertyDataParser(filename) sem.remove() sectionList = SectionList() for i in range(0, len(parser.getPropertyAsList('section'))): attrs = parser.getPropertyAttrsAsList('section')[i] section = Section() section.name = parser.getPropertyAsList('section')[i] section.longname = attrs['longname'] if ('isHomepage' in attrs): section.isHomepage = (attrs['isHomepage'] in TRUE) if ('columns' in attrs): section.columns = int(attrs['columns']) if ('order' in attrs): section.order = int(attrs['order']) if ('isActive' in attrs): section.isActive = (attrs['isActive'] in TRUE) if ('isVisible' in attrs): section.isVisible = (attrs['isVisible'] in TRUE) sectionList.add(section) return sectionList
def loadStyles(filename): '''Create a new dictionary of news styles by passing in a file name to the style properties file.''' sem = Semaphore(semname) sem.put() parser = PropertyDataParser(filename) sem.remove() styles = dict() for i in range(0, len(parser.getPropertyAsList('style'))): attrs = parser.getPropertyAttrsAsList('style')[i] style = Style() style.name = parser.getPropertyAsList('style')[i] style.id = int(attrs['id']) style.prettyName = attrs['prettyName'] style.menuType = attrs['menuType'] styles[style.name] = style return styles
def write(self, filename): sem = Semaphore(usersemname) sem.put() data = self.build() f = file(filename, 'w') f.write(data) f.flush() f.close() sem.remove()
def loadUserRules(filename): urCollection = None sem = Semaphore(ursemname) sem.put() userRulesProperties = PropertyDataParser(filename) sem.remove() if (userRulesProperties.hasProperty('rule')): rules = userRulesProperties.getPropertyAsList('rule') urCollection = UserRuleCollection(rules) return urCollection
def writeUserRules(urCollection, filename): '''Write the rules out to a properties file.''' pfb = PropertyFileBuilder() for rule in urCollection.rules: pfb.add('rule', rule) sem = Semaphore(ursemname) sem.put() pfb.write(filename) sem.remove()
def writeSites(filename, sites): '''Write the sites properties file.''' pfb = PropertyFileBuilder() for site in sites: pfb.add('site', sites[site].domain, sites[site].getAttrDict()) sem = Semaphore(semname) sem.put() pfb.write(filename) sem.remove()
def writeNewsPageProperties(pages, filename): '''Write the news pages out to a properties file.''' pfb = PropertyFileBuilder() for page in pages: pfb.add('page', pages[page].name, pages[page].getAttrDict()) sem = Semaphore(semname) sem.put() pfb.write(filename) sem.remove()
def __init__(self, filename): """Initialze the class with a file name relative to the path of the root script.""" sem = Semaphore(usersemname) sem.put() try: self.users = None f = file(filename) data = f.read() f.close() self.parse(data) except IOError: sem.remove() raise "IOError attempting to access:", filename sem.remove()
def writeStyles(filename, styles): '''Write the styles properties file.''' pfb = PropertyFileBuilder() for style in styles: pfb.add('style', styles[style].name, styles[style].getAttrDict()) sem = Semaphore(semname) sem.put() pfb.write(filename) sem.remove()
def writeNewsletterData(filename, recipients): '''Write the sections properties file.''' pfb = PropertyFileBuilder() for recipient in recipients: pfb.add('recipient', recipient.name, \ recipient.getAttrDict()) sem = Semaphore(semname) sem.put() pfb.write(filename) sem.remove()
def writeInfoPages(filename, infoPages): '''Write the info pages properties file.''' pfb = PropertyFileBuilder() pfb.setCData(True) for item in infoPages: pfb.add(item.name, item.content, item.getAttrDict()) sem = Semaphore(semname) sem.put() pfb.write(filename) sem.remove()
def __writePage__(self, filename, pageData): #Write the page to a file try: sem = Semaphore(semname) sem.put() ff = file(filename, 'w') ff.write(str(pageData)) ff.flush() ff.close() sem.remove() except IOError: raise "IOError attempting to write:", filename
def writeApplication(filename, application): '''Write the sections properties file.''' pfb = PropertyFileBuilder() pfb.setCData(True) propDict = application.getPropDict() for prop in propDict: pfb.add(prop, propDict[prop]) sem = Semaphore(semname) sem.put() pfb.write(filename) sem.remove()
def writeSections(filename, sections): '''Write the sections properties file.''' pfb = PropertyFileBuilder() # TODO-L: Remove next line when refactored to use only loadSectionList sectionList = buildSectionList(sections) for section in sectionList: pfb.add('section', section.name, section.getAttrDict()) sem = Semaphore(semname) sem.put() pfb.write(filename) sem.remove()
def loadNewsletterData(filename): '''Create a new dictionary of news sections by passing in a file name to the section properties file.''' sem = Semaphore(semname) sem.put() parser = PropertyDataParser(filename) sem.remove() recipients = list() if (parser.hasProperty('recipient')): for i in range(0, len(parser.getPropertyAsList('recipient'))): attrs = parser.getPropertyAttrsAsList('recipient')[i] nr = NewsletterRecipient() nr.name = attrs['name'] nr.email = attrs['email'] recipients += [nr] return recipients
def loadApplication(filename): '''Create a new dictionary of news sections by passing in a file name to the section properties file.''' sem = Semaphore(semname) sem.put() parser = PropertyDataParser(filename) sem.remove() application = Application() application.siteTitle = parser.getSafeProperty('siteTitle', '') application.siteSubTitle = parser.getSafeProperty('siteSubTitle', '') application.metaDescription = parser.getSafeProperty('metaDescription', '') application.metaKeywords = parser.getSafeProperty('metaKeywords', '') application.category = parser.getSafeProperty('category', '') application.cookieName = parser.getSafeProperty('cookieName', '') application.rootURL = parser.getSafeProperty('rootURL', '') application.siteID = parser.getSafeProperty('siteID', '') application.ID = parser.getSafeProperty('ID', '') application.dataDirectory = parser.getSafeProperty('dataDirectory', '') application.includesDirectory = parser.getSafeProperty( 'includesDirectory', '') application.rssDirectory = parser.getSafeProperty('rssDirectory', '') application.rssFullURL = parser.getSafeProperty('rssFullURL', '') application.newsFileLocation = parser.getSafeProperty( 'newsFileLocation', '') application.exceptionHeader = parser.getSafeProperty('exceptionHeader', '') application.exceptionFooter = parser.getSafeProperty('exceptionFooter', '') application.headerFile = parser.getSafeProperty('headerFile', '') application.footerFile = parser.getSafeProperty('footerFile', '') application.redirectOnFailedLogin = parser.getSafeProperty( 'redirectOnFailedLogin', '') application.startPage = parser.getSafeProperty('startPage', '') application.homePage = parser.getSafeProperty('homePage', '') application.templateDir = parser.getSafeProperty('templateDir', '') application.indexTemplate = parser.getSafeProperty('indexTemplate', '') application.domainName = parser.getSafeProperty('domainName', '') application.adminCssFile = parser.getSafeProperty('adminCssFile', '') application.attachDirectory = parser.getSafeProperty('attachDirectory', '') application.attachURL = parser.getSafeProperty('attachURL', '') application.userDirectory = parser.getSafeProperty('userDirectory', '') application.userURL = parser.getSafeProperty('userURL', '') application.active = (parser.getSafeProperty('active', True) in TRUE) application.premium = (parser.getSafeProperty('premium', False) in TRUE) application.showAds = (parser.getSafeProperty('showAds', True) in TRUE) application.storageLocked = (parser.getSafeProperty( 'storageLocked', False) in TRUE) application.siteType = parser.getSafeProperty('siteType', SITE_TYPE_BASIC) application.newsletter = (parser.getSafeProperty('newsletter', True) in TRUE) application.styleURL = parser.getSafeProperty('styleURL', '') application.printStyleURL = parser.getSafeProperty('printStyleURL', application.styleURL) application.styleDir = parser.getSafeProperty('styleDir', '') application.styleName = parser.getSafeProperty('styleName', '') application.customStyle = (parser.getSafeProperty('customStyle', False) in TRUE) application.subTitleDate = (parser.getSafeProperty('subTitleDate', False) in TRUE) application.articleDate = (parser.getSafeProperty('articleDate', True) in TRUE) application.moreText = parser.getSafeProperty('moreText', '[more]') application.imageSize = int(parser.getSafeProperty('imageSize', 60)) application.advancedLinks = (parser.getSafeProperty( 'advancedLinks', False) in TRUE) application.adminURL = parser.getSafeProperty('adminURL', '') application.contactEmail = parser.getSafeProperty('contactEmail', '') application.autoResizeImages = (parser.getSafeProperty( 'autoResizeImages', True) in TRUE) application.maxImageSize = int( parser.getSafeProperty('maxImageSize', 250000)) application.absoluteRootPath = parser.getSafeProperty( 'absoluteRootPath', '/home/yakjivec/www/') application.allowRTEToggleSrc = (parser.getSafeProperty( 'allowRTEToggleSrc', False) in TRUE) application.db = parser.getSafeProperty('db', '') application.dbUser = parser.getSafeProperty('dbUser', '') application.dbPassword = parser.getSafeProperty('dbPassword', '') return application
def loadNewsPageProperties(filename): '''Create a new dictionary of news pages by passing in a file name to the page properties file.''' sem = Semaphore(semname) sem.put() parser = PropertyDataParser(filename) sem.remove() pages = NewsPageDict() for i in range(0, len(parser.getPropertyAsList('page'))): attrs = parser.getPropertyAttrsAsList('page')[i] name = parser.getPropertyAsList('page')[i] title = attrs['title'] headlineType = attrs['headlineType'] pageType = attrs['pageType'] # TODO-L: refactor 'newspage' to be 'section' newspage = attrs['newspage'] column = attrs['column'] displayNum = attrs['displayNum'] rank = attrs['rank'] isVisible = 'True' if ('isVisible' in attrs): isVisible = attrs['isVisible'] pageOwner = None if ('pageOwner' in attrs): pageOwner = attrs['pageOwner'] isBlog = 'False' if ('isBlog' in attrs): isBlog = attrs['isBlog'] expires = 'Never' if ('expires' in attrs): if (attrs['expires'] == 'Never'): expires = 'Never' else: expires = int(attrs['expires']) # TODO-L: Changes this to a zero-arg constructor newsPage = NewsPage(name, title, headlineType, pageType, newspage, column, displayNum, rank, isVisible, pageOwner, isBlog, expires) if ('id' in attrs): newsPage.id = int(attrs['id']) if ('active' in attrs): newsPage.active = (attrs['active'] in TRUE) if ('feedback' in attrs): newsPage.feedback = (attrs['feedback'] in TRUE) if ('rating' in attrs): newsPage.rating = attrs['rating'] if ('attachments' in attrs): newsPage.attachments = (attrs['attachments'] in TRUE) if ('subTitle' in attrs): newsPage.subTitle = attrs['subTitle'] if ('sortType' in attrs): newsPage.sortType = attrs['sortType'] if (newsPage.sortType == 'date'): newsPage.sortType = 'date: newest first' if ('promptComments' in attrs): newsPage.promptComments = attrs['promptComments'] if ('allowComments' in attrs): newsPage.allowComments = (attrs['allowComments'] in TRUE) pages[parser.getPropertyAsList('page')[i]] = newsPage return pages