Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: third_party/gsutil/pkg_util.py

Issue 12317103: Added gsutil to depot tools (Closed) Base URL: https://chromium.googlesource.com/chromium/tools/depot_tools.git@master
Patch Set: Created 7 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « third_party/gsutil/oauth2_plugin/oauth2_plugin.py ('k') | third_party/retry_decorator/LICENSE.google » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: third_party/gsutil/pkg_util.py
diff --git a/third_party/gsutil/pkg_util.py b/third_party/gsutil/pkg_util.py
new file mode 100644
index 0000000000000000000000000000000000000000..8a0befc6b1642a53187f88393c347669120c284d
--- /dev/null
+++ b/third_party/gsutil/pkg_util.py
@@ -0,0 +1,60 @@
+#!/usr/bin/env python
+
+# Utilities to facilitate maintaining one master list of package contents
+# in MANIFEST.in and allow us to import that list into various packaging
+# tools (e.g. rpmbuid and setup.py).
+
+# Define the file in which we maintain package contents. Rather than
+# hard-coding our package contents, to ease maintenance we read the
+# manifest file to obtain the list of files and directories to include.
+MANIFEST_IN = 'MANIFEST.in'
+
+# Define input and output files for customizing the rpm package spec.
+SPEC_IN = 'gsutil.spec.in'
+SPEC_OUT = 'gsutil.spec'
+
+# Root of rpmbuild tree for file enumeration in gsutil.spec file.
+RPM_ROOT = '%{_datadir}/%{name}/'
+
+def parse_manifest(files, dirs):
+ '''Parse contents of manifest file and append results to passed lists
+ of files and directories.
+ '''
+ f = open(MANIFEST_IN, 'r')
+ for line in f:
+ line = line.strip()
+ # Skip empty or comment lines.
+ if (len(line) <= 0) or (line[0] == '#'):
+ continue
+ tokens = line.split()
+ if len(tokens) >= 0:
+ if tokens[0] == 'include':
+ files.extend(tokens[1:])
+ elif tokens[0] == 'recursive-include' and tokens[2] == '*':
+ dirs.append(tokens[1])
+ else:
+ err = 'Unsupported type ' + tokens[0] + ' in ' + MANIFEST_IN + ' file.'
+ raise Exception(err)
+ f.close()
+
+# When executed as a separate script, create a dynamically generated rpm
+# spec file. Otherwise, when loaded as a module by another script, no
+# specific actions are taken, other than making utility functions available
+# to the loading script.
+if __name__ == '__main__':
+ # Running as main so generate a new rpm spec file.
+ files = []
+ dirs = []
+ parse_manifest(files, dirs)
+ fin = open(SPEC_IN, 'r')
+ fout = open(SPEC_OUT, 'w')
+ for line in fin:
+ if line.strip() == '###FILES_GO_HERE###':
+ for file in files:
+ fout.write(RPM_ROOT + file + '\n')
+ for dir in dirs:
+ fout.write(RPM_ROOT + dir + '/\n')
+ else:
+ fout.write(line)
+ fout.close()
+ fin.close()
« no previous file with comments | « third_party/gsutil/oauth2_plugin/oauth2_plugin.py ('k') | third_party/retry_decorator/LICENSE.google » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698