Created
May 15, 2011 15:55
-
-
Save naufraghi/973260 to your computer and use it in GitHub Desktop.
Convert .hgignore files to a local recoll skipped[Names|Paths] lines
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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