зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1620140 - Convert gen_event_data.py to py3; r=firefox-build-system-reviewers,rstewart
Differential Revision: https://phabricator.services.mozilla.com/D65462 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
891abab72e
Коммит
76e55932f5
|
@ -166,7 +166,7 @@ def generate_JSON_definitions(output, *filenames):
|
|||
'products': event.products,
|
||||
})
|
||||
|
||||
json.dump(event_definitions, output)
|
||||
json.dump(event_definitions, output, sort_keys=True)
|
||||
|
||||
|
||||
def main(output, *filenames):
|
||||
|
|
|
@ -7,9 +7,9 @@ import re
|
|||
import yaml
|
||||
import itertools
|
||||
import string
|
||||
import shared_telemetry_utils as utils
|
||||
from . import shared_telemetry_utils as utils
|
||||
|
||||
from shared_telemetry_utils import ParserError
|
||||
from .shared_telemetry_utils import ParserError
|
||||
atexit.register(ParserError.exit_func)
|
||||
|
||||
MAX_CATEGORY_NAME_LENGTH = 30
|
||||
|
@ -22,7 +22,7 @@ IDENTIFIER_PATTERN = r'^[a-zA-Z][a-zA-Z0-9_.]*[a-zA-Z0-9]$'
|
|||
|
||||
|
||||
def nice_type_name(t):
|
||||
if issubclass(t, basestring):
|
||||
if issubclass(t, str):
|
||||
return "string"
|
||||
return t.__name__
|
||||
|
||||
|
@ -97,14 +97,14 @@ class DictTypeChecker:
|
|||
if len(value.keys()) < 1:
|
||||
ParserError("%s: Failed check for %s - dict should not be empty." %
|
||||
(identifier, key)).handle_now()
|
||||
for x in value.iterkeys():
|
||||
for x in value.keys():
|
||||
if not isinstance(x, self.keys_instance_type):
|
||||
ParserError("%s: Failed dict type check for %s - expected key type %s, got "
|
||||
"%s." %
|
||||
(identifier, key,
|
||||
nice_type_name(self.keys_instance_type),
|
||||
nice_type_name(type(x)))).handle_later()
|
||||
for k, v in value.iteritems():
|
||||
for k, v in value.items():
|
||||
if not isinstance(v, self.values_instance_type):
|
||||
ParserError("%s: Failed dict type check for %s - "
|
||||
"expected value type %s for key %s, got %s." %
|
||||
|
@ -116,19 +116,19 @@ class DictTypeChecker:
|
|||
def type_check_event_fields(identifier, name, definition):
|
||||
"""Perform a type/schema check on the event definition."""
|
||||
REQUIRED_FIELDS = {
|
||||
'objects': ListTypeChecker(basestring),
|
||||
'objects': ListTypeChecker(str),
|
||||
'bug_numbers': ListTypeChecker(int),
|
||||
'notification_emails': ListTypeChecker(basestring),
|
||||
'record_in_processes': ListTypeChecker(basestring),
|
||||
'description': AtomicTypeChecker(basestring),
|
||||
'products': ListTypeChecker(basestring),
|
||||
'notification_emails': ListTypeChecker(str),
|
||||
'record_in_processes': ListTypeChecker(str),
|
||||
'description': AtomicTypeChecker(str),
|
||||
'products': ListTypeChecker(str),
|
||||
}
|
||||
OPTIONAL_FIELDS = {
|
||||
'methods': ListTypeChecker(basestring),
|
||||
'release_channel_collection': AtomicTypeChecker(basestring),
|
||||
'expiry_version': AtomicTypeChecker(basestring),
|
||||
'extra_keys': DictTypeChecker(basestring, basestring),
|
||||
'operating_systems': ListTypeChecker(basestring),
|
||||
'methods': ListTypeChecker(str),
|
||||
'release_channel_collection': AtomicTypeChecker(str),
|
||||
'expiry_version': AtomicTypeChecker(str),
|
||||
'extra_keys': DictTypeChecker(str, str),
|
||||
'operating_systems': ListTypeChecker(str),
|
||||
}
|
||||
ALL_FIELDS = REQUIRED_FIELDS.copy()
|
||||
ALL_FIELDS.update(OPTIONAL_FIELDS)
|
||||
|
@ -145,7 +145,7 @@ def type_check_event_fields(identifier, name, definition):
|
|||
ParserError(identifier + ': Unknown fields: ' + ', '.join(unknown_fields)).handle_later()
|
||||
|
||||
# Type-check fields.
|
||||
for k, v in definition.iteritems():
|
||||
for k, v in definition.items():
|
||||
ALL_FIELDS[k].check(identifier, k, v)
|
||||
|
||||
|
||||
|
@ -222,7 +222,7 @@ class EventData:
|
|||
if len(extra_keys.keys()) > MAX_EXTRA_KEYS_COUNT:
|
||||
ParserError("%s: Number of extra_keys exceeds limit %d." %
|
||||
(self.identifier, MAX_EXTRA_KEYS_COUNT)).handle_later()
|
||||
for key in extra_keys.iterkeys():
|
||||
for key in extra_keys.keys():
|
||||
string_check(self.identifier, field='extra_keys', value=key,
|
||||
min_length=1, max_length=MAX_EXTRA_KEY_NAME_LENGTH,
|
||||
regex=IDENTIFIER_PATTERN)
|
||||
|
@ -337,7 +337,7 @@ class EventData:
|
|||
|
||||
@property
|
||||
def extra_keys(self):
|
||||
return self._definition.get('extra_keys', {}).keys()
|
||||
return list(sorted(self._definition.get('extra_keys', {}).keys()))
|
||||
|
||||
|
||||
def load_events(filename, strict_type_checks):
|
||||
|
@ -368,7 +368,7 @@ def load_events(filename, strict_type_checks):
|
|||
# <event definition>
|
||||
# ...
|
||||
# ...
|
||||
for category_name, category in events.iteritems():
|
||||
for category_name, category in sorted(events.items()):
|
||||
string_check("top level structure", field='category', value=category_name,
|
||||
min_length=1, max_length=MAX_CATEGORY_NAME_LENGTH,
|
||||
regex=IDENTIFIER_PATTERN)
|
||||
|
@ -378,7 +378,7 @@ def load_events(filename, strict_type_checks):
|
|||
ParserError('Category ' + category_name + ' must contain at least one entry.'
|
||||
).handle_now()
|
||||
|
||||
for name, entry in category.iteritems():
|
||||
for name, entry in sorted(category.items()):
|
||||
string_check(category_name, field='event name', value=name,
|
||||
min_length=1, max_length=MAX_METHOD_NAME_LENGTH,
|
||||
regex=IDENTIFIER_PATTERN)
|
||||
|
|
|
@ -189,7 +189,6 @@ if CONFIG['MOZ_TELEMETRY_EXTRA_EVENT_FILES']:
|
|||
event_files.extend(CONFIG['MOZ_TELEMETRY_EXTRA_EVENT_FILES'])
|
||||
|
||||
GeneratedFile('TelemetryEventData.h', script='build_scripts/gen_event_data.py',
|
||||
py2=True,
|
||||
inputs=event_files)
|
||||
|
||||
GeneratedFile('TelemetryEventEnums.h', script='build_scripts/gen_event_enum.py',
|
||||
|
@ -200,7 +199,6 @@ GeneratedFile('TelemetryEventEnums.h', script='build_scripts/gen_event_enum.py',
|
|||
# used in artifact or "build faster" builds.
|
||||
GeneratedFile('EventArtifactDefinitions.json',
|
||||
script='build_scripts/gen_event_data.py',
|
||||
py2=True,
|
||||
entry_point='generate_JSON_definitions', inputs=event_files)
|
||||
|
||||
# Move the events JSON file to the directory where the Firefox binary is.
|
||||
|
|
Загрузка…
Ссылка в новой задаче