Example #1
0
def generate_meta(options):

    categories = (
        'culture',
        'dynasty',
        'movement',
        'period',
        'region',
        'school',
        'style'
        )

    index = {}

    for category in categories:
        index[category] = {}

    for root, dirs, files in os.walk(options.objects):

        for f in files:

            if not f.endswith(".json") :
                continue
            
            path = os.path.join(root, f)
            path = os.path.abspath(path)

            logging.debug("generate meta for %s" % path)

            fh = open(path, 'r')
            data = json.load(fh)

            for category in categories:

                if data.get(category, False):

                    subject = data[category]
                    bucket = "%s.%s" % (category, subject)

                    # update_bucket(options, bucket, path)

                    bucket_name = utils.clean_meta_name(bucket) + ".txt"
                    bucket_path = os.path.join(options.meta, bucket_name)

                    index[category][subject] = bucket_path

    if options.index:

        fh = open(options.index, 'w')
        json.dump(index, fh, indent=2)
        fh.close()

        logging.info("created meta data index at %s" % options.index)
Example #2
0
def generate_meta(options):

    categories = ('culture', 'dynasty', 'movement', 'period', 'region',
                  'school', 'style')

    index = {}

    for category in categories:
        index[category] = {}

    for root, dirs, files in os.walk(options.objects):

        for f in files:

            if not f.endswith(".json"):
                continue

            path = os.path.join(root, f)
            path = os.path.abspath(path)

            logging.debug("generate meta for %s" % path)

            fh = open(path, 'r')
            data = json.load(fh)

            for category in categories:

                if data.get(category, False):

                    subject = data[category]
                    bucket = "%s.%s" % (category, subject)

                    # update_bucket(options, bucket, path)

                    bucket_name = utils.clean_meta_name(bucket) + ".txt"
                    bucket_path = os.path.join(options.meta, bucket_name)

                    index[category][subject] = bucket_path

    if options.index:

        fh = open(options.index, 'w')
        json.dump(index, fh, indent=2)
        fh.close()

        logging.info("created meta data index at %s" % options.index)
Example #3
0
def update_bucket(options, bucket, object_path):

    # sudo put me in utils.py

    bucket = utils.clean_meta_name(bucket)

    object_root = os.path.abspath(options.objects)
    object_path = os.path.abspath(object_path)

    object_path = object_path.replace(object_root + "/", "")
    
    bucket_name = "%s.txt" % bucket
    bucket_path = os.path.join(options.meta, bucket_name)

    logging.debug("%s %s" % (bucket, object_path))

    fh = open(bucket_path, "a")
    fh.write(object_path + "\n")
    fh.close()
Example #4
0
def update_bucket(options, bucket, object_path):

    # sudo put me in utils.py

    bucket = utils.clean_meta_name(bucket)

    object_root = os.path.abspath(options.objects)
    object_path = os.path.abspath(object_path)

    object_path = object_path.replace(object_root + "/", "")

    bucket_name = "%s.txt" % bucket
    bucket_path = os.path.join(options.meta, bucket_name)

    logging.debug("%s %s" % (bucket, object_path))

    fh = open(bucket_path, "a")
    fh.write(object_path + "\n")
    fh.close()