def galleries_list(fspath, stat=False, **args): term.banner("LIST OF GALLERIES") compact = not stat galleries = search_galleries(fspath) if compact: print(term.em('# '), end='') print_gallery_name('Name', term.em) print(term.em("{1}{0}".format('Albums', SYMBOL_SEPARATOR_CLEAR))) for i, gallery in enumerate(galleries): if compact: print(term.p("{:<5d}".format(i)), end='') print_gallery_name(gallery.name) print(term.p("{1}{0}".format( ', '.join(str(x) for x in gallery.albums), SYMBOL_SEPARATOR ))) else: print_gallery_name(gallery.name, term.em, end='\n') print(term.p("{0:>20}: {1}".format('Albums', ', '.join(str(x) for x in gallery.albums)))) nop, notp, sod = gallery_stat(gallery.path) print(term.p("{0:>20}: {1!s}".format("Number of pictures", nop))) print(term.p("{0:>20}: {1}".format("Size on disk", humanfriendly.format_size(sod)))) print()
def create(users, fspath, wspath, htpasswd, **args): verbose = args.get("verbose", False) term.banner("CREATE INDEXES") progress = term.Progress(0, title="Searching:", bar=(verbose is False)) galleries = search_galleries(fspath, load_access=True, load_albums=True, progress=progress.progress) progress.finish() # create default index file create_write(fspath, galleries, path=wspath) if users: users = collect_users(galleries) for user in users: user_path = os.path.join(fspath, "~{0}".format(safe(user.name))) if not os.path.exists(user_path): os.mkdir(user_path) if os.path.isdir(user_path): user_galleries = collect_galleries_for_user(galleries, user) # create user index file create_write(user_path, user_galleries, path=wspath, title=user.name) # create htaccess file for user directory access = Access(authname=TITLE, authuserfile=htpasswd) access.users.extend([user]) access.write(user_path) else: raise IOError("CREATE INDEXES: could not write index for user '{0}'".format(str(user))) term.banner("DONE", type="INFO")
def install(wspath, fspath, htpasswd, **args): """ Install indexes: Create htaccess file with rewrite rules to serve user-specific indexes. Indexes must be created by executing 'index create' command. NOTE: htaccess file will be overwritten! """ term.banner("INSTALL INDEXES") galleries = search_galleries(fspath, load_access=True) users = collect_users(galleries) access = Access(authname=TITLE, authuserfile=htpasswd) access.users.extend(users) access.conf.append(("RewriteEngine", "On")) access.conf.append(("RewriteBase", wspath)) access.conf.append(("RewriteCond", "%{REMOTE_user} ^.+$")) access.conf.append(("RewriteRule", "^$ {0}~%{{REMOTE_user}} [R,L]".format(wspath))) access.write(fspath) term.banner("DONE", type="INFO")
def access_manage(galleries_name_pattern, fspath, **args): galleries = search_galleries(fspath) for gallery in galleries: if fnmatch.fnmatch(gallery.name, galleries_name_pattern): access.manage(gallery_name=gallery.name, fspath=fspath, **args)