[go: up one dir, main page]

Menu

[9a5978]: / ignore.py  Maximize  Restore  History

Download this file

41 lines (39 with data), 1.4 kB

 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
#!/usr/bin/env python
# python script to take svn:ignore information from stdin in "svn propget"
# form and output in stdout regex's representing the same data that
# can be used in the CMake CPACK_SOURCE_IGNORE_FILES list.
# usage:
# svn propget svn:ignore --recursive . | ./ignore.py |less
import sys
ifdirectory = True
ifignore = False
input = sys.stdin.readlines()
for line in input:
if ifdirectory:
ifdirectory = False
ifignore = True
# parse directory line which consists of the directory name,
# a blank-surrounded minus sign, i.e., " - ", and the first file
# pattern to ignore.
try:
directory = line[:line.index(" - ")]
except ValueError, dummymessage:
raise RuntimeError, "stdin is not result of svn propget svn:ignore --recursive . |"
ignore = line[line.index(" - ")+3:-1]
elif ifignore:
ignore = line[:-1]
if ignore == "":
ifignore = False
ifdirectory = True
else:
if directory == ".":
line_out = '"^${PROJECT_SOURCE_DIR}/' + ignore + '$"'
else:
line_out = '"^${PROJECT_SOURCE_DIR}/' + directory + "/" + ignore + '$"'
# Need to escape a regular period with 4 back slashes in CMake which
# means you need 8 here!
line_out = line_out.replace(".", "\\\\\\\\.")
# All name globbing wild cards replaced by regex .* (zero or more occurrences
# of any character).
line_out = line_out.replace("*", ".*")
print line_out