Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Convert .hgignore files to a local recoll skipped[Names|Paths] lines
import os
import sys
from collections import defaultdict
def hgignore2skipped(filename):
localdir = os.path.dirname(os.path.abspath(os.path.expanduser(filename)))
def _iter_skipped():
with open(filename) as lines:
for line in (l.strip() for l in lines):
if line.startswith("syntax:") or line.startswith("#") or not line:
continue
line = line.strip("^$")
if os.path.isdir(os.path.join(localdir, line)):
yield ('Paths', line)
else:
yield ('Names', line)
skipped = defaultdict(list)
for key, value in _iter_skipped():
skipped[key] += [value]
print "[{0}]".format(localdir)
if skipped['Paths']:
print "skippedPaths = {0}".format(" ".join(skipped['Paths']))
if skipped['Names']:
print "skippedNames = {0}".format(" ".join(skipped['Names']))
if __name__ == "__main__":
if len(sys.argv) == 2 and os.path.isfile(sys.argv[1]):
hgignore2skipped(filename=sys.argv[1])
else:
print "Usage: {0} path/to/.hgignore".format(sys.argv[0])
sys.exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment