2 from logging
import info
, debug
4 path_dirs
= os
.environ
.get('PATH', '/bin:/usr/bin').split(':')
6 def available_in_path(command
):
7 info("Checking for %s in $PATH", command
)
9 debug("Checking for %s/%s", x
, command
)
10 if os
.path
.isfile(os
.path
.join(x
, command
)):
15 fd
, tmp
= tempfile
.mkstemp(prefix
= '0publish-', suffix
= '.xml')
17 stream
= os
.fdopen(fd
, 'w')
20 editor
= os
.environ
.get('EDITOR', None)
22 info("$EDITOR not set. Trying fallbacks...")
23 for editor
in ['sensible-editor', 'nano', 'vi']: # ,'ed'] ;-)
24 if available_in_path(editor
):
27 raise Exception("No editor found. Try setting $EDITOR first.")
28 info("Editing tmp file with '%s %s'..." % (editor
, tmp
))
29 if os
.spawnlp(os
.P_WAIT
, editor
, editor
, tmp
):
30 raise Exception('Editing with $EDITOR ("%s") failed' % editor
)
31 new_data
= file(tmp
).read()