Modify

Opened 15 years ago

Closed 15 years ago

#7037 closed defect (fixed)

The DiaVisView plugin does not work on Windows

Reported by: Glenn Ramsey Owned by: robert_martin
Priority: normal Component: DiaVisViewPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.11

Description

DiaVisView plugin does not work on Windows. It fails with the message:

32The process cannot access the file because it is being used by another process

This is appears to be because it uses the popen2.Popen4 class, which is not available on Windows.

The log says this:

2010-04-28 15:49:08,358 Trac[loader] ERROR: Skipping "DiaVisView.DiaVisView = DiaVisView.DiaVisView": (can't import "ImportError: cannot import name Popen4")
2010-04-28 15:49:31,187 Trac[diavisview] INFO: Getting file modification times.
2010-04-28 15:49:31,203 Trac[diavisview] INFO: Comparing dia and png file modification times : 1268358663.05, 1268358663.05
2010-04-28 15:49:31,203 Trac[diavisview] INFO: Running Dia : dia -l --filter=png --export=c:\trac\attachments\wiki\diatest\Diagram1.png c:\trac\attachments\wiki\diatest\Diagram1.dia
2010-04-28 15:49:31,203 Trac[diavisview] INFO: Dia failed with exception= 'module' object has no attribute 'Popen4'
2010-04-28 15:49:31,203 Trac[diavisview] INFO: Error unlinking uncompressed file for Dia:- c:\trac\attachments\wiki\diatest\decomp_Diagram1.dia
2010-04-28 15:49:31,217 Trac[formatter] ERROR: Macro DiaVisView(Diagram1.dia) failed: 
Traceback (most recent call last):
  File "C:\Python25\lib\site-packages\trac-0.11.5rc1-py2.5-win32.egg\trac\wiki\formatter.py", line 480, in _macro_formatter
    return macro.process(args, in_paragraph=True)
  File "C:\Python25\lib\site-packages\trac-0.11.5rc1-py2.5-win32.egg\trac\wiki\formatter.py", line 180, in process
    text = self.processor(text)
  File "C:\Python25\lib\site-packages\trac-0.11.5rc1-py2.5-win32.egg\trac\wiki\formatter.py", line 167, in _macro_processor
    text)
  File "build\bdist.win32\egg\DiaVisView\DiaVisView.py", line 177, in expand_macro
    os.unlink(decompFileName)
WindowsError: [Error 32] The process cannot access the file because it is being used by another process: 'c:\\trac\\attachments\\wiki\\diatest\\decomp_Diagram1.dia'

Attachments (0)

Change History (6)

comment:1 Changed 15 years ago by Martin

Could you please try the following patch? It uses the subprocess API instead of popen and works well on Debian GNU/Linux. I don't have a Windows machine to test.

--- DiaVisView.py.orig	2010-06-01 19:09:08.409518220 +0200
+++ DiaVisView.py	2010-06-01 19:35:28.011225063 +0200
@@ -11,8 +11,8 @@
 
 
 import os
-import popen2
 import re
+import subprocess
 import gzip
 import Image
 
@@ -158,16 +158,11 @@
                       raise Exception('Dia execution failed.')
                 finally:
                     decompFile.close
+                diacmd = ['dia', '-l', '--filter=png', '--export=%s' % png_path, dia_path]
                 if width:
-                  diacmd = 'dia -l --filter=png --size=%dx --export=%s %s' % (int(width), png_path, dia_path)
-                else:
-                  diacmd = 'dia -l --filter=png --export=%s %s' % (png_path, dia_path)
-                self.env.log.info('Running Dia : %s',diacmd)
-                f = popen2.Popen4(diacmd)
-                lines = []
-                while (f.poll() == -1):
-                    lines += f.fromchild.readlines()
-                    f.wait()
+                    diacmd.insert(1, '--size=%dx' % int(width))
+                self.env.log.info('Running Dia : %s', ' '.join(diacmd))
+                subprocess.call(diacmd)
                 self.env.log.info('Exiting Dia')
             except Exception, e:
                 self.env.log.info('Dia failed with exception= %s',e)

comment:2 Changed 15 years ago by Glenn Ramsey

Yes, that works. Thanks. Another issue is that the block of code above that which tries to decompress the file also doesn't work on Windows. One of the issues is that it uses os.link() which AFAIK is unix only. I have commented that block out in my version.

comment:3 in reply to:  2 ; Changed 15 years ago by Martin

Replying to glennr:

Another issue is that the block of code above that which tries to decompress the file also doesn't work on Windows.

I have no idea why the plugin has this decompression feature anyway. Dia does (de-) compression transparently anyway, so there is no need for this feature, IMHO.

One of the issues is that it uses os.link() which AFAIK is unix only. I have commented that block out in my version.

Like this?

--- DiaVisView.py.orig	2010-06-02 10:39:51.034011345 +0200
+++ DiaVisView.py	2010-06-02 10:44:30.746010956 +0200
@@ -13,7 +13,6 @@
 import os
 import popen2
 import re
-import gzip
 import Image
 
 
@@ -133,31 +132,6 @@
 
         if (dia_mtime > png_mtime) or (existing_width != width):
             try:
-                # The file maybe compressed.  The name has to be prepended to keep the extension.
-                (attachDir, attachFile) = os.path.split(dia_path)
-                decompFileName = os.path.join(attachDir, 'decomp_' + attachFile)
-                try:
-                    decompFile = open(decompFileName , 'w')
-                except Exception, e:
-                    self.env.log.info('Creating temp uncompressed file for Dia Failed = %s',e)
-                    raise Exception('Dia execution failed.')
-                try:
-                    for line in gzip.GzipFile(dia_path):
-                        decompFile.write(line)
-                except IOError, e:
-                    if e.message == 'Not a gzipped file':
-                        self.env.log.info('Not a gzipped file, so linking %s', dia_path)
-                        try:
-                            os.unlink(decompFileName)
-                            os.link(dia_path, decompFileName)
-                        except Exception, e:
-                            self.env.log.info('Error linking uncompressed file for Dia:- %s', dia_path)
-                            raise
-                    else:
-                      self.env.log.info('Error decompressing file for Dia = %s',e)
-                      raise Exception('Dia execution failed.')
-                finally:
-                    decompFile.close
                 if width:
                   diacmd = 'dia -l --filter=png --size=%dx --export=%s %s' % (int(width), png_path, dia_path)
                 else:
@@ -172,12 +146,6 @@
             except Exception, e:
                 self.env.log.info('Dia failed with exception= %s',e)
                 raise Exception('Dia execution failed.')
-            finally:
-                try:
-                    os.unlink(decompFileName)
-                except Exception, e:
-                    self.env.log.info('Error unlinking uncompressed file for Dia:- %s', decompFileName)
-                    raise
 
             (png_file_size, png_file_time) = os.stat(png_path)[6:8]
             # Based on attachment.py, insert

(Careful! Untested patch.)

comment:4 in reply to:  3 Changed 15 years ago by anonymous

Replying to debacle@debian.org:

(Careful! Untested patch.)

Yes, just like that.

comment:5 Changed 15 years ago by Martin

(In [8096]) Removed unnessary gzip code. Closes #7197. Refs #7037.

comment:6 Changed 15 years ago by Martin

Resolution: fixed
Status: newclosed

(In [8097]) Replaced popen API with subprocess.call(). Closes #7037.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain robert_martin.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.