A few more style changes and logic changes fro code review

This commit is contained in:
Scott Zawalski 2010-09-30 08:26:04 -07:00
parent 6f0584cd2d
commit 6332272fa7
2 changed files with 30 additions and 33 deletions

View File

@ -96,6 +96,7 @@ def RevGitFile(filename, key, value):
'http://git.chromium.org/git')
try:
cros_build_lib.RunCommand(git_ssh_config_cmd, shell=True)
cros_build_lib.RunCommand('git pull', shell=True)
cros_build_lib.RunCommand('git config push.default tracking', shell=True)
cros_build_lib.RunCommand('git commit -am "%s"' % description, shell=True)
cros_build_lib.RunCommand('git push', shell=True)
@ -116,9 +117,8 @@ def LoadFilterFile(filter_file):
filter_file: file to load into FILTER_PACKAGES
"""
filter_fh = open(filter_file)
global FILTER_PACKAGES
try:
FILTER_PACKAGES.update(set([filter.strip() for filter in filter_fh]))
FILTER_PACKAGES.update([filter.strip() for filter in filter_fh])
finally:
filter_fh.close()
return FILTER_PACKAGES
@ -155,7 +155,8 @@ def _GsUpload(args):
return
cmd = 'gsutil cp -a public-read %s %s' % (local_file, remote_file)
# TODO: port to use _Run or similar when it is available in cros_build_lib.
# TODO(scottz): port to use _Run or similar when it is available in
# cros_build_lib.
for attempt in range(_RETRIES):
try:
output = cros_build_lib.RunCommand(cmd, print_cmd=False, shell=True)
@ -163,8 +164,8 @@ def _GsUpload(args):
except cros_build_lib.RunCommandError:
print 'Failed to sync %s -> %s, retrying' % (local_file, remote_file)
else:
# TODO: potentially return what failed so we can do something with it but
# for now just print an error.
# TODO(scottz): potentially return what failed so we can do something with
# with it but for now just print an error.
print 'Retry failed uploading %s -> %s, giving up' % (local_file,
remote_file)
@ -178,7 +179,7 @@ def RemoteUpload(files, pool=10):
files: dictionary with keys to local files and values to remote path.
pool: integer of maximum proesses to have at the same time.
"""
# TODO port this to use _RunManyParallel when it is available in
# TODO(scottz) port this to use _RunManyParallel when it is available in
# cros_build_lib
pool = Pool(processes=pool)
workers = []
@ -194,8 +195,6 @@ def RemoteUpload(files, pool=10):
pass
def GenerateUploadDict(local_path, gs_path, strip_str):
"""Build a dictionary of local remote file key pairs for gsutil to upload.
@ -224,12 +223,14 @@ def UploadPrebuilt(build_path, bucket, board=None, git_file=None):
Args:
build_path: The path to the root of the chroot.
bucket: The Google Storage bucket to upload to.
board: The board to upload to Google Storage, if this is None upload
host packages.
git_file: If set, update this file with a host/version combo, commit and
push it.
"""
version = GetVersion()
if board is None:
if not board:
# We are uploading host packages
# TODO: eventually add support for different host_targets
package_path = os.path.join(build_path, _HOST_PACKAGES_PATH)

View File

@ -40,7 +40,7 @@ class TestUpdateFile(unittest.TestCase):
else:
self.fail('Could not find "%s %s" in version file' % (key, val))
def testAddVariableThatDoesnotExist(self):
def testAddVariableThatDoesNotExist(self):
"""Add in a new variable that was no present in the file."""
key = 'x86-testcase'
value = '1234567'
@ -92,15 +92,14 @@ class TestPrebuiltFilters(unittest.TestCase):
class TestPrebuilt(unittest.TestCase):
fake_path = '/b/cbuild/build/chroot/build/x86-dogfood/'
bin_package_mock = ['packages/x11-misc/shared-mime-info-0.70.tbz2',
'packages/x11-misc/util-macros-1.5.0.tbz2',
'packages/x11-misc/xbitmaps-1.1.0.tbz2',
'packages/x11-misc/read-edid-1.4.2.tbz2',
'packages/x11-misc/xdg-utils-1.0.2-r3.tbz2']
files_to_sync = ['/b/cbuild/build/chroot/build/x86-dogfood/packages/x11-misc/shared-mime-info-0.70.tbz2',
'/b/cbuild/build/chroot/build/x86-dogfood/packages/x11-misc/util-macros-1.5.0.tbz2',
'/b/cbuild/build/chroot/build/x86-dogfood/packages/x11-misc/xbitmaps-1.1.0.tbz2',
'/b/cbuild/build/chroot/build/x86-dogfood/packages/x11-misc/read-edid-1.4.2.tbz2',
'/b/cbuild/build/chroot/build/x86-dogfood/packages/x11-misc/xdg-utils-1.0.2-r3.tbz2']
strip_path = '/b/cbuild/build/chroot/build/x86-dogfood/'
files_to_sync = [os.path.join(fake_path, file) for file in bin_package_mock]
def setUp(self):
self.mox = mox.Mox()
@ -109,25 +108,22 @@ class TestPrebuilt(unittest.TestCase):
self.mox.UnsetStubs()
self.mox.VerifyAll()
def _generate_dict_results(self, gs_bucket_path):
"""
Generate a dictionary result similar to GenerateUploadDict
"""
results = {}
for entry in self.files_to_sync:
results[entry] = os.path.join(gs_bucket_path,
entry.replace(self.strip_path, '').lstrip('/'))
results[entry] = os.path.join(
gs_bucket_path, entry.replace(self.fake_path, '').lstrip('/'))
return results
def testGenerateUploadDict(self):
gs_bucket_path = 'gs://chromeos-prebuilt/host/version'
self.mox.StubOutWithMock(cros_build_lib, 'ListFiles')
cros_build_lib.ListFiles(' ').AndReturn(self.files_to_sync)
self.mox.ReplayAll()
result = prebuilt.GenerateUploadDict(' ', gs_bucket_path, self.strip_path)
print result
result = prebuilt.GenerateUploadDict(' ', gs_bucket_path, self.fake_path)
self.assertEqual(result, self._generate_dict_results(gs_bucket_path))