2013-11-29 19:16:10 +00:00
|
|
|
#!/usr/bin/env python
|
2013-11-26 22:32:11 +00:00
|
|
|
import os
|
|
|
|
os.environ ['PYTHONPATH'] = '/home/daz/Documents/Projects/Py/django/papiez_ipsum'
|
|
|
|
os.environ['DJANGO_SETTINGS_MODULE'] = 'papiez_ipsum.settings'
|
2013-12-22 13:31:17 +00:00
|
|
|
from glob import glob
|
2013-12-23 18:53:20 +00:00
|
|
|
from papiezator.models import PopeImage, Pope
|
|
|
|
from papiezator.pope_utils import parse_pope, pope_or_death
|
2013-11-26 22:32:11 +00:00
|
|
|
from os import path
|
2013-11-29 19:16:10 +00:00
|
|
|
from optparse import OptionParser
|
2013-12-22 13:31:17 +00:00
|
|
|
import ast
|
2013-11-26 22:32:11 +00:00
|
|
|
|
|
|
|
PREFIX = "popes"
|
|
|
|
|
|
|
|
|
|
|
|
|
2013-11-29 19:16:10 +00:00
|
|
|
|
2013-12-22 13:31:17 +00:00
|
|
|
def init_pope(meta):
|
2013-12-23 18:53:20 +00:00
|
|
|
pope = pope_or_death(Pope, id=meta["id"])
|
2013-12-22 13:31:17 +00:00
|
|
|
|
|
|
|
if pope:
|
|
|
|
return pope
|
|
|
|
else:
|
2013-12-23 18:53:20 +00:00
|
|
|
pope = Pope(meta["id"], meta["name"])
|
2013-12-22 13:31:17 +00:00
|
|
|
pope.save()
|
|
|
|
return pope
|
|
|
|
|
|
|
|
|
|
|
|
def add_pope_entry(pope, path):
|
2013-12-23 18:53:20 +00:00
|
|
|
if pope_or_death(PopeImage, path=path):
|
|
|
|
print('-', end='')
|
2013-12-22 13:31:17 +00:00
|
|
|
return False
|
|
|
|
pope_image = parse_pope(path)
|
2013-12-23 18:53:20 +00:00
|
|
|
pope_image.pope = pope
|
2013-12-22 13:31:17 +00:00
|
|
|
pope_image.save()
|
2013-12-23 18:53:20 +00:00
|
|
|
print('+', end='')
|
2013-12-22 13:31:17 +00:00
|
|
|
return pope_image
|
|
|
|
|
2013-11-29 19:16:10 +00:00
|
|
|
def main():
|
2013-12-22 13:31:17 +00:00
|
|
|
existing_popes = []
|
2013-11-29 19:16:10 +00:00
|
|
|
parser = OptionParser()
|
|
|
|
options, args = parser.parse_args()
|
|
|
|
|
2013-12-22 13:31:17 +00:00
|
|
|
pope_lists = glob("popes/*_list")
|
|
|
|
|
|
|
|
for pl in pope_lists:
|
|
|
|
pope = pl.split('_')[0]
|
2013-12-23 18:53:20 +00:00
|
|
|
print(pope)
|
2013-12-22 13:31:17 +00:00
|
|
|
|
|
|
|
if os.path.exists(pope+"_meta"):
|
|
|
|
with open(pope+"_meta") as file:
|
|
|
|
meta = ast.literal_eval(file.read())
|
|
|
|
|
|
|
|
if meta["id"] in existing_popes:
|
|
|
|
raise "jp2gmd"
|
|
|
|
|
|
|
|
existing_popes.append(meta["id"])
|
|
|
|
|
|
|
|
pope = init_pope(meta)
|
|
|
|
with open(pl) as file:
|
|
|
|
for line in file:
|
|
|
|
line = line.rstrip()
|
|
|
|
line = path.join("popes", line)
|
|
|
|
add_pope_entry(pope, line)
|
2013-11-29 19:16:10 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|
2013-11-26 22:32:11 +00:00
|
|
|
|