def processPicture(src, depth): FORMATS = ['jpg', 'jpeg', 'png'] extension = os.path.splitext(src)[1][1:] if extension not in FORMATS: return src = os.path.normpath(src) dst_abs = os.path.normpath(os.path.join(TRGROOT, src)) src_abs = os.path.normpath(os.path.join(SRCROOT, src)) dst_dir = os.path.dirname(dst_abs) tn_dst = thumbnail.makeThumbnailPath(src) tn_dst_abs = os.path.normpath(os.path.join(TRGROOT, tn_dst)) tn_dst_dir = os.path.dirname(tn_dst_abs) # Make sure the destination directories exist. utility.makedir(dst_dir) utility.makedir(tn_dst_dir) # Copy the original image over. utility.copy(src_abs, dst_abs) # Create the thumbnail. if utility.newer([src_abs], tn_dst_abs): print '» Thumbnailing', src thumbnail.makeThumbnail(src_abs, tn_dst_abs, (200, 200))
def processWWW(src, depth): src = os.path.normpath(src) prefix = os.path.splitext(src)[0] suffix = os.path.splitext(src)[1][1:] if suffix != DEFAULTLANG: return for lang in languages: if lang == DEFAULTLANG: dst = prefix + '.php' dst_depth = depth else: dst = lang + '/' + prefix + '.php' dst_depth = depth + 1 src = altLang(prefix, lang) dst_abs = os.path.normpath(os.path.join(TRGROOT, dst)) src_abs = os.path.normpath(os.path.join(SRCROOT, src)) dst_dir = os.path.dirname(dst_abs) utility.makedir(dst_dir) if utility.newer([TEMPLATE + lang, src_abs], dst_abs): utility.reportBuilding(dst) strings = { 'ROOT': '../' * dst_depth, 'BASE': '../' * dst_depth, 'CONTENT': convertWWW(src_abs, lang) } file(dst_abs, 'w').write(TEMPLATE_DATA[lang] % strings) else: utility.reportSkipping(dst)
def processHTML(src, depth): src = os.path.normpath(src) prefix = os.path.splitext(src)[0] suffix = os.path.splitext(src)[1][1:] if suffix != DEFAULTLANG: return dst = prefix + '.html' #.' + suffix dst_abs = os.path.normpath(os.path.join(TRGROOT, dst)) src_abs = os.path.normpath(os.path.join(SRCROOT, src)) dst_dir = os.path.dirname(dst_abs) utility.makedir(dst_dir) if utility.newer([src_abs], dst_abs): utility.reportBuilding(src) arguments = [ '--no-generator', '--language=' + suffix, '--no-source-link', '--no-datestamp', '--output-encoding=iso-8859-15', '--target-suffix=html', '--stylesheet=' + '../' * depth + 'aros.css?v=1.3', '--link-stylesheet', src_abs, dst_abs ] publisher = Publisher() publisher.set_reader('standalone', None, 'restructuredtext') publisher.set_writer('html') publisher.publish(argv=arguments) else: utility.reportSkipping(dst)
def makeNews(): NEWS_SRC_DIR = os.path.join(SRCROOT, 'news/data') NEWS_DST_DIR = os.path.join(SRCROOT, 'news/data') NEWS_SRC_INDX = os.path.join(SRCROOT, 'news/index.') NEWS_SRC_ARCH = os.path.join(SRCROOT, 'news/archive/') NOOFITEMS = 5 news = {} # Lists of news, per language, to determine the recent news archives = { } # Lists of news, per year per language, to list news per year # Get list of news and archive items for each language # Initialise the languages for lang in languages: news[lang] = [] archives[lang] = {} # Do all the year directories for yeardirname in os.listdir(NEWS_SRC_DIR): yeardirpath = os.path.join(NEWS_SRC_DIR, yeardirname) for lang in languages: archives[lang][yeardirname] = list() # Do all the news item files (originals) in a specific year directory for filename in os.listdir(yeardirpath): date, ext = os.path.splitext(filename) if ext == '.en' and len(date) == 8 and date.isdigit(): year = date[:4] if year != yeardirname: print 'Error: News item "' + date + '" found in news year "' + yeardirname + '".' # Generate a recent news source list and year news source lists for each language for lang in languages: lang_filepath = os.path.join( yeardirpath, altLang(date, lang, yeardirpath)) news[lang].append(lang_filepath) archives[lang][year].append(lang_filepath) # Disadvantage of this approach is that sorting the lists will have to compare entire paths. # Check whether we actually found any news (we test for DEFAULTLANG, but all news lists have the same length) if not len(news[DEFAULTLANG]): return False # Generate news and archive ReST files for lang in languages: news[lang].sort(reverse=True) current = news[lang][:NOOFITEMS] _dst = NEWS_SRC_INDX + lang # Set up translated title dictionary config = gallery.ConfigParser() config.read(os.path.join('targets/www/template/languages', lang)) _T = {} for option in config.options('titles'): _T[option] = config.get('titles', option) # Create a recent news page if utility.newer(current, _dst): output = file(_dst, 'w') output.write(utility.titleReST(_T['news'])) for filepath in current: output.write( utility.htmlReST(' <a name="%s"></a>\n' % filepath[-11:-3]) ) # Not ideal, but at least legal HTML output.write(utility.drctReST('include', filepath)) output.close() # Create year news pages for year in archives[lang].keys(): if len(archives[lang][year]): archives[lang][year].sort(reverse=True) _dst = os.path.join(NEWS_SRC_ARCH + year + '.' + lang) if utility.newer(archives[lang][year], _dst): output = file(_dst, 'w') output.write( utility.titleReST(_T['news-archive-for'] + ' ' + year)) for filepath in archives[lang][year]: output.write( utility.htmlReST( ' <a name="%s"></a>\n' % filepath[-11:-3])) # At least legal HTML output.write(utility.drctReST('include', filepath)) output.close() return True