terom@64: """ terom@64: Top-level gallery state terom@64: """ terom@64: terom@112: import filesystem, folder terom@64: terom@64: from utils import lazy_load terom@64: terom@64: class Gallery (filesystem.Root, folder.Folder) : terom@64: """ terom@64: A Gallery is a single place in the filesystem which acts as a Folder of Images, but had some additional stuff terom@64: """ terom@141: terom@141: def _init_config (self) : terom@141: """ terom@141: Keep using our given .config terom@141: """ terom@141: terom@141: return self.config terom@64: terom@64: def __init__ (self, path, config) : terom@64: """ terom@64: Build a Gallery rooted at the given filesystem path, and using the given user configuration. terom@64: terom@64: XXX: replace path with config.gallery_path? terom@64: """ terom@64: terom@141: # store config for access by Folder.__init__ terom@141: self.config = config terom@141: terom@141: # cooperative terom@141: super(Gallery, self).__init__(path) terom@64: terom@118: @property terom@141: def _app_dir (self) : terom@118: """ terom@141: The dir containing our application data. terom@118: """ terom@118: terom@118: return self.subdir('.degal') terom@118: terom@64: @lazy_load terom@141: def app_dir (self) : terom@64: """ terom@141: The dir containing our application data. terom@64: terom@64: It will be created if it does not exist. terom@64: """ terom@64: terom@73: return self.subdir('.degal', create=True) terom@73: terom@64: @lazy_load terom@64: def stylesheet (self) : terom@64: """ terom@64: The stylesheet file. terom@64: terom@64: It will be copied from internal resources if it does not exist. terom@64: """ terom@64: terom@141: stylesheet = self.app_dir.subfile('style.css') terom@64: terom@82: if not stylesheet.exists() : terom@112: # load the resources dir terom@129: from resources import STATIC_DIR terom@112: terom@112: # copy it from the static resource file terom@112: stylesheet.copy_from(STATIC_DIR.subfile('style.css')) terom@141: terom@141: # elif stylesheet-is-older-than-resources-one: warn terom@64: terom@64: return stylesheet terom@64: