Skip to content

Make gpxmerge default output (print, I guess?) to stdout vs. file? #1

Description

@bdklahn

Thanks for making such a handy library!

Using your package, I was able to create a monthly summary of my daughter's Strava bulk download for her Physical Education (PE) class monthly logs, with your code and a bash script. I do this by running gpxinfo on a gpxmerge file of all the monthly files.

This is fine, but it nagged me a little thinking about that intermediate file on disk. So I decided to put it in memory, by making it a named pipe (mkfifo and mktemp -u).

It got me thinking that it seems like the following might be more conventional.

  • no option -> stdout
  • '--output' -> output to merge.gpx
  • '--output some_file.gpx ' -> output to some_file.gpx

It looks like it might not be too hard, utilizing the argparser info with some addition/modification near . . .

with open(out_file, "w") as f:
f.write(base_gpx.to_xml())

Then, I ought to be able to run something like gpxinfo <(gpxmerge . . .).
I suppose another step might then be to have gpxinfo accept stdin.

I suppose I could put together come code, and a pull request. :-)

I remember now . . . it's a little tricky with argparse to make an optional argument act both like a flag and like a container to store a value. But it can be done with 'default=argparse.SUPPRESS' (don't even add that attribute to the namespace if the flag is missing from the CL) and nargs = '?'. Then branch to stdout (print) if hasattr(args, 'output') returns False. If args.output == None ('if args.output:' should be enough), then set filename = 'merged.gpx'. Otherwise take the filename string entered after the '--output' (args.output).

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions