Project

General

Profile

1
#!/usr/bin/env python
2
# Concatenates spreadsheets, removing any duplicated headers
3
# Usage: self [sheet...] >out_sheet
4

    
5
import os.path
6
import sys
7

    
8
sys.path.append(os.path.dirname(__file__)+"/../lib")
9

    
10
import csvs
11
import util
12

    
13
def main():
14
    paths = sys.argv[1:]
15
    
16
    first_path = None
17
    first_info = None
18
    for path in paths:
19
        stream = open(path, 'rb')
20
        
21
        # Get dialect and process first line
22
        info = csvs.stream_info(stream)
23
        def write_header(): sys.stdout.write(info.header_line)
24
        if first_info == None:
25
            first_path = path
26
            first_info = info
27
            write_header()
28
        else:
29
            if not util.classes_eq(info.dialect, first_info.dialect):
30
                raise SystemExit('Spreadsheet error: "'+path
31
                    +'" dialect doesn\'t match "'+first_path+'" dialect')
32
            if info.header_line != first_info.header_line: write_header()
33
                # not a duplicated header
34
        
35
        # Copy remaining lines
36
        while True:
37
            line = stream.readline()
38
            if line == '': break
39
            sys.stdout.write(line)
40
        
41
        stream.close()
42

    
43
main()
(1-1/28)