diff options
author | Steve Fung <stevefung@google.com> | 2016-04-18 17:46:26 -0700 |
---|---|---|
committer | Steve Fung <stevefung@google.com> | 2016-04-19 18:51:33 +0000 |
commit | 7d2918e6efb0936eb1c45980451678f625b4f638 (patch) | |
tree | 612944595a065afff2798ac1fa3fcad43de5b3e1 | |
parent | b3baeb0038327709517abe6c9ae3e7682a00e0e5 (diff) | |
download | bdk-7d2918e6efb0936eb1c45980451678f625b4f638.tar.gz |
metrics: Use proper naming conventions
Fixed up all the instances of CapWords() method names to use the
proper PEP8 lower_with_under() style.
Bug: 27836335
Test: `python test_runner.py` passes
Test: pylint passes
Change-Id: I130dcd3db000994d19de09d01c8f3aa826044244
-rw-r--r-- | cli/lib/bdk.py | 2 | ||||
-rw-r--r-- | cli/lib/cli/clicommand.py | 2 | ||||
-rw-r--r-- | cli/lib/metrics/data_types/event.py | 4 | ||||
-rw-r--r-- | cli/lib/metrics/data_types/exception.py | 10 | ||||
-rw-r--r-- | cli/lib/metrics/data_types/exception_unittest.py | 4 | ||||
-rw-r--r-- | cli/lib/metrics/data_types/hit.py | 4 | ||||
-rw-r--r-- | cli/lib/metrics/data_types/hit_stub.py | 4 | ||||
-rw-r--r-- | cli/lib/metrics/data_types/hit_unittest.py | 8 | ||||
-rw-r--r-- | cli/lib/metrics/data_types/timing.py | 10 | ||||
-rw-r--r-- | cli/lib/metrics/data_types/timing_unittest.py | 4 | ||||
-rw-r--r-- | cli/lib/metrics/hit_store.py | 16 | ||||
-rw-r--r-- | cli/lib/metrics/hit_store_stub.py | 4 | ||||
-rw-r--r-- | cli/lib/metrics/hit_store_unittest.py | 10 | ||||
-rw-r--r-- | cli/lib/metrics/metrics_util.py | 24 | ||||
-rw-r--r-- | cli/lib/metrics/metrics_util_stub.py | 4 |
15 files changed, 55 insertions, 55 deletions
diff --git a/cli/lib/bdk.py b/cli/lib/bdk.py index 747fa10..86140b8 100644 --- a/cli/lib/bdk.py +++ b/cli/lib/bdk.py @@ -66,7 +66,7 @@ def main(): # pylint: disable=broad-except except Exception as e: metrics_util.send_hit_and_retries( - exception.ExceptionHit.FromException(e, is_fatal=True)) + exception.ExceptionHit.from_exception(e, is_fatal=True)) if bdk_cli.args.debug: raise else: diff --git a/cli/lib/cli/clicommand.py b/cli/lib/cli/clicommand.py index 4fec8e3..67b5154 100644 --- a/cli/lib/cli/clicommand.py +++ b/cli/lib/cli/clicommand.py @@ -245,7 +245,7 @@ class Command(object): if result is not None: self._timer.Stop() metrics_util.send_hit_and_retries( - timing.Timing.FromTimer(self._timer, result)) + timing.Timing.from_timer(self._timer, result)) return result diff --git a/cli/lib/metrics/data_types/event.py b/cli/lib/metrics/data_types/event.py index 9985d4a..d93ca28 100644 --- a/cli/lib/metrics/data_types/event.py +++ b/cli/lib/metrics/data_types/event.py @@ -51,9 +51,9 @@ class Event(hit.Hit): self.label = label self.value = value - def GetFields(self): + def get_fields(self): """See base class.""" - params = super(Event, self).GetFields() + params = super(Event, self).get_fields() params.update({self.GA_KEY_EVENT_CATEGORY: self.category, self.GA_KEY_EVENT_ACTION: self.action}) if self.label: diff --git a/cli/lib/metrics/data_types/exception.py b/cli/lib/metrics/data_types/exception.py index e89e636..b966e4d 100644 --- a/cli/lib/metrics/data_types/exception.py +++ b/cli/lib/metrics/data_types/exception.py @@ -48,17 +48,17 @@ class ExceptionHit(hit.Hit): self.exception_desc = exception_desc self.is_fatal = is_fatal - def GetFields(self): + def get_fields(self): """See base class.""" - params = super(ExceptionHit, self).GetFields() + params = super(ExceptionHit, self).get_fields() params.update({self.GA_KEY_EXCEPTION_DESCRIPTION: self.exception_desc, self.GA_KEY_EXCEPTION_FATAL: self.is_fatal}) return params @classmethod - def FromException(cls, exception, is_fatal=False): + def from_exception(cls, exception, is_fatal=False): """Converts an Exception object to an ExceptionHit""" - return cls(metrics_util.MetaData(), + return cls(metrics_util.get_meta_data(), type(exception).__name__, is_fatal=is_fatal, - custom_dimensions=metrics_util.CustomDimensions()) + custom_dimensions=metrics_util.get_custom_dimensions()) diff --git a/cli/lib/metrics/data_types/exception_unittest.py b/cli/lib/metrics/data_types/exception_unittest.py index e516ed8..0a32458 100644 --- a/cli/lib/metrics/data_types/exception_unittest.py +++ b/cli/lib/metrics/data_types/exception_unittest.py @@ -50,13 +50,13 @@ class ExceptionTest(hit_unittest.HitTest): }) def test_from_exception(self): - """Test exception.ExceptionHit.FromException() method.""" + """Test exception.ExceptionHit.from_exception() method.""" metrics_util_stub_ = metrics_util_stub.StubMetricsUtil(self.data, {}) exception.metrics_util = metrics_util_stub_ ex = error.Error('Test error') - self.hit = exception.ExceptionHit.FromException(ex, is_fatal=True) + self.hit = exception.ExceptionHit.from_exception(ex, is_fatal=True) self.expected_fields = { exception.ExceptionHit.GA_KEY_PROTOCOL_VERSION: self.data.version, exception.ExceptionHit.GA_KEY_TRACKING_ID: self.data.app_id, diff --git a/cli/lib/metrics/data_types/hit.py b/cli/lib/metrics/data_types/hit.py index 3105a25..659c067 100644 --- a/cli/lib/metrics/data_types/hit.py +++ b/cli/lib/metrics/data_types/hit.py @@ -72,7 +72,7 @@ class Hit(object): self.cds = custom_dimensions or {} self.cms = custom_metrics or {} - def GetFields(self): + def get_fields(self): """Returns all fields as a dictionary of { param : value }.""" params = {self.GA_KEY_PROTOCOL_VERSION: self.version, self.GA_KEY_TRACKING_ID: self.app_id, @@ -87,7 +87,7 @@ class Hit(object): return params @classmethod - def SendFields(cls, fields): + def send_fields(cls, fields): """Sends the hit described by fields to Google Analytics. Args: diff --git a/cli/lib/metrics/data_types/hit_stub.py b/cli/lib/metrics/data_types/hit_stub.py index b580055..ca2d593 100644 --- a/cli/lib/metrics/data_types/hit_stub.py +++ b/cli/lib/metrics/data_types/hit_stub.py @@ -41,12 +41,12 @@ class StubHit(object): class Hit(hit.Hit): """Stub class that extends a hit object. - Override the SendFields function to not actually send data, and instead + Override the send_fields function to not actually send data, and instead store the fields to the StubHit.last_send variable so that it can be checked later. """ @classmethod - def SendFields(cls, fields): + def send_fields(cls, fields): StubHit.last_send = fields return True diff --git a/cli/lib/metrics/data_types/hit_unittest.py b/cli/lib/metrics/data_types/hit_unittest.py index e236610..58afd5e 100644 --- a/cli/lib/metrics/data_types/hit_unittest.py +++ b/cli/lib/metrics/data_types/hit_unittest.py @@ -102,14 +102,14 @@ class HitTest(unittest.TestCase): self.setup_hit() def test_get_fields(self): - """Test that hit.GetFields() returns the expected fields.""" - fields = self.hit.GetFields() + """Test that hit.get_fields() returns the expected fields.""" + fields = self.hit.get_fields() self.assertEqual(fields, self.expected_fields) def test_send_fields(self): - """Test that hit.Hit.SendFields(fields) correctly sends the fields.""" + """Test that hit.Hit.send_fields(fields) correctly sends the fields.""" subproc = self.stub_subprocess.AddCommand() - hit.Hit.SendFields(self.hit.GetFields()) + hit.Hit.send_fields(self.hit.get_fields()) subproc.AssertCallWas( ['curl', '--data', self.stub_urllib.urlencode(self.expected_fields), hit.Hit._GA_ENDPOINT], # pylint: disable=protected-access diff --git a/cli/lib/metrics/data_types/timing.py b/cli/lib/metrics/data_types/timing.py index 9d0624d..7af721a 100644 --- a/cli/lib/metrics/data_types/timing.py +++ b/cli/lib/metrics/data_types/timing.py @@ -52,9 +52,9 @@ class Timing(hit.Hit): self.time = time self.label = label - def GetFields(self): + def get_fields(self): """See base class.""" - params = super(Timing, self).GetFields() + params = super(Timing, self).get_fields() params.update({self.GA_KEY_USER_TIMING_CATEGORY: self.category, self.GA_KEY_USER_TIMING_VARIABLE: self.variable, self.GA_KEY_USER_TIMING_TIME: self.time}) @@ -63,7 +63,7 @@ class Timing(hit.Hit): return params @classmethod - def FromTimer(cls, timer, result=None): + def from_timer(cls, timer, result=None): """Converts a timer.Timer object to a Timing hit. The hit has the following structure: @@ -82,9 +82,9 @@ class Timing(hit.Hit): processing easier.) """ current_time = timer.Read() - return cls(metrics_util.MetaData(), + return cls(metrics_util.get_meta_data(), timer.name, int(round(current_time)), int(round(current_time * 1000)), timer.label, - metrics_util.CustomDimensions(result=result)) + metrics_util.get_custom_dimensions(result=result)) diff --git a/cli/lib/metrics/data_types/timing_unittest.py b/cli/lib/metrics/data_types/timing_unittest.py index 4dc3b5e..ab6e22f 100644 --- a/cli/lib/metrics/data_types/timing_unittest.py +++ b/cli/lib/metrics/data_types/timing_unittest.py @@ -59,7 +59,7 @@ class TimingTest(hit_unittest.HitTest): timer.time = self.stub_time def test_from_timer(self): - """Tests the timing.Timing.FromTimer(..) method.""" + """Tests the timing.Timing.from_timer(..) method.""" my_timer = timer.Timer('test_timer') my_timer.name = 'test_name' my_timer.label = 'test_label' @@ -67,7 +67,7 @@ class TimingTest(hit_unittest.HitTest): self.stub_time.current_time = 12.3 my_timer.Stop() - hit = timing.Timing.FromTimer(my_timer) + hit = timing.Timing.from_timer(my_timer) self.assertEqual(hit.category, 'test_name') self.assertEqual(hit.variable, 12) # Variable is in s. self.assertEqual(hit.time, 12300) # Time is in ms. diff --git a/cli/lib/metrics/hit_store.py b/cli/lib/metrics/hit_store.py index e65f251..e8e0e55 100644 --- a/cli/lib/metrics/hit_store.py +++ b/cli/lib/metrics/hit_store.py @@ -40,7 +40,7 @@ class Backup(object): self._table = table self._initialized = False - def _Setup(self): + def _setup(self): if self._initialized: return True self._conn = sqlite3.connect(self._path) @@ -50,7 +50,7 @@ class Backup(object): os.chmod(self._path, 0o600) self._initialized = True - def _AddFields(self, fields): + def _add_fields(self, fields): """Ensures that all necessary columns in the table are present. This lets us store all hit types in the same table, so that when @@ -61,7 +61,7 @@ class Backup(object): fields - a list of columns the table should have. """ if not self._initialized: - self._Setup() + self._setup() # Get existing columns and find which expected ones are missing. c = self._conn.cursor() c.execute('PRAGMA TABLE_INFO(%s)' % self._table) @@ -73,16 +73,16 @@ class Backup(object): c.execute('ALTER TABLE %s ADD COLUMN %s' % (self._table, field)) self._conn.commit() - def Save(self, fields): + def save(self, fields): """Saves a hit. Args: fields - a dictionary of { key, val } pairs for the hit. """ if not self._initialized: - self._Setup() + self._setup() # Ensure we have all the fields we need. - self._AddFields(fields.keys()) + self._add_fields(fields.keys()) # Save the hit c = self._conn.cursor() @@ -95,14 +95,14 @@ class Backup(object): values_list) self._conn.commit() - def RetrieveAll(self): + def retrieve_all(self): """Retrieves all saved hits and removes them from the DB. Returns: A list of dictionaries of { key, val } pairs. Each dictionary contains the data for a single hit.""" if not self._initialized: - self._Setup() + self._setup() # Make sure this happens atomically - we don't want another process # also retrieving hits we're about to delete. self._conn.isolation_level = 'EXCLUSIVE' diff --git a/cli/lib/metrics/hit_store_stub.py b/cli/lib/metrics/hit_store_stub.py index 6ffec0f..b4e60d0 100644 --- a/cli/lib/metrics/hit_store_stub.py +++ b/cli/lib/metrics/hit_store_stub.py @@ -30,8 +30,8 @@ class StubHitStore(object): def __init__(self, *args, **kwargs): pass - def Save(self, *args, **kwargs): + def save(self, *args, **kwargs): pass - def RetrieveAll(self): + def retrieve_all(self): return [] diff --git a/cli/lib/metrics/hit_store_unittest.py b/cli/lib/metrics/hit_store_unittest.py index 9ae8132..5ab9a4f 100644 --- a/cli/lib/metrics/hit_store_unittest.py +++ b/cli/lib/metrics/hit_store_unittest.py @@ -34,12 +34,12 @@ class HitStoreTest(unittest.TestCase): field1 = {'key1': 'value_a_1', 'key2': 'value_a_2', 'key3': 'value_a_3'} field2 = {'key1': 'value_b_1', 'key2': 'value_b_2', 'key3': 'value_b_3'} field3 = {'key1': 'value_c_1', 'key2': 'value_c_2', 'key3': 'value_c_3'} - self.hit_store.Save(field1) - self.hit_store.Save(field2) - retrieved = self.hit_store.RetrieveAll() + self.hit_store.save(field1) + self.hit_store.save(field2) + retrieved = self.hit_store.retrieve_all() self.assertEqual(retrieved, [field1, field2]) # Verify that the hit store removed any entries already retrieved. - self.hit_store.Save(field3) - retrieved = self.hit_store.RetrieveAll() + self.hit_store.save(field3) + retrieved = self.hit_store.retrieve_all() self.assertEqual(retrieved, [field3]) diff --git a/cli/lib/metrics/metrics_util.py b/cli/lib/metrics/metrics_util.py index 1d79dc6..cb96a60 100644 --- a/cli/lib/metrics/metrics_util.py +++ b/cli/lib/metrics/metrics_util.py @@ -49,12 +49,12 @@ _BRILLO_CD_RESULT = 7 _BRILLO_PROTOCOL_VERSION = 1 -def _GetOSVersion(): +def _get_os_version(): """Gets the OS release and major revision""" return '.'.join(platform.release().split('.')[:2]) -def _GetCPUSpeed(): +def _get_cpu_speed(): """Gets the CPU speed of the first core.""" speed = 'unknown' try: @@ -67,7 +67,7 @@ def _GetCPUSpeed(): return speed -def _GetRAM(): +def _get_ram(): """Gets the amount of physical memory in the system in GB. This function rounds down to the nearest byte. @@ -84,7 +84,7 @@ def _GetRAM(): return ram -def MetaData(): +def get_meta_data(): return meta_data.MetaData(_BRILLO_PROTOCOL_VERSION, _BRILLO_APP_ID, _BRILLO_APP_NAME, @@ -92,13 +92,13 @@ def MetaData(): user_config.USER_CONFIG.uid or 0) -def CustomDimensions(result=None): +def get_custom_dimensions(result=None): cds = {} cds[_BRILLO_CD_OS] = platform.system() - cds[_BRILLO_CD_OS_VERSION] = _GetOSVersion() + cds[_BRILLO_CD_OS_VERSION] = _get_os_version() cds[_BRILLO_CD_CPU_CORES] = multiprocessing.cpu_count() - cds[_BRILLO_CD_CPU_SPEED] = _GetCPUSpeed() - cds[_BRILLO_CD_RAM] = _GetRAM() + cds[_BRILLO_CD_CPU_SPEED] = _get_cpu_speed() + cds[_BRILLO_CD_RAM] = _get_ram() cds[_BRILLO_CD_BDK] = util.GetBDKVersion() if result is not None: cds[_BRILLO_CD_RESULT] = result @@ -142,7 +142,7 @@ def send_hit(hit_obj): Returns: True if the Send succeeds, False otherwise. """ - return send_hit_fields(hit_obj.GetFields()) + return send_hit_fields(hit_obj.get_fields()) @_requires_metrics_init_and_opt_in @@ -154,10 +154,10 @@ def send_hit_fields(hit_fields): """ result = False try: - result = hit.Hit.SendFields(hit_fields) + result = hit.Hit.send_fields(hit_fields) finally: if not result: - hit_store.Backup().Save(hit_fields) + hit_store.Backup().save(hit_fields) return result @@ -187,7 +187,7 @@ def send_retries(): If they fail again, they will be re-saved for the *next* time SendRetries is called. """ - for hit_fields in hit_store.Backup().RetrieveAll(): + for hit_fields in hit_store.Backup().retrieve_all(): send_hit_fields(hit_fields) diff --git a/cli/lib/metrics/metrics_util_stub.py b/cli/lib/metrics/metrics_util_stub.py index 49c7fbe..fde8099 100644 --- a/cli/lib/metrics/metrics_util_stub.py +++ b/cli/lib/metrics/metrics_util_stub.py @@ -24,9 +24,9 @@ class StubMetricsUtil(object): self._meta_data = meta_data self._custom_dimensions = custom_dimensions - def MetaData(self): + def get_meta_data(self): return self._meta_data # pylint: disable=unused-argument - def CustomDimensions(self, result=None): + def get_custom_dimensions(self, result=None): return self._custom_dimensions |