summary refs log tree commit diff stats
path: root/doc/tools/convert_papermode_to_metadata.py
blob: a1d6372d051e043e61f0902fa523482bf6dd5442 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#!/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")
ight: bold } /* Generic.Strong */ .highlight .gu { color: #666666 } /* Generic.Subheading */ .highlight .gt { color: #aa0000 } /* Generic.Traceback */ .highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */ .highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */ .highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */ .highlight .kp { color: #008800 } /* Keyword.Pseudo */ .highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */ .highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */ .highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */ .highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */ .highlight .na { color: #336699 } /* Name.Attribute */ .highlight .nb { color: #003388 } /* Name.Builtin */ .highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */ .highlight .no { color: #003366; font-weight: bold } /* Name.Constant */ .highlight .nd { color: #555555 } /* Name.Decorator */ .highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */ .highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */ .highlight .nl { color: #336699; font-style: italic } /* Name.Label */ .highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */ .highlight .py { color: #336699; font-weight: bold } /* Name.Property */ .highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #336699 } /* Name.Variable */ .highlight .ow { color: #008800 } /* Operator.Word */ .highlight .w { color: #bbbbbb } /* Text.Whitespace */ .highlight .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 */
module git.sr.ht/~sircmpwn/aerc

require (
	git.sr.ht/~sircmpwn/getopt v0.0.0-20190214165041-9a4f886f9fc7
	git.sr.ht/~sircmpwn/pty v0.0.0-20190330154901-3a43678975a9
	github.com/danwakefield/fnmatch v0.0.0-20160403171240-cbb64ac3d964
	github.com/ddevault/go-libvterm v0.0.0-20190526194226-b7d861da3810
	github.com/emersion/go-imap v1.0.0-beta.5
	github.com/emersion/go-imap-idle v0.0.0-20190519112320-2704abd7050e
	github.com/emersion/go-message v0.10.3
	github.com/emersion/go-sasl v0.0.0-20190517184301-63aa71ca65a3
	github.com/emersion/go-smtp v0.11.0
	github.com/gdamore/encoding v0.0.0-20151215212835-b23993cbb635 // indirect
	github.com/gdamore/tcell v1.0.0
	github.com/go-ini/ini v1.42.0
	github.com/google/shlex v0.0.0-20181106134648-c34317bd91bf
	github.com/kyoh86/xdg v0.0.0-20171127140545-8db68a8ea76a
	github.com/lucasb-eyer/go-colorful v0.0.0-20180531031333-d9cec903b20c // indirect
	github.com/martinlindhe/base36 v0.0.0-20190418230009-7c6542dfbb41
	github.com/mattn/go-isatty v0.0.3
	github.com/mattn/go-runewidth v0.0.2
	github.com/miolini/datacounter v0.0.0-20171104152933-fd4e42a1d5e0
	github.com/mitchellh/go-homedir v1.1.0
	github.com/pkg/errors v0.8.1
	github.com/riywo/loginshell v0.0.0-20181227004642-c2f4167b2303
	github.com/smartystreets/goconvey v0.0.0-20190330032615-68dc04aab96a // indirect
	github.com/stretchr/testify v1.3.0
	golang.org/x/sys v0.0.0-20190516110030-61b9204099cb // indirect
	gopkg.in/ini.v1 v1.42.0 // indirect
)