2014-06-21 02:37:48 +00:00
|
|
|
#!/usr/bin/env python
|
2015-07-10 07:27:13 +00:00
|
|
|
from __future__ import unicode_literals, print_function, absolute_import
|
2014-06-21 02:37:48 +00:00
|
|
|
|
|
|
|
"""Locate any orphaned photos.
|
|
|
|
|
|
|
|
Usage: scripts/orphaned-photos.py <path/to/db> <path/to/static/photos>"""
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import codecs
|
|
|
|
import json
|
|
|
|
import glob
|
|
|
|
|
|
|
|
sys.path.append(".")
|
2015-07-10 07:27:13 +00:00
|
|
|
from rophako.settings import Config
|
|
|
|
Config.load_settings()
|
|
|
|
|
2014-06-21 02:37:48 +00:00
|
|
|
import rophako.jsondb as JsonDB
|
|
|
|
|
|
|
|
def main():
|
|
|
|
if len(sys.argv) == 1:
|
2015-07-10 07:27:13 +00:00
|
|
|
print("Usage: {} <path/to/static/photos>".format(__file__))
|
2014-06-21 02:37:48 +00:00
|
|
|
sys.exit(1)
|
|
|
|
|
|
|
|
photo_root = sys.argv[1]
|
|
|
|
|
|
|
|
db = JsonDB.get("photos/index")
|
|
|
|
photos = set()
|
|
|
|
for album in db["albums"]:
|
|
|
|
for key, data in db["albums"][album].iteritems():
|
|
|
|
for img in ["large", "thumb", "avatar"]:
|
|
|
|
photos.add(data[img])
|
|
|
|
|
|
|
|
# Get all the images and compare.
|
|
|
|
for img in glob.glob("{}/*.*".format(photo_root)):
|
|
|
|
fname = img.split("/")[-1]
|
|
|
|
if not fname in photos:
|
2015-07-10 07:27:13 +00:00
|
|
|
print("Orphan:", fname)
|
2014-06-21 02:37:48 +00:00
|
|
|
|
|
|
|
if __name__ == "__main__":
|
2015-02-23 21:10:21 +00:00
|
|
|
main()
|