[Zope-CVS] CVS: Products/ExternalEditor - CHANGES.txt:1.9 zopeedit.py:1.10
Casey Duncan
casey@zope.com
Mon, 10 Jun 2002 14:21:31 -0400
Update of /cvs-repository/Products/ExternalEditor
In directory cvs.zope.org:/tmp/cvs-serv19509
Modified Files:
CHANGES.txt zopeedit.py
Log Message:
Improved temp file naming code
Added corrected config pathing for Windows
Replaced stat with getmtime
=== Products/ExternalEditor/CHANGES.txt 1.8 => 1.9 ===
- Now works on Windows (applause) using Pythonwin. Much overall
- refactoring to abstract process control.
+ refactoring to abstract process control. Thanks to Oliver Deckmyn and
+ Gabriel Genellina for testing, patches and suggestions.
- Added "temp_dir" configuration option for specifying a different
- temp file directory then the OS default.
+ temp file directory then the OS default. Also further improved
+ temp file name generation.
- Added support for domain specific configuration options.
=== Products/ExternalEditor/zopeedit.py 1.9 => 1.10 ===
__version__ = '0.3'
-import sys, os, stat
+import sys, os
+from os import path
+from tempfile import mktemp
from ConfigParser import ConfigParser
from httplib import HTTPConnection, HTTPSConnection
from urlparse import urlparse
+import urllib
win32 = sys.platform == 'win32'
@@ -87,7 +90,11 @@
def __init__(self, input_file):
try:
# Read the configuration file
- config_path = os.path.expanduser('~/.zope-external-edit')
+ if win32:
+ config_path = path.expanduser('~\ZopeExternalEdit.ini')
+ else:
+ config_path = path.expanduser('~/.zope-external-edit')
+
self.config = Configuration(config_path)
# Open the input file and read the metadata headers
@@ -114,20 +121,23 @@
self.host)
# Write the body of the input file to a separate file
- content_file = (self.host + self.path)\
- .replace('/', ',').replace(':',',')
+ content_file = urllib.unquote('-%s%s' % (self.host, self.path))\
+ .replace('/', ',').replace(':',',').replace(' ','_')
+ ext = self.options.get('extension')
+
+ if ext and not content_file.endswith(ext):
+ content_file = content_file + ext
if self.options.has_key('temp_dir'):
- temp = os.tempnam(self.options['temp_dir'])
- elif win32:
- temp = os.tempnam()
+ while 1:
+ temp = path.expanduser(self.options['temp_dir'])
+ temp = os.tempnam(temp)
+ content_file = '%s%s' % (temp, content_file)
+ if not path.exists(content_file):
+ break
else:
- temp = os.tmpnam()
+ content_file = mktemp(content_file)
- content_file = '%s-%s' % (temp, content_file)
- ext = self.options.get('extension')
- if ext and not content_file.endswith(ext):
- content_file = content_file + ext
body_f = open(content_file, 'wb')
body_f.write(in_f.read())
self.content_file = content_file
@@ -175,7 +185,7 @@
save_interval = float(self.options.get('save_interval'))
use_locks = int(self.options.get('use_locks'))
launch_success = 0
- last_fstat = os.stat(self.content_file)
+ last_mtime = path.getmtime(self.content_file)
command = '%s %s' % (self.getEditorCommand(), self.content_file)
editor = EditorProcess(command)
@@ -184,14 +194,13 @@
while 1:
editor.wait(save_interval or 2)
- fstat = os.stat(self.content_file)
+ mtime = path.getmtime(self.content_file)
- if (save_interval or not editor.isAlive()) \
- and fstat[stat.ST_MTIME] != last_fstat[stat.ST_MTIME]:
+ if (save_interval or not editor.isAlive()) and mtime != last_mtime:
# File was modified
launch_success = 1 # handle very short editing sessions
self.saved = self.putChanges()
- last_fstat = fstat
+ last_mtime = mtime
if editor.isAlive():
launch_success = 1