/
sorter
executable file
·33 lines (28 loc) · 968 Bytes
/
sorter
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
#! /usr/bin/env python2.6
# vi: expandtab ts=4 sw=4
#
# Takes a 'manifest' style file and outputs a sorted version, warning about
# any duplicates.
#
import os
import sys
files = {}
filename = 'manifest'
# if filename is passed as first argument, use that file instead
if len(sys.argv) >= 2 and os.path.isfile(sys.argv[1]):
filename = sys.argv[1]
for line in open(filename).readlines():
line = line.strip()
if len(line) == 0 or line[0] == '#':
continue
fields = line.split(' ')
if len(fields) < 2:
sys.stderr.write("WARNING: unexpected manifest line: '%s' (removing)\n" % line)
continue
if fields[1] in files and not (
# Don't warn about same directory with identical properties.
fields[0] == 'd' and files[fields[1]] == line):
sys.stderr.write("WARNING: duplicate entry for '%s'\n" % fields[1])
files[fields[1]] = line
for key in sorted(files):
print files[key].rstrip(' ')