File: generate_collection.py

package info (click to toggle)
libsdsl 2.1.1%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 3,992 kB
  • sloc: cpp: 42,286; makefile: 1,171; ansic: 318; sh: 201; python: 27
file content (35 lines) | stat: -rw-r--r-- 877 bytes parent folder | download | duplicates (19)
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
#!/usr/bin/python

import fnmatch
import sys
import os
import re

includes = ['*.cpp','*.hpp'] # sources only
includes = r'|'.join([fnmatch.translate(x) for x in includes])

collection_path = "collection.txt"

def main():

    if len(sys.argv) == 1:
        print "Usage ./", sys.argv[0], "directory"
        sys.exit(0)
    cur_dir = sys.argv[1]
    doc_paths = []
    for root, dirs, files in os.walk(cur_dir):
        files = [f for f in files if re.match(includes, f)]
        for f in files:
            doc_path = root+"/"+f
            doc_paths.append(doc_path)

    print "Found ", len(doc_paths), "source files in", cur_dir
    collection_f = open(collection_path,'w')
    for doc_path in doc_paths:
        f = open(doc_path, 'r')
        content = f.read()
        collection_f.write(content)
        collection_f.write('\1')

if __name__ == '__main__':
    main()