updateqrc.py 1.14 KB
Newer Older
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
#!/usr/bin/env python
import os

qgc_rc  = "qgroundcontrol.qrc"
res_rc  = "qgcresources.qrc"
qgc_exc = "qgroundcontrol.exclusion"
res_exc = "qgcresources.exclusion"

def read_file(filename):
    with open(filename) as src:
        return [line.rstrip().lstrip() for line in src.readlines()]

def process(src, exclusion, dst):
    file1 = read_file(src)
    file2 = read_file(exclusion)
    file3 = open(dst, 'w')
    for line in file1:
        if line not in file2:
            if line.startswith('<qresource') or line.startswith('</qresource'):
                file3.write('\t')
            if line.startswith('<file') or line.startswith('</file'):
                file3.write('\t\t')
            newLine = str(line)
            if line.startswith('<file'):
                newLine = newLine.replace(">", ">../", 1)
            file3.write(newLine + '\n')
        else:
            print 'Excluded:', line
    file3.close()

def main():
    if(os.path.isfile(qgc_exc)):
        process(os.path.join("../",qgc_rc), qgc_exc, qgc_rc)
    if(os.path.isfile(res_exc)):
        process(os.path.join("../",res_rc), res_exc, res_rc)

if __name__ == '__main__':
    main()