summary refs log tree commit diff stats
BranchCommit messageAuthorAge
masterremove remote registry list push to leveldb because that doesn't work right nowBenjamin Morrison3 years
 
TagDownloadAuthorAge
v0.5.0getwtxt-0.5.0.tar.gz  Benjamin Morrison3 years
v0.4.15getwtxt-0.4.15.tar.gz  Ben Morrison4 years
v0.4.14getwtxt-0.4.14.tar.gz  Ben Morrison4 years
v0.4.13getwtxt-0.4.13.tar.gz  Ben Morrison4 years
v0.4.12getwtxt-0.4.12.tar.gz  Ben Morrison4 years
v0.4.11getwtxt-0.4.11.tar.gz  Ben Morrison4 years
v0.4.10getwtxt-0.4.10.tar.gz  Ben Morrison5 years
v0.4.9getwtxt-0.4.9.tar.gz  Ben Morrison5 years
v0.4.8getwtxt-0.4.8.tar.gz  Ben Morrison5 years
v0.4.7getwtxt-0.4.7.tar.gz  Ben Morrison5 years
v0.4.6getwtxt-0.4.6.tar.gz  Ben Morrison5 years
v0.4.5getwtxt-0.4.5.tar.gz  Ben Morrison5 years
v0.4.4getwtxt-0.4.4.tar.gz  Ben Morrison5 years
v0.4.3getwtxt-0.4.3.tar.gz  Ben Morrison5 years
v0.4.2getwtxt-0.4.2.tar.gz  Ben Morrison5 years
v0.4.1getwtxt-0.4.1.tar.gz  Ben Morrison5 years
v0.4.0getwtxt-0.4.0.tar.gz  Ben Morrison5 years
v0.3.3getwtxt-0.3.3.tar.gz  Ben Morrison5 years
v0.3.2getwtxt-0.3.2.tar.gz  Ben Morrison5 years
v0.3.1getwtxt-0.3.1.tar.gz  Ben Morrison5 years
v0.3.0getwtxt-0.3.0.tar.gz  Ben Morrison5 years
v0.2.4getwtxt-0.2.4.tar.gz  Ben Morrison5 years
v0.2.3getwtxt-0.2.3.tar.gz  Ben Morrison5 years
v0.2.2getwtxt-0.2.2.tar.gz  Ben Morrison5 years
v0.2.1getwtxt-0.2.1.tar.gz  Ben Morrison5 years
v0.2.0getwtxt-0.2.0.tar.gz  Ben Morrison5 years
v0.1.1getwtxt-0.1.1.tar.gz  Ben Morrison5 years
v0.1getwtxt-0.1.tar.gz  Ben Morrison5 years
t .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */ .highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */ .highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */ .highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */ .highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */ .highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */ .highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */ .highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */ .highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */ .highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */ .highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */ .highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */ .highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */ .highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #336699 } /* Name.Variable.Class */ .highlight .vg { color: #dd7700 } /* Name.Variable.Global */ .highlight .vi { color: #3333bb } /* Name.Variable.Instance */ .highlight .vm { color: #336699 } /* Name.Variable.Magic */ .highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */
#!/bin/python
"""
usage: ./convert_papermode_to_metadata.py

This script converts the .paperinfo CSV file in the current directory to an
equivalent .metadata.json file.

ranger used to store metadata in .paperinfo files, but that format was rather
limited, so .metadata.json files were introduced.
"""

import csv
import json
import os
import sys

if sys.version < '3.':
    getuserinput = raw_input
else:
    getuserinput = input

FIELDS = ["name", "year", "title", "authors", "url"]


def replace(source, target):
    if not os.path.exists(source):
        print("Source file `%s' doesn't exist, skipping." % source)
        return

    # Ask for user confirmation if the target file already exists
    if os.path.exists(target):
        sys.stdout.write("Warning: target file `%s' exists! Overwrite? [y/N]")
        userinput = getuserinput()
        if not (userinput.startswith("y") or userinput.startswith("Y")):
            print("Skipping file `%s'" % source)
            return

    result = dict()

    # Read the input file and convert it to a dictionary
    with open(".paperinfo", "r") as infile:
        reader = csv.reader(infile, skipinitialspace=True)
        for lineno, row in enumerate(reader):
            if len(row) != len(FIELDS):
                print("skipping invalid row `%s' on line %d" % (row, lineno))
                continue
            name = row[0]
            entry = {}

            # Filling up the resulting entry dict
            for i, column in enumerate(row[1:]):
                if column:
                    entry[FIELDS[i + 1]] = column

            # Adding the dict if it isn't empty
            if entry:
                result[name] = entry

    # Write the obtained dictionary into the target file
    if result:
        with open(".metadata.json", "w") as outfile:
            json.dump(result, outfile, indent=2)
    else:
        print("Skipping writing `%s' due to a lack of data" % target)

if __name__ == "__main__":
    if set(['--help', '-h']) & set(sys.argv[1:]):
        print(__doc__.strip())
    else:
        replace(".paperinfo", ".metadata.json")