Skip to content

Commit

Permalink
Deprecate/http download (#395)
Browse files Browse the repository at this point in the history
* deprecate and remove http option

Signed-off-by: Charayaphan Nakorn Boon Han <[email protected]>

* Add helpful warning

Signed-off-by: Charayaphan Nakorn Boon Han <[email protected]>

* use argparse deprecation method

Signed-off-by: Charayaphan Nakorn Boon Han <[email protected]>

* use function level variables

Signed-off-by: Charayaphan Nakorn Boon Han <[email protected]>
  • Loading branch information
cnboonhan authored Oct 7, 2021
1 parent b221f28 commit 52cc0a6
Showing 1 changed file with 21 additions and 33 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import os
import yaml


__all__ = [
"download_models"
]
Expand All @@ -22,6 +23,14 @@

g = Generator()


class HTTPDownloadDeprecated(argparse.Action):
def __call__(self, parser, namespace, values, option_string=None):
logger.warn('DEPRECATED: The Options -f and -m is no longer in use. \
Please remove these.')
setattr(namespace, self.dest, values)


# Init overall parser
parser = argparse.ArgumentParser(
prog="building_map_model_downloader",
Expand All @@ -33,18 +42,17 @@
help="Input building.yaml file to process")
parser.add_argument("-m", "--model-path", type=str,
default="~/.gazebo/models/",
action=HTTPDownloadDeprecated,
help="Path to check models from and download models to. \
Redundant if using ignition fuel tools flag")
parser.add_argument("-c", "--cache", type=str,
default="~/.pit_crew/model_cache.json",
help="Path to pit_crew model cache")
parser.add_argument("-i", "--include", type=str,
help="Search this directory first for models. "
"If -f flag is specified, then directory must "
"follow ignition gazebo directory structure.")
parser.add_argument("-f", "--fuel-tools", action='store_true',
parser.add_argument("-f", "--fuel-tools", action=HTTPDownloadDeprecated,
help="Use ignition fuel tools to download models instead "
"of http")
"of http", nargs=0)
parser.add_argument("-i", "--include", type=str,
help="Search this directory first for models.")
parser.add_argument("-e", "--export-path", type=str, default=None,
help="Export model downloaded using ignition fuel tools "
"to a folder with classic gazebo directory structure."
Expand Down Expand Up @@ -73,13 +81,14 @@ def get_crowdsim_models(input_filename):

def download_models(
input_yaml,
model_path=None,
cache=None,
include=None,
fuel_tools=False,
export_path=None):
"""Download models for a given input building yaml."""
# Construct model set

IGN_FUEL_MODEL_PATH = "~/.ignition/fuel/"

model_set = set()
stringent_dict = {} # Dict to tighten download scope

Expand All @@ -101,27 +110,12 @@ def download_models(
else:
model_set.add(model.model_name)

# If we are using ignition fuel tools to download the models
# and we do not need to parse them, it means the model directory follows
# the ignition gazebo directory structure
ign = fuel_tools
logging.info("\nUsing Ignition Fuel directory struture : %s\n" % (ign))
# Ignition fuel tools can only download to this folder, so we set the
# model path to it
if fuel_tools:
if export_path is not None:
model_path = export_path
ign = False
else:
model_path = "~/.ignition/fuel/"

missing_models = pit_crew.get_missing_models(
model_set,
model_path=model_path,
model_path=IGN_FUEL_MODEL_PATH,
cache_file_path=cache,
lower=True,
priority_dir=include,
ign=ign
)

logger.info("\n== REQUESTED MODEL REPORT ==")
Expand Down Expand Up @@ -151,13 +145,9 @@ def download_models(
logger.info("Downloading model %s / %s : %s" %
(key + 1, len(missing_downloadables), model_name))

if fuel_tools:
pit_crew.download_model_fuel_tools(
model_name, author_name,
sync_names=True, export_path=export_path)
else:
pit_crew.download_model(model_name, author_name, sync_names=True,
download_path=model_path, ign=ign)
pit_crew.download_model_fuel_tools(
model_name, author_name,
sync_names=True, export_path=export_path)

if missing_models.get('missing', []):
logger.warning("\nMissing models (not in local or Fuel):")
Expand All @@ -168,10 +158,8 @@ def main():
args = parser.parse_args()
download_models(
args.INPUT_YAML,
args.model_path,
args.cache,
args.include,
args.fuel_tools,
args.export_path)


Expand Down

0 comments on commit 52cc0a6

Please sign in to comment.