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

Unified Diff: prebuilt.py

Issue 3930001: Update prebuilt.py to filter Packages database. (Closed) Base URL: ssh://git@gitrw.chromium.org:9222/crosutils.git
Patch Set: Typo fix Created 10 years, 2 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 | « no previous file | prebuilt_unittest.py » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: prebuilt.py
diff --git a/prebuilt.py b/prebuilt.py
index cf03157a9ff716103b2ca7dea5f0c51020ac3ef3..d14c801dd06c975235d5d680a8098cfec824e9ea 100755
--- a/prebuilt.py
+++ b/prebuilt.py
@@ -9,6 +9,7 @@ import optparse
import os
import re
import sys
+import tempfile
from chromite.lib import cros_build_lib
"""
@@ -190,6 +191,63 @@ def ShouldFilterPackage(file_path):
return False
+def _ShouldFilterPackageFileSection(section):
+ """Return whether an section in the package file should be filtered out.
+
+ Args:
+ section: The section, as a list of strings.
+
+ Returns:
+ True if the section should be excluded.
+ """
+
+ for line in section:
+ if line.startswith("CPV: "):
+ package = line.replace("CPV: ", "").rstrip()
+ if ShouldFilterPackage(package):
+ return True
+ else:
+ return False
+
+
+def FilterPackagesFile(packages_filename):
+ """Read a portage Packages file and filter out private packages.
+
+ The new, filtered packages file is written to a temporary file.
+
+ Args:
+ packages_filename: The filename of the Packages file.
+
+ Returns:
+ filtered_packages: A filtered Packages file, as a NamedTemporaryFile.
+ """
+
+ packages_file = open(packages_filename)
+ filtered_packages = tempfile.NamedTemporaryFile()
+ section = []
+ for line in packages_file:
+ if line == "\n":
+ if not _ShouldFilterPackageFileSection(section):
+ # Looks like this section doesn't contain a private package. Write it
+ # out.
+ filtered_packages.write("".join(section))
+
+ # Start next section.
+ section = []
+
+ section.append(line)
+ else:
+ if not _ShouldFilterPackageFileSection(section):
+ filtered_packages.write("".join(section))
+ packages_file.close()
+
+ # Flush contents to disk.
+ filtered_packages.flush()
+ filtered_packages.seek(0)
+
+ return filtered_packages
+
+
def _GsUpload(args):
"""Upload to GS bucket.
@@ -203,6 +261,10 @@ def _GsUpload(args):
if ShouldFilterPackage(local_file):
return
+ if local_file.endswith("/Packages"):
+ filtered_packages_file = FilterPackagesFile(local_file)
+ local_file = filtered_packages_file.name
+
cmd = '%s cp -a public-read %s %s' % (_GSUTIL_BIN, local_file, remote_file)
# TODO(scottz): port to use _Run or similar when it is available in
# cros_build_lib.
« no previous file with comments | « no previous file | prebuilt_unittest.py » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698