Skip to content

Commit

Permalink
Refactor yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
cbm755 committed Feb 25, 2023
1 parent db2918c commit 803e802
Showing 1 changed file with 21 additions and 20 deletions.
41 changes: 21 additions & 20 deletions req2flatpak.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,16 +728,6 @@ def main():
parser = cli_parser()
options = parser.parse_args()

def _get_yaml_module_or_exit():
try:
# optional dependency, not imported at top
import yaml
except ImportError:
parser.error(
"Outputing YAML requires 'pyyaml' package: try 'pip install pyyaml'"
)
return yaml

# stream output to a file or to stdout
if hasattr(options.outfile, "write"):
output_stream = options.outfile
Expand All @@ -746,17 +736,29 @@ def _get_yaml_module_or_exit():
else:
output_stream = sys.stdout

if options.yaml:
try:
# optional dependency, not imported at top
import yaml
except ImportError:
parser.error(
"Outputing YAML requires 'pyyaml' package: try 'pip install pyyaml'"
)

# print platform info if requested, and exit
if options.platform_info and options.yaml:
yaml = _get_yaml_module_or_exit()
yaml.dump(
asdict(PlatformFactory.from_current_interpreter()), output_stream, indent=2
)
parser.exit()
if options.platform_info:
json.dump(
asdict(PlatformFactory.from_current_interpreter()), output_stream, indent=4
)
if options.yaml:
yaml.dump(
asdict(PlatformFactory.from_current_interpreter()),
output_stream,
indent=2,
)
else:
json.dump(
asdict(PlatformFactory.from_current_interpreter()),
output_stream,
indent=4,
)
parser.exit()

# print installed packages if requested, and exit
Expand Down Expand Up @@ -816,7 +818,6 @@ def _get_yaml_module_or_exit():
build_module = FlatpakGenerator.build_module(requirements, downloads)

if options.yaml:
yaml = _get_yaml_module_or_exit()
yaml.dump(build_module, output_stream, indent=2)
parser.exit()

Expand Down

0 comments on commit 803e802

Please sign in to comment.