Skip to content

gmt docs behavior on server installations #498

Closed

Description

@KristofKoch

Description of the desired feature

Have gmt docs behave differently on desktop and server installations.

  • on desktop installations everything is fine.
  • on server sessions there is no browser to open - therefore I'd like to suggest to display the URL to the online documentation and maybe a hint for the man page and a note that there is desktop environment detected.

Detailed …

Currently gmt docs tries to open the default browser. While this is nice on desktop installations it understandably fails on server installations.

$ gmt docs coast -J
sh: 1: xdg-open: not found
docs [ERROR]: Opening http://gmt.soest.hawaii.edu/doc/latest/coast.html#j in the default browser via xdg-open failed with error 32512
docs: No such file or directory

According to xdg-open man page: "xdg-open is for use inside a desktop session only."

As I normally SSH into a remote machine to work with GMT the current incarnation of gmt docs is almost useless to me. It fails in a way that is still usable but I guess this is accidental.

While there are man pages I prefer working with the online documentation (better layout, links, easier to read). Therefore I would still appreciate the URL to the online documentation. This allows to easily call the URL on the local machine (Cmd-click in iTerm on MacOS for example) while working on the remote machine.

My suggestion

$ gmt docs coast -J
You are working in a server environment. Try opening
http://gmt.soest.hawaii.edu/doc/latest/coast.html#j
in a web browser on your local machine. 

Your thoughts?

