def CmdFetch(ab_client, opts): """Implements the `abutil fetch ab://...` subcommand. Args: ab_client: The androidbuild API client. opts: The command line arguments, result of ArgumentParser's parse_args. Returns: The return status for the command. None or 0 for success. """ branch, target, build_id, filepath = androidbuild.SplitAbUrl(opts.url) if not filepath: raise ValueError('Invalid URL [%s] must specify a filepath.' % opts.url) androidbuild.FetchArtifact(ab_client, branch, target, build_id, filepath, opts.output)
def CmdListBuilds(ab_client, opts): """Implements the `abutil list-builds ab://...` subcommand. Args: ab_client: The androidbuild API client. opts: The command line arguments, result of ArgumentParser's parse_args. Returns: The return status for the command. None or 0 for success. """ branch, target, build_id, filepath = androidbuild.SplitAbUrl(opts.url) if build_id or filepath: raise ValueError('Invalid URL [%s] must only have branch and target.' % opts.url) for build_id in androidbuild.FindRecentBuilds(ab_client, branch, target): print(build_id)
def testSplitAbUrl(self): """Checks that SplitAbUrl works as expected.""" # Full URL. branch, target, build_id, filepath = androidbuild.SplitAbUrl( 'ab://android-build/git_mnc-dev/mickey-userdebug/123456/' 'abc/mickey-img-123456.zip') self.assertEqual(branch, 'git_mnc-dev') self.assertEqual(target, 'mickey-userdebug') self.assertEqual(build_id, 123456) self.assertEqual(filepath, 'abc/mickey-img-123456.zip') # Without the filepath. branch, target, build_id, filepath = androidbuild.SplitAbUrl( 'ab://android-build/git_mnc-dev/mickey-userdebug/123456') self.assertEqual(branch, 'git_mnc-dev') self.assertEqual(target, 'mickey-userdebug') self.assertEqual(build_id, 123456) self.assertIsNone(filepath) # Only branch and target. branch, target, build_id, filepath = androidbuild.SplitAbUrl( 'ab://android-build/git_mnc-dev/mickey-userdebug') self.assertEqual(branch, 'git_mnc-dev') self.assertEqual(target, 'mickey-userdebug') self.assertIsNone(build_id) self.assertIsNone(filepath) # Less than that it's an error. with self.assertRaisesRegexp(ValueError, r'\btoo short\b'): branch, target, build_id, filepath = androidbuild.SplitAbUrl( 'ab://android-build/git_mnc-dev') with self.assertRaisesRegexp(ValueError, r'\btoo short\b'): branch, target, build_id, filepath = androidbuild.SplitAbUrl( 'ab://android-build') with self.assertRaisesRegexp(ValueError, r'\btoo short\b'): branch, target, build_id, filepath = androidbuild.SplitAbUrl( 'ab://android-build/') with self.assertRaisesRegexp(ValueError, r'\bempty target\b'): branch, target, build_id, filepath = androidbuild.SplitAbUrl( 'ab://android-build/git_mnc-dev/') # Non-numeric build_id. with self.assertRaisesRegexp(ValueError, r'\bnon-numeric build_id\b'): branch, target, build_id, filepath = androidbuild.SplitAbUrl( 'ab://android-build/git_mnc-dev/mickey-userdebug/NaN/test.zip') # Wrong protocol. with self.assertRaisesRegexp(ValueError, r'\bab:// protocol\b'): branch, target, build_id, filepath = androidbuild.SplitAbUrl( 'gs://android-build/git_mnc-dev/mickey-userdebug/123456/' 'abc/mickey-img-123456.zip') with self.assertRaisesRegexp(ValueError, r'\bab:// protocol\b'): branch, target, build_id, filepath = androidbuild.SplitAbUrl( 'http://android-build/git_mnc-dev/mickey-userdebug/123456') # Wrong bucket. with self.assertRaisesRegexp(ValueError, r'\s"android-build" bucket\b'): branch, target, build_id, filepath = androidbuild.SplitAbUrl( 'ab://cros-build/git_mnc-dev/mickey-userdebug/123456')