OLD | NEW |
| (Empty) |
1 #!/usr/bin/env python | |
2 | |
3 # Utilities to facilitate maintaining one master list of package contents | |
4 # in MANIFEST.in and allow us to import that list into various packaging | |
5 # tools (e.g. rpmbuid and setup.py). | |
6 | |
7 # Define the file in which we maintain package contents. Rather than | |
8 # hard-coding our package contents, to ease maintenance we read the | |
9 # manifest file to obtain the list of files and directories to include. | |
10 MANIFEST_IN = 'MANIFEST.in' | |
11 | |
12 # Define input and output files for customizing the rpm package spec. | |
13 SPEC_IN = 'gsutil.spec.in' | |
14 SPEC_OUT = 'gsutil.spec' | |
15 | |
16 # Root of rpmbuild tree for file enumeration in gsutil.spec file. | |
17 RPM_ROOT = '%{_datadir}/%{name}/' | |
18 | |
19 def parse_manifest(files, dirs): | |
20 '''Parse contents of manifest file and append results to passed lists | |
21 of files and directories. | |
22 ''' | |
23 f = open(MANIFEST_IN, 'r') | |
24 for line in f: | |
25 line = line.strip() | |
26 # Skip empty or comment lines. | |
27 if (len(line) <= 0) or (line[0] == '#'): | |
28 continue | |
29 tokens = line.split() | |
30 if len(tokens) >= 0: | |
31 if tokens[0] == 'include': | |
32 files.extend(tokens[1:]) | |
33 elif tokens[0] == 'recursive-include' and tokens[2] == '*': | |
34 dirs.append(tokens[1]) | |
35 else: | |
36 err = 'Unsupported type ' + tokens[0] + ' in ' + MANIFEST_IN + ' file.' | |
37 raise Exception(err) | |
38 f.close() | |
39 | |
40 # When executed as a separate script, create a dynamically generated rpm | |
41 # spec file. Otherwise, when loaded as a module by another script, no | |
42 # specific actions are taken, other than making utility functions available | |
43 # to the loading script. | |
44 if __name__ == '__main__': | |
45 # Running as main so generate a new rpm spec file. | |
46 files = [] | |
47 dirs = [] | |
48 parse_manifest(files, dirs) | |
49 fin = open(SPEC_IN, 'r') | |
50 fout = open(SPEC_OUT, 'w') | |
51 for line in fin: | |
52 if line.strip() == '###FILES_GO_HERE###': | |
53 for file in files: | |
54 fout.write(RPM_ROOT + file + '\n') | |
55 for dir in dirs: | |
56 fout.write(RPM_ROOT + dir + '/\n') | |
57 else: | |
58 fout.write(line) | |
59 fout.close() | |
60 fin.close() | |
OLD | NEW |