Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cat-log - open job logs in editor #2260

Merged
merged 10 commits into from
May 12, 2017
Merged

Conversation

challurip
Copy link
Contributor

@challurip challurip commented May 1, 2017

cylc cat-log - allow opening job logs in users' editor ( temporary read only copy ); same via gcylc.

[not ready for review yet - coming soon]

@oliver-sanders
Copy link
Member

This will be a really useful feature! Just taking a quick glance through before review:

Something which would make it more convenient is if the editor command is run in the background in the case that the --geditor option is set. That way users could continue to work in the terminal whilst going through the log file.
Popen runs commands in the background by default its the proc.communicate and proc.wait methods which cause the process to wait until the command returns.

PS: There is a typo in bin/cylc-cat-log at line 302.

@hjoliver hjoliver changed the title Cat log open job logs in editor Cat-log - open job logs in editor May 4, 2017
@hjoliver hjoliver self-requested a review May 4, 2017 20:39
Copy link
Member

@hjoliver hjoliver left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, a couple of typos (made in recent commits, as I know it was working earlier!)

bin/cylc-cat-log Outdated

viewfile = NamedTemporaryFile(
suffix='.' + os.path.basename(filename),
prefix=suite + '.', dir=cylc_tmpdiir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo (diir) - spotted by @oliver-sanders

bin/cylc-cat-log Outdated

for line in lines:
viewfile.write(line + '\n')
viewfile.seek(0, 0)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation error - seek after all lines written, not after each.

bin/cylc-cat-log Outdated
'WARNING: YOU HAVE EDITED A TEMPORARY READ_ONLY COPY OF: ')
print >> sys.stderr, filename
else:
print >> sys.stderr, 'NO CHANGES MADE TO: %s' % viewfile.name
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We don't need this line IMO.

@hjoliver
Copy link
Member

hjoliver commented May 4, 2017

@oliver-sanders -

Something which would make it more convenient is if the editor command is run in the background in the case that the --geditor option is set.

The reason we block on the editor command is to check and warn if the user edited and force-saved the file, which suggests they thought they were editing the original file rather than a temporary read-only copy. (This is more important in cylc view --geditor which views the suite.rc file, but I think it's probably worth doing here too). I think the right way to do what you want is:

cylc cat-log --geditor my-suite my-task.2010 &

(most GUI editors - except for gvim default behaviour - don't automatically background either btw - i.e. you need to use & on the command line).

@challurip
Copy link
Contributor Author

Made changes as suggested.

bin/cylc-cat-log Outdated

viewfile = NamedTemporaryFile(
suffix='.' + os.path.basename(filename),
prefix=suite + '.', dir=cylc_tmpdir
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more problem found while testing: prefix=suite doesn't work for suite names containing / corresponding to the directory path under cylc-run/ - this makes the viewfile path refer to a non-existent directory. Can you change to this:
prefix=suite.replace('/','_') + '.' - and also do the same for the original code in cylc view.

@hjoliver hjoliver modified the milestones: next release, soon May 5, 2017
Copy link
Member

@oliver-sanders oliver-sanders left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

most GUI editors - except for gvim default behaviour - don't automatically background either btw

Good point, I'm too used to gvim.

Looks good to me, only one comment:

bin/cylc-cat-log Outdated
@@ -296,6 +335,10 @@ def main():
cmd_tmpl = str(GLOBAL_CFG.get_host_item(
"local tail command template"))
commands.append(shlex.split(cmd_tmpl % {"filename": filename}))
elif options.geditor or options.editor:
command_list = editor.split()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be safer to do this with shlex.split.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@challurip - if you can make this change and push it up today, I'll merge this for the new release (tonight, if the anesthetic has worn off...)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants