def makerss(titletext, top, root, files): print 'Building %s' % os.path.join(root, 'photos.rss') dirlen = len(top) + len(os.path.sep) rootpath = root[dirlen:] rootlen = len(rootpath) > 0 and len(rootpath) + len(os.path.sep) or 0 rss = Element('rss', version='2.0') rss.attrib['xmlns:atom'] = NS_ATOM rss.attrib['xmlns:media'] = NS_MEDIA channel = SubElement(rss, 'channel') title = SubElement(channel, 'title') title.text = titletext description = SubElement(channel, 'description') description.text = _( 'This feed enables cooliris http://www.cooliris.com/ in your web browser' ) channel.append(Comment('must have a link for rss')) link = SubElement(channel, 'link') link.text = 'http://localhost/' result = [] for image in files: imagepath = util.www_image_path(image, '.images') if not options.noimages: util.www_image_create(os.path.join(top, image), force=options.force, verbose=options.verbose) thumbpath = util.www_image_path(image, '.thumbs') if not options.nothumbs: util.www_thumb_create(os.path.join(top, image), force=options.force, verbose=options.verbose) if options.verbose >= 3: print 'rootpath:', rootpath, 'image:', image, 'imagepath:', imagepath, 'thumbpath:', thumbpath print 'imagepath[rootlen:]:', imagepath[ rootlen:], 'thumbpath[rootlen:]:', thumbpath[rootlen:] result.append(os.path.join(rootpath, image)) image = image[rootlen:] item = SubElement(channel, 'item') title = SubElement(item, 'title') title.text = image link = SubElement(item, 'link') link.text = urllib.quote(imagepath) description = SubElement(item, 'media:description') description.text = convert_entities( os.path.splitext(os.path.basename(image))[0]) # need to double quote special characters thumbnail = SubElement(item, 'media:thumbnail', url=urllib.quote( urllib.quote(thumbpath[rootlen:]))) content = SubElement(item, 'media:content', url=urllib.quote(urllib.quote( imagepath[rootlen:]))) indent(rss) file = open(os.path.join(root, 'photos.rss'), 'w') print >> file, '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' print >> file, tostring(rss) file.close() return result
def cache_www_thumbnails(defaults): """ cache all image files for web server by creating thumbnails """ import cStringIO import stat print checking('checking web-server thumbnails'), print sys.__stdout__.flush() files = [] for dirname in defaults['directory']: if defaults['dry_run']: print dirname if os.path.isdir(dirname): if defaults['recursive']: files += util.match_files_recursively(dirname, config.IMAGE_SUFFIX) else: files += util.match_files(dirname, config.IMAGE_SUFFIX) else: files += [os.path.abspath(dirname)] files = util.misc.unique(files) for filename in files[:]: thumb = util.www_image_path(filename, '.thumbs') try: sinfo = os.stat(filename) if os.stat(thumb)[ST_MTIME] > sinfo[ST_MTIME]: files.remove(filename) except OSError: pass for bad_dir in ('.svn', '.xvpics', '.thumbnails', '.pics'): if filename.find(os.path.join(os.path.sep, bad_dir + '')) > 0: try: files.remove(filename) except: pass print '%s file%s' % (len(files), len(files) != 1 and 's' or '') for filename in files: fname = filename if len(fname) > 65: fname = fname[:20] + ' [...] ' + fname[-40:] print ' %4d/%-4d %s' % (files.index(filename) + 1, len(files), Unicode(fname)) if defaults['dry_run']: continue util.www_thumb_create(filename) if files: print
def cache_www_thumbnails(defaults): """ cache all image files for web server by creating thumbnails """ import cStringIO import stat print checking('checking web-server thumbnails'), print sys.__stdout__.flush() files = [] for dirname in defaults['directory']: if defaults['dry_run']: print dirname if os.path.isdir(dirname): if defaults['recursive']: files += util.match_files_recursively(dirname, config.IMAGE_SUFFIX) else: files += util.match_files(dirname, config.IMAGE_SUFFIX) else: files += [ os.path.abspath(dirname) ] files = util.misc.unique(files) for filename in files[:]: thumb = util.www_image_path(filename, '.thumbs') try: sinfo = os.stat(filename) if os.stat(thumb)[ST_MTIME] > sinfo[ST_MTIME]: files.remove(filename) except OSError: pass for bad_dir in ('.svn', '.xvpics', '.thumbnails', '.pics'): if filename.find(os.path.join(os.path.sep, bad_dir + '')) > 0: try: files.remove(filename) except: pass print '%s file%s' % (len(files), len(files) != 1 and 's' or '') for filename in files: fname = filename if len(fname) > 65: fname = fname[:20] + ' [...] ' + fname[-40:] print ' %4d/%-4d %s' % (files.index(filename)+1, len(files), Unicode(fname)) if defaults['dry_run']: continue util.www_thumb_create(filename) if files: print
def makerss(titletext, top, root, files): print 'Building %s' % os.path.join(root, 'photos.rss') dirlen = len(top)+len(os.path.sep) rootpath = root[dirlen:] rootlen = len(rootpath) > 0 and len(rootpath)+len(os.path.sep) or 0 rss = Element('rss', version='2.0') rss.attrib['xmlns:atom'] = NS_ATOM rss.attrib['xmlns:media'] = NS_MEDIA channel = SubElement(rss, 'channel') title = SubElement(channel, 'title') title.text = titletext description = SubElement(channel, 'description') description.text = _('This feed enables cooliris http://www.cooliris.com/ in your web browser') channel.append(Comment('must have a link for rss')) link = SubElement(channel, 'link') link.text = 'http://localhost/' result = [] for image in files: imagepath = util.www_image_path(image, '.images') if not options.noimages: util.www_image_create(os.path.join(top, image), force=options.force, verbose=options.verbose) thumbpath = util.www_image_path(image, '.thumbs') if not options.nothumbs: util.www_thumb_create(os.path.join(top, image), force=options.force, verbose=options.verbose) if options.verbose >= 3: print 'rootpath:', rootpath, 'image:', image, 'imagepath:', imagepath, 'thumbpath:', thumbpath print 'imagepath[rootlen:]:', imagepath[rootlen:], 'thumbpath[rootlen:]:', thumbpath[rootlen:] result.append(os.path.join(rootpath, image)) image = image[rootlen:] item = SubElement(channel, 'item') title = SubElement(item, 'title') title.text = image link = SubElement(item, 'link') link.text = urllib.quote(imagepath) description = SubElement(item, 'media:description') description.text = convert_entities(os.path.splitext(os.path.basename(image))[0]) # need to double quote special characters thumbnail = SubElement(item, 'media:thumbnail', url=urllib.quote(urllib.quote(thumbpath[rootlen:]))) content = SubElement(item, 'media:content', url=urllib.quote(urllib.quote(imagepath[rootlen:]))) indent(rss) file = open(os.path.join(root, 'photos.rss'), 'w') print >>file, '<?xml version="1.0" encoding="UTF-8" standalone="yes"?>' print >>file, tostring(rss) file.close() return result