Beispiel #1
0
def read_optional_image_metadata (album_path, pattern ):
    """Checks if a given folder contains an INFO_FILE_NAME and tries to obtain
    optional image information from a section named 'ImageInfo'"""

    if not album_path:
        album_path = ''
    album_path = path.abspath(album_path)
    if not path.exists(album_path):
        raise TypeError('album_path does not exist!')
    if not pattern:
        raise TypeError('filename not provided!')

    subfiles = get_immediate_subfiles(album_path)
    info_ini_file = None
    for subfile in subfiles:
        matching = match(pattern, subfile.lower())
        if matching != None:
            info_ini_file = path.join(album_path, subfile)

    # set default values
    image_infos = {}

    # try to read file
    if info_ini_file and path.exists(info_ini_file):
        config = configparser()
        config.readfp(open(info_ini_file, 'r', 'utf8'))
        if config.has_section('ImageInfo'):
            options = config.options('ImageInfo')
            for option in options:
                #print 'Adding detailed info for file {0}'.format(option)
                info = config.get('ImageInfo', option).strip()
                image_infos[option.lower()] = info

    return image_infos
Beispiel #2
0
def read_optional_image_metadata(album_path, pattern):
    """Checks if a given folder contains an INFO_FILE_NAME and tries to obtain
    optional image information from a section named 'ImageInfo'"""

    if not album_path:
        album_path = ''
    album_path = path.abspath(album_path)
    if not path.exists(album_path):
        raise TypeError('album_path does not exist!')
    if not pattern:
        raise TypeError('filename not provided!')

    subfiles = get_immediate_subfiles(album_path)
    info_ini_file = None
    for subfile in subfiles:
        matching = match(pattern, subfile.lower())
        if matching != None:
            info_ini_file = path.join(album_path, subfile)

    # set default values
    image_infos = {}

    # try to read file
    if info_ini_file and path.exists(info_ini_file):
        config = configparser()
        config.readfp(open(info_ini_file, 'r', 'utf8'))
        if config.has_section('ImageInfo'):
            options = config.options('ImageInfo')
            for option in options:
                #print 'Adding detailed info for file {0}'.format(option)
                info = config.get('ImageInfo', option).strip()
                image_infos[option.lower()] = info

    return image_infos
Beispiel #3
0
def read_optional_album_metadata (album_path, pattern ):
    """Checks if a given folder contains an INFO_FILE_NAME and tries to obtain
    optional album information from a section named 'AlbumInfo'"""

    if not album_path:
        album_path = ''
    album_path = path.abspath(album_path)
    if not path.exists(album_path):
        raise TypeError('album_path does not exist!')
    if not pattern:
        raise TypeError('filename not provided!')

    subfiles = get_immediate_subfiles(album_path)
    info_ini_file = None
    for subfile in subfiles:
        matching = match(pattern, subfile.lower())
        if matching != None:
            info_ini_file = path.join(album_path, subfile)

    # set default values
    album_title = path.basename(album_path)
    album_description = ''
    album_cover = None
    album_sorted_rev = False
    album_hide_cover = False
    modified_albums_on_top = False
    ignore_in_book = False

    # try to read file
    if info_ini_file and path.exists(info_ini_file):
        config = configparser()
        config.readfp(open(info_ini_file, 'r', 'utf8'))
        if config.has_option('AlbumInfo', 'Title'):
            album_title = config.get('AlbumInfo', 'Title')
        if config.has_option('AlbumInfo', 'Description'):
            album_description = config.get('AlbumInfo', 'Description')
        if config.has_option('AlbumInfo', 'CoverImage'):
            album_cover = config.get('AlbumInfo', 'CoverImage')
        if config.has_option('AlbumInfo', 'ReverseImages'):
            reverse = config.get('AlbumInfo', 'ReverseImages')
            if reverse == 'True':
                album_sorted_rev = True
        if config.has_option('AlbumInfo', 'HideCover'):
            hidecover = config.get('AlbumInfo', 'HideCover')
            if hidecover == 'True':
                album_hide_cover = True
        if config.has_option('AlbumInfo', 'ModifiedAlbumsOnTop'):
            modtop = config.get('AlbumInfo', 'ModifiedAlbumsOnTop')
            if modtop == 'True':
                modified_albums_on_top = True
        if config.has_option('AlbumInfo', 'IgnoreInBook'):
            igbook = config.get('AlbumInfo', 'IgnoreInBook')
            if igbook == 'True':
                ignore_in_book = True

    return (album_title, album_description, album_cover, album_sorted_rev,
            album_hide_cover, modified_albums_on_top, ignore_in_book)
Beispiel #4
0
def read_optional_album_metadata(album_path, pattern):
    """Checks if a given folder contains an INFO_FILE_NAME and tries to obtain
    optional album information from a section named 'AlbumInfo'"""

    if not album_path:
        album_path = ''
    album_path = path.abspath(album_path)
    if not path.exists(album_path):
        raise TypeError('album_path does not exist!')
    if not pattern:
        raise TypeError('filename not provided!')

    subfiles = get_immediate_subfiles(album_path)
    info_ini_file = None
    for subfile in subfiles:
        matching = match(pattern, subfile.lower())
        if matching != None:
            info_ini_file = path.join(album_path, subfile)

    # set default values
    album_title = path.basename(album_path)
    album_description = ''
    album_cover = None
    album_sorted_rev = False
    album_hide_cover = False
    modified_albums_on_top = False
    ignore_in_book = False

    # try to read file
    if info_ini_file and path.exists(info_ini_file):
        config = configparser()
        config.readfp(open(info_ini_file, 'r', 'utf8'))
        if config.has_option('AlbumInfo', 'Title'):
            album_title = config.get('AlbumInfo', 'Title')
        if config.has_option('AlbumInfo', 'Description'):
            album_description = config.get('AlbumInfo', 'Description')
        if config.has_option('AlbumInfo', 'CoverImage'):
            album_cover = config.get('AlbumInfo', 'CoverImage')
        if config.has_option('AlbumInfo', 'ReverseImages'):
            reverse = config.get('AlbumInfo', 'ReverseImages')
            if reverse == 'True':
                album_sorted_rev = True
        if config.has_option('AlbumInfo', 'HideCover'):
            hidecover = config.get('AlbumInfo', 'HideCover')
            if hidecover == 'True':
                album_hide_cover = True
        if config.has_option('AlbumInfo', 'ModifiedAlbumsOnTop'):
            modtop = config.get('AlbumInfo', 'ModifiedAlbumsOnTop')
            if modtop == 'True':
                modified_albums_on_top = True
        if config.has_option('AlbumInfo', 'IgnoreInBook'):
            igbook = config.get('AlbumInfo', 'IgnoreInBook')
            if igbook == 'True':
                ignore_in_book = True

    return (album_title, album_description, album_cover, album_sorted_rev,
            album_hide_cover, modified_albums_on_top, ignore_in_book)
Beispiel #5
0
    def generate_view_context(self, request_path):
        """The core "magic" method that reads the requested album filesystem
        path related to the virtual album path from the request and obtains all
        necessary information to create a neat web photo album"""

        local_albumpath_abs = convert_url_path_to_local_filesystem_path(
                  self.main_images_path, request_path)
        local_albumpath_rel = convert_url_path_to_local_filesystem_path(
                                                     '', request_path)
        mkdirs(path.join (self.static_fullsize_path, local_albumpath_rel))
        mkdirs(path.join (self.static_ithumbs_path, local_albumpath_rel))

        (album_title, album_description, album_cover, reversed_sorting,
         hide_cover, mods_on_top, _) = read_optional_album_metadata (
            local_albumpath_abs, pyntrest_config.META_INI_FILE_PATTERN)

        # setup sub albums
        subalbums = []
        for subalbum_name in get_immediate_subdirectories(local_albumpath_abs):
            self.process_subalbum (subalbums, subalbum_name,
            local_albumpath_rel, local_albumpath_abs)

        # sort subalbums by path
        if (mods_on_top):
            subalbums = sorted(subalbums, key=lambda subalbum:
                subalbum.last_modified, reverse=True)
        else:
            subalbums = sorted(subalbums, key=lambda subalbum:
                subalbum.path, reverse=False)

        # setup images
        images = []
        for image_name in listdir(local_albumpath_abs):
            subimage = self.process_subimage(image_name,
                                    local_albumpath_rel, local_albumpath_abs)
            if subimage is None:
                continue
            if (album_cover is None or hide_cover is False):
                images.append(subimage)
            else:
                if album_cover == image_name:
                    pass # ignore
                else:
                    images.append(subimage)

        # update image descriptions
        image_descriptions = read_optional_image_metadata(
                    local_albumpath_abs, pyntrest_config.META_INI_FILE_PATTERN)
        for image in images:
            basename = path.basename(image.location).lower()
            try:
                image_description = image_descriptions[basename]
                image.description = image_description
            except KeyError:
                pass # Ignore

        # sort images by path
        images = sorted(images, key=lambda albumimage: albumimage.location,
                        reverse=reversed_sorting)

        # setup breadcrumb
        breadcrumbs = []
        breadcrumb_paths = get_absolute_breadcrumb_filesystem_paths (
            request_path)
        local_albumpath_abs = self.main_images_path
        path_string = ''
        for breadcrumb_path in breadcrumb_paths:
            local_albumpath_abs = path.join(local_albumpath_abs,
                breadcrumb_path)
            path_string = path_string + '/' + breadcrumb_path
            path_string = sub ('[/]+' , '/', path_string)
            album_title, album_description, _, _, _, _, _= (
                read_optional_album_metadata (local_albumpath_abs,
                    pyntrest_config.META_INI_FILE_PATTERN))
            url_path = path_string
            if pyntrest_config.EXTERNAL_BASE_URL is not None:
                url_path  = pyntrest_config.EXTERNAL_BASE_URL + url_path

            web_path = WebPath(title=album_title, path=url_path)
            breadcrumbs.append(web_path)
        page_title = breadcrumbs[0].title
        breadcrumbs[0].title = pyntrest_config.WORDING_HOME

        # check for intro text
        intro_content = None
        intro_file = None
        subfiles = get_immediate_subfiles(local_albumpath_abs)
        for subfile in subfiles:
            matching = match(pyntrest_config.INTRO_MD_FILE_PATTERN,
                             subfile.lower())
            if matching != None:
                intro_file = path.join(local_albumpath_abs, subfile)

        if intro_file and path.isfile(intro_file):
            intro_content, _ = get_html_content(intro_file)

        # show header?
        show_breadcrumb = True
        first_page = len(breadcrumbs) == 1
        try:
            if first_page and pyntrest_config.SUPPRESS_BREADCRUMB_ON_HOME:
                show_breadcrumb = False
        except AttributeError:
            pass # just show it.

        context = { 'page_title': page_title,
                    'col_width': pyntrest_config.IMAGE_THUMB_WIDTH,
                    'col_height' : pyntrest_config.IMAGE_THUMB_HEIGHT,
                    'images': images,
                    'show_breadcrum': False,
                    'first_page': first_page,
                    'subalbums': subalbums,
                    'album_title' : album_title,
                    'album_description' : album_description,
                    'lang_images' : pyntrest_config.WORDING_IMAGES,
                    'lang_albums' : pyntrest_config.WORDING_ALBUM,
                    'breadcrumbs' : breadcrumbs,
                    'show_breadcrumb': show_breadcrumb,
                    'show_headings' :
                        pyntrest_config.SHOW_ALBUM_IMAGES_WORDINGS,
                   'intro_content' : intro_content}

        return context