Activity

  1. joa-quim commented on Mar 12, 2019

    @joa-quim
    Member

    Hmmm, this bit of code at the end of docs.c should have done almost what you propose. I wonder why the system command have not triggered that error case.

    	sprintf (cmd, "%s %s", can_opener[k], URL);
    	if ((error = system (cmd))) {
    		GMT_Report (GMT->parent, GMT_MSG_NORMAL, "Opening %s in the default browser via %s failed with error %d\n", URL, can_opener[k], error);
    		perror ("docs");
    		Return (GMT_RUNTIME_ERROR);
    	}
    
  2. KristofKoch commented on Mar 12, 2019

    @KristofKoch
    ContributorAuthor

    @joa-quim as far as I can see it did trigger (third line in my output). But it seems GMT assumes xdg-open to be present and doesn't check for it. This throws the first error message (sh: 1: xdg-open: not found) in my understanding.

  3. joa-quim commented on Mar 12, 2019

    @joa-quim
    Member

    Sorry, you are right. It did trigger the error message. But to print what you propose we would have to know that it failed for that exact reason. That is, how could we know that You are working in a server environment.?

  4. KristofKoch commented on Mar 12, 2019

    @KristofKoch
    ContributorAuthor

    Maybe check if xdg-open is installed? As it is hosted by the freedesktop.org project as part of the xdg-utils I assume you only find it in desktop distributions.

    This can be done POSIX compliant with

    command -v xdg-open
    

    it will return nothing if not installed. Otherwise you will get the path back:

    kristof@h2813222:~$ command -v xdg-open
    kristof@h2813222:~$ command -v gmt
    /usr/local/bin/gmt
    kristof@h2813222:~$
    

    Checking for desktop environments is a different beast. Most GUIs rely on an X-Server so

    command -v Xorg
    

    might be your friend. However they might use Wayland or even more obscure solutions. So this is unreliable at best.

    As you rely on xdg-open for the function of gmt docs the safest bet might be just to check for xdg-open as described above and change my proposed wording to something less assertive and more informative as well:

    $ gmt docs coast -J
    We couldn't find the program "xdg-open" on which "docs" relies upon.
    This is normal if you are working in a server environment. Just open
    http://gmt.soest.hawaii.edu/doc/latest/coast.html#j
    in a web browser on your local machine. 
    
  5. uleysky commented on Mar 13, 2019

    @uleysky
    Contributor

    In the server environment, there may be a command links or lynx. Maybe make this command customizable? With default value xdg-open.

  6. KristofKoch commented on Mar 13, 2019

    @KristofKoch
    ContributorAuthor

    Good point, @uleysky

  7. PaulWessel commented on Mar 13, 2019

    @PaulWessel
    Contributor

    We can try to strengthen this. However, I do not think most GMT users are running GMT remotely on a server. In fact, most of them are sitting on a Windows or OS X computer, and we are not calling xdg-open anyway. If there is a system utility that can reveal you are running in a system where X11 cannot open then we could add such messages under an if/endif for UNIX.
    We could also look at the error code returned by system. E.g., https://stackoverflow.com/questions/5638321/why-child-process-returns-exit-status-32512-in-unix
    but most likely the causes will be (1) xdg-open not installed and distant second (2) cannot open X11 for display. Or am I wrong?

  8. uleysky commented on Mar 14, 2019

    @uleysky
    Contributor

    In case (1) system returns error code 127. This is return code of sh -c , if command can't be found. In case (2), the return code will be return code of xdg-open. xdg-open can return 3 (A required tool could not be found) or 4 (The action failed). On one of my systems xdg-open return 3, if X11 is not available. On another xdg-open run links in this case )

    I look at the gmt docs as a special version of the man command. Of course, you can always search for information on the Internet, but if you just need to remember something small, the man command is irreplaceable. The man command has two advantages: it is fast (it works right there in the terminal, there is no need to switch windows) and local (it does not depend on the Internet connection). So, I prefer to use the links as a browser for gmt doc, even if I work in a graphical environment.

  9. PaulWessel commented on Mar 14, 2019

    @PaulWessel
    Contributor

    At the very least we should probably list xdg-open as a prerequisite for Unix-like systems, similar to how ghostscript gs is a required executable for all.

  10. KristofKoch commented on Mar 14, 2019

    @KristofKoch
    ContributorAuthor

    @PaulWessel I think it isn't such a great idea to list xdg-open as a prerequisite. I run gmt exclusively on headless machines. No X11 or similar installed. So no point in having xdg-open available.

    My original point was that gmt docs fails on headless or remote machines. I do enjoy however the easy access to the web documentation it provides in form of the URL. Basically a special (nicer) form of the man pages as @uleysky said.

    Maybe the best idea is to not touch it at all and add a note to the documentation why there might be a problem with xdg-open?

  11. joa-quim commented on Mar 14, 2019

    @joa-quim
    Member

    We could add an option to only print the URLs (both the local one and www) and not trying to open it.
    Something like gmt docs <module-name> -?

  12. uleysky commented on Mar 14, 2019

    @uleysky
    Contributor

    A good option. Writing the own wrapper script is a simple task.

  13. KristofKoch commented on Mar 14, 2019

    @KristofKoch
    ContributorAuthor

    A great idea, @joa-quim. Very useful on these seemingly rare installations like mine.

  14. PaulWessel commented on Mar 14, 2019

    @PaulWessel
    Contributor

    How about instead simply catching the system error and say xdg-open could not open (to stderr) and then print the URL? I.e., instead of adding an option it may print

    docs: Could not execute xdg-open (missing|other reason)
    http://<theaddress/thefile.html

    The current error message is too harsh.

  15. joa-quim commented on Mar 14, 2019

    @joa-quim
    Member

    That was actually my first idea when this tread started (and not restricted to xdg-open only), but now @uleysky seems to want to capture the stdout to wrap it in a script.

  16. 3 remaining items

  17. PaulWessel commented on Mar 15, 2019

    @PaulWessel
    Contributor

    I have no strong views on this. If @uleysky does not want to have xdg-open handle the URL then there truly are only two ways:

    1. Add a module option such as what @joa-quim suggested above
    2. Add a GMT Default GMT_URL_OPENER that can be set to something else.

    I am not convinced of the hardship of xdg-open creating a new tab with the documentation. You read it and hit Command-W or similar to close the tab. Presumably the alternative viewer also need some sort of exit key to end?

  18. joa-quim commented on Mar 15, 2019

    @joa-quim
    Member

    I've created PR #510 that now would print (in my case it's not finding the local URL because GMT5_SHAREDIR is pointing to GMT5)

    docs plot
             Error running the "cmd /c start" program. This may indicate that you are working in a
             server environment. Try open this URL in a web browser on your local machine.
             http://gmt.soest.hawaii.edu/doc/latest/plot.html
    

    @uleysky Is this good enough for you or still prefer a program option?

  19. uleysky commented on Mar 15, 2019

    @uleysky
    Contributor

    @joa-quim, it does not allow you to select a browser if the xdg-open is installed. The option would be much more flexible.

  20. PaulWessel commented on Mar 17, 2019

    @PaulWessel
    Contributor

    Hi @uleysky, It would be helpful to understand exactly what you need (and why). If I understand you correctly, you wish gmt docs manpage to print the local (if installed) or remote URL to stdout and then you can use that with lynx or some other command-line browser. Is that correct (which browser is it)? If so, what is the practical difference between quitting that browser versus closing the page in the fuller browser that xdg-open will use? Don't both scenarios require a single keystroke? I ask because this would seem to be the workflow of a very small subset of users so we would need a very good reason, i.e., the solution would accomplish something that cannot be done otherwise. It sounds like we are no longer dealing with what to do if xdg-open fails; it is now about not wanting xdg-open to do its job.

  21. uleysky commented on Mar 18, 2019

    @uleysky
    Contributor

    In short, because it is Linux. The xdg-open gives an unpredictable result in the general case. Let me describe in more detail. I have a three different installations of Linux. First, my home computer with X and firefox in the system. Second, my computer at work with X, but firefox installed locally and not in path, so xdg-open can't find it. Third, worstation(s) without X and without xdg-open at all. Thus, the following situations arise

    1. Home computer. xdg-open creates new tab in Firefox. Good for long reads, but if you need a quick look at the option, the slowness is somewhat annoying.
    2. Home computer, ssh -X to work. Worst case, xdg-open try to launch winebrowser.
    3. Home computer, ssh to work. Good, links is running.
    4. ssh to workstation without xdg-open. Bad, nothing is running.
    5. Work computer, same as 2)
    6. Relatively rare situation, ssh -X from work to home. Same as 1), xdg-open creates new tab in local Firefox.

    So, depending on where and how I work, there are four situations, from good to bad: links is running, new tab in firefox, nothing happens, an absolutely unnecessary program is launched. With -? option I'll just write a wrapper script with exactly the same behavior in all cases, doing what I need.

  22. PaulWessel commented on Mar 18, 2019

    @PaulWessel
    Contributor

    OK, since docs does not really have options I don't mind adding one that just prints the URL to stdout. However, it won't be -? since that is gmt speak for print usage. Probably -Q for a "dry run".

  23. joa-quim commented on Mar 18, 2019

    @joa-quim
    Member

    The problem with that naming is that it would be interpret as a request to show option -Q of module XXX. That's why I picked the ? so that we could parse it as meaning "print the URL". If not -? we need to pick char that is not used as option in modules.

  24. PaulWessel commented on Mar 18, 2019

    @PaulWessel
    Contributor

    Right, which is why I brought up a new GMT Default setting instead. @uleysky can just as easily run

    export GMT_URL_OPENER=links gmt $*

    in a script called linksdoc and run that browser instead of some option like

    links gmt docs $@ -?

  25. PaulWessel commented on Mar 18, 2019

    @PaulWessel
    Contributor

    Or it would simply be an option to docs:

    gmt docs -Q psbasemap -L

    you would not put -Q after psbasemap.

  26. joa-quim commented on Mar 18, 2019

    @joa-quim
    Member

    Definitively prefer this. Gmtdefaults is too looong already.

  27. PaulWessel commented on Mar 18, 2019

    @PaulWessel
    Contributor

    OK, I will give this a test and report. But going for coffee first and you will be asleep by the time I get back.

  28. uleysky commented on Mar 18, 2019

    @uleysky
    Contributor

    Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions