[generator] Fixed countries.txt generation.

This commit is contained in:
Maksim Andrianov 2021-01-01 23:13:37 +03:00 committed by Arsentiy Milchakov
parent 1825dc3c18
commit 3f66ec64a9
3 changed files with 24 additions and 18 deletions

View file

@ -112,7 +112,9 @@ class StagePreprocess(Stage):
D(settings.FOOD_URL, PathProvider.food_paths, "p"),
D(settings.FOOD_TRANSLATIONS_URL, PathProvider.food_translations_path, "p"),
)
@test_stage(Test(st.make_test_booking_data(max_days=7), lambda e, _: e.production, True))
@test_stage(
Test(st.make_test_booking_data(max_days=7), lambda e, _: e.production, True)
)
class StageFeatures(Stage):
def apply(self, env: Env):
extra = {}
@ -179,8 +181,13 @@ class StageMwm(Stage):
@staticmethod
def make_mwm(country: AnyStr, env: Env):
world_stages = {
WORLD_NAME: [StageIndex, StageCitiesIdsWorld, StagePrepareRoutingWorld, StageRoutingWorld,
StageMwmStatistics],
WORLD_NAME: [
StageIndex,
StageCitiesIdsWorld,
StagePrepareRoutingWorld,
StageRoutingWorld,
StageMwmStatistics,
],
WORLD_COASTS_NAME: [StageIndex, StageMwmStatistics],
}
@ -302,12 +309,11 @@ class StageRoutingTransit(Stage):
class StageMwmDiffs(Stage):
def apply(self, env: Env, country, logger, **kwargs):
data_dir = diffs.DataDir(
mwm_name=env.build_name, new_version_dir=env.build_path,
old_version_root_dir=settings.DATA_ARCHIVE_DIR
)
diffs.mwm_diff_calculation(
data_dir, logger, depth=settings.DIFF_VERSION_DEPTH
mwm_name=env.build_name,
new_version_dir=env.build_path,
old_version_root_dir=settings.DATA_ARCHIVE_DIR,
)
diffs.mwm_diff_calculation(data_dir, logger, depth=settings.DIFF_VERSION_DEPTH)
@country_stage
@ -323,7 +329,8 @@ class StageMwmStatistics(Stage):
settings.PROMO_CATALOG_COUNTRIES_URL,
PathProvider.promo_catalog_countries_path,
"p",
)
),
D(settings.PROMO_CATALOG_CITIES_URL, PathProvider.promo_catalog_cities_path, "p"),
)
class StageCountriesTxt(Stage):
def apply(self, env: Env):
@ -336,9 +343,8 @@ class StageCountriesTxt(Stage):
env.paths.mwm_version,
)
if env.production:
countries_json = json.loads(countries)
inject_promo_ids(
countries_json,
countries,
env.paths.promo_catalog_cities_path,
env.paths.promo_catalog_countries_path,
env.paths.mwm_path,
@ -346,8 +352,8 @@ class StageCountriesTxt(Stage):
env.paths.mwm_path,
)
with open(env.paths.counties_txt_path, "w") as f:
json.dump(countries_json, f, ensure_ascii=True, indent=1)
with open(env.paths.counties_txt_path, "w") as f:
json.dump(countries, f, ensure_ascii=True, indent=1)
@outer_stage

View file

@ -90,7 +90,7 @@ The post_generation commands are:
help="Output countries.txt file (default is stdout)",
)
args = parser.parse_args(sys.argv[2:])
countries_json = hierarchy_to_countries_(
countries = hierarchy_to_countries_(
args.old,
args.osm,
args.countries_synonyms,
@ -100,9 +100,9 @@ The post_generation commands are:
)
if args.output:
with open(args.output, "w") as f:
f.write(countries_json)
json.dump(countries, f, ensure_ascii=True, indent=1)
else:
print(countries_json)
print(json.dumps(countries, ensure_ascii=True, indent=1))
@staticmethod
def inject_promo_ids():
@ -152,7 +152,7 @@ The post_generation commands are:
)
with open(args.output, "w") as f:
json.dump(countries, f, indent=1)
json.dump(countries, f, ensure_ascii=True, indent=1)
PostGeneration()

View file

@ -185,4 +185,4 @@ def hierarchy_to_countries(
stack[-1]["g"].append(g)
collapse_single(stack[-1])
return json.dumps(stack[-1], ensure_ascii=True, indent=1)
return stack[-1]