summaryrefslogtreecommitdiff
path: root/scripts
diff options
context:
space:
mode:
authorMike Frysinger <vapier@chromium.org>2015-06-04 01:45:52 -0400
committerChromeOS Commit Bot <chromeos-commit-bot@chromium.org>2015-06-04 23:27:19 +0000
commitef4839af6e131ab668eb5abafcf73565707a0860 (patch)
tree225f78935161dbcd486a392c418a7851877d2f95 /scripts
parent393b6815a5abbc55d3e4f93814e6f7b1a55de2c1 (diff)
downloadchromite-ef4839af6e131ab668eb5abafcf73565707a0860.tar.gz
check_gdata_token: convert to commandline.ArgumentParser
This makes the module more like our others and uses the standard cmdline interface. Also polish a few things: - use os.path.expanduser instead of $HOME - drop hardcoded gdata setup as our test wrapper handles this now BUG=None TEST=`check_gdata_token` still works BUG=chromium:496565 Change-Id: Iaa88c2397c088abd225757cc19d1cb9ee5a388f7 Reviewed-on: https://chromium-review.googlesource.com/275094 Reviewed-by: Don Garrett <dgarrett@chromium.org> Commit-Queue: Mike Frysinger <vapier@chromium.org> Tested-by: Mike Frysinger <vapier@chromium.org>
Diffstat (limited to 'scripts')
-rw-r--r--scripts/check_gdata_token.py45
-rw-r--r--scripts/check_gdata_token_unittest.py17
2 files changed, 25 insertions, 37 deletions
diff --git a/scripts/check_gdata_token.py b/scripts/check_gdata_token.py
index 435ecf27a..04845c69d 100644
--- a/scripts/check_gdata_token.py
+++ b/scripts/check_gdata_token.py
@@ -2,16 +2,25 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-"""Validate or replace the standard gdata authorization token."""
+"""Validate or replace the standard gdata authorization token.
+
+Run outside of chroot to validate the gdata token file at ~/.gdata_token or
+update it if it has expired.
+To update the token file, there must be a valid credentials file at
+~/.gdata_cred.txt.
+
+If run inside chroot the updated token file is still valid but will not be
+preserved if chroot is deleted.
+"""
from __future__ import print_function
import filecmp
-import optparse
import os
import shutil
from chromite.cbuildbot import constants
+from chromite.lib import commandline
from chromite.lib import cros_build_lib as build_lib
from chromite.lib import operation
@@ -19,8 +28,8 @@ from chromite.lib import operation
MODULE = os.path.splitext(os.path.basename(__file__))[0]
oper = operation.Operation(MODULE)
-TOKEN_FILE = os.path.join(os.environ['HOME'], '.gdata_token')
-CRED_FILE = os.path.join(os.environ['HOME'], '.gdata_cred.txt')
+TOKEN_FILE = os.path.expanduser('~/.gdata_token')
+CRED_FILE = os.path.expanduser('~/.gdata_cred.txt')
def _ChrootPathToExternalPath(path):
@@ -208,35 +217,17 @@ class InsideChroot(object):
self._SaveTokenFile()
-def _CreateParser():
- usage = 'Usage: %prog'
- epilog = ('\n'
- 'Run outside of chroot to validate the gdata '
- 'token file at %r or update it if it has expired.\n'
- 'To update the token file there must be a valid '
- 'credentials file at %r.\n'
- 'If run inside chroot the updated token file is '
- 'still valid but will not be preserved if chroot\n'
- 'is deleted.\n' %
- (TOKEN_FILE, CRED_FILE))
-
- return optparse.OptionParser(usage=usage, epilog=epilog)
+def GetParser():
+ return commandline.ArgumentParser(description=__doc__)
def main(argv):
"""Main function."""
- # Create a copy of args just to be safe.
- argv = list(argv)
-
# No actual options used, but --help is still supported.
- parser = _CreateParser()
- (_options, args) = parser.parse_args(argv)
-
- if args:
- parser.print_help()
- oper.Die('No arguments allowed.')
+ parser = GetParser()
+ _opts = parser.parse_args(argv)
if build_lib.IsInsideChroot():
InsideChroot().Run()
else:
- OutsideChroot(args).Run()
+ OutsideChroot(argv).Run()
diff --git a/scripts/check_gdata_token_unittest.py b/scripts/check_gdata_token_unittest.py
index c0c51f468..d3f18aa3e 100644
--- a/scripts/check_gdata_token_unittest.py
+++ b/scripts/check_gdata_token_unittest.py
@@ -2,7 +2,7 @@
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.
-"""Unit tests for cros_portage_upgrade.py."""
+"""Unit tests for check_gdata_token_unittest.py."""
from __future__ import print_function
@@ -10,19 +10,16 @@ import filecmp
import mox
import os
import shutil
-import sys
-
-sys.path.insert(0, os.path.join(os.path.dirname(os.path.dirname(
- os.path.abspath(__file__))), 'third_party', 'gdata', 'src'))
-import gdata.service
-from gdata.projecthosting import client as gdata_ph_client
-from gdata.spreadsheet import service as gdata_ss_service
from chromite.lib import cros_build_lib as build_lib
from chromite.lib import cros_test_lib
from chromite.lib import gdata_lib
from chromite.scripts import check_gdata_token as cgt
+import gdata.service
+from gdata.projecthosting import client as gdata_ph_client
+from gdata.spreadsheet import service as gdata_ss_service
+
# pylint: disable=protected-access
@@ -38,9 +35,9 @@ class MainTest(cros_test_lib.MoxOutputTestCase):
# Running with --help should exit with code==0.
self.AssertFuncSystemExitZero(cgt.main, argv)
- # Verify that a message beginning with "Usage: " was printed.
+ # Verify that a message beginning with "usage: " was printed.
stdout = output.GetStdout()
- self.assertTrue(stdout.startswith('Usage: '))
+ self.assertTrue(stdout.startswith('usage: '))
def testMainOutsideChroot(self):
"""Test flow outside chroot"""