1 # -*- coding: utf-8 -*-
5 This module supplies vfs functionality.
16 ######################################################################
17 ##### module variables
21 ######################################################################
23 # initialize vfs stuff
24 def init(tab
, filename
, vfstype
):
25 """initiliaze vfs stuff"""
27 tempdir
= files
.mkdtemp()
29 st
, msg
= utils
.ProcessFunc('Creating vfs', filename
,
30 utils
.do_uncompress_dir
, filename
,
31 tab
.path
, tempdir
, True).run()
34 messages
.error('Creating vfs', msg
)
36 return # temppdir deleted by previous call, so we just return
37 elif st
== -100: # stopped by user
39 files
.do_delete(tempdir
)
48 tab
.vbase
= os
.path
.join(vpath
, filename
) + '#vfs'
49 # refresh the other panel
54 def copy(tab_org
, tab_new
):
57 tempdir
= files
.mkdtemp()
59 dir_src
= tab_org
.base
60 for f
in glob(os
.path
.join(dir_src
, '*')):
61 f
= os
.path
.basename(f
)
63 files
.do_copy(os
.path
.join(dir_src
, f
), os
.path
.join(tempdir
, f
))
64 except (IOError, os
.error
), (errno
, strerror
):
66 messages
.error('Error regenerating vfs file',
67 '%s (%s)' % (strerror
, errno
))
69 tab_new
.base
= tempdir
70 tab_new
.vfs
= tab_org
.vfs
71 tab_new
.vbase
= tab_org
.vbase
74 # exit from vfs, clean all
76 """exit from vfs, clean all"""
79 rebuild
= app
.prefs
.options
['rebuild_vfs']
80 if app
.prefs
.confirmations
['ask_rebuild_vfs']:
81 ans
= messages
.confirm('Rebuild vfs file', 'Rebuild vfs file', rebuild
)
85 return pan_regenerate(tab
)
89 files
.do_delete(tab
.base
)
94 def regenerate_file(tab
):
95 """regenerate vfs file: compress new file"""
97 vfs_file
= tab
.vbase
.replace('#vfs', '')
99 tmpfile
= files
.mktemp()
100 c
= compress
.check_compressed_file(vfs_file
)
101 cmd
= c
.build_compressXXX_cmd('*', tmpfile
)
102 f
= os
.path
.basename(vfs_file
)
103 st
, buf
= utils
.ProcessFunc('Compressing Directory', '\'%s\'' % f
,
104 utils
.run_shell
, cmd
, tab
.base
).run()
107 messages
.error('Creating vfs', buf
)
110 files
.do_delete(tmpfile
)
114 elif st
== -100: # stopped by user
116 files
.do_delete(tmpfile
)
121 tmpfile
+= c
.exts
[0] # zip & rar always adds extension
124 files
.do_copy(tmpfile
, vfs_file
)
125 except (IOError, os
.error
), (errno
, strerror
):
126 files
.do_delete(tmpfile
)
127 return '%s (%s)' % (strerror
, errno
)
128 files
.do_delete(tmpfile
)
133 if tab
.base
== tab
.path
:
136 return tab
.vbase
+ tab
.path
.replace(tab
.base
, '')
139 # initialize panelize vfs stuff
140 def pan_init(tab
, fs
):
141 """initiliaze panelize vfs stuff"""
144 tempdir
= files
.mkdtemp()
147 f_orig
= os
.path
.join(tab
.path
, f
)
148 f_dest
= os
.path
.join(tempdir
, f
)
149 d
= os
.path
.join(tempdir
, os
.path
.dirname(f
))
152 except (IOError, os
.error
), (errno
, strerror
):
155 if os
.path
.isfile(f_orig
):
156 files
.do_copy(f_orig
, f_dest
)
157 elif os
.path
.isdir(f_orig
):
159 except (IOError, os
.error
), (errno
, strerror
):
160 messages
.error('Can\'t create vfs', '%s (%s)' % (strerror
, errno
))
166 tab
.vbase
= vpath
+ '#vfs'
170 def pan_copy(tab_org
, tab_new
):
173 tempdir
= files
.mkdtemp()
175 dir_src
= tab_org
.base
176 for f
in glob(os
.path
.join(dir_src
, '*')):
177 f
= os
.path
.basename(f
)
179 files
.do_copy(os
.path
.join(dir_src
, f
), os
.path
.join(tempdir
, f
))
180 except (IOError, os
.error
), (errno
, strerror
):
182 messages
.error('Error regenerating vfs file',
183 '%s (%s)' % (strerror
, errno
))
185 tab_new
.base
= tempdir
186 tab_new
.vfs
= tab_org
.vfs
187 tab_new
.vbase
= tab_org
.vbase
190 # regenerate vfs pan file
191 def pan_regenerate(tab
):
192 """regenerate vfs pan file: copy files"""
195 dir_dest
= tab
.vbase
.replace('#vfs', '')
196 # check if can copy files
197 i
, oe
= os
.popen4('touch ' + dir_dest
, 'r')
199 i
.close(), oe
.close()
201 return ''.join(out
.split(':')[1:])[1:]
203 for f
in glob(os
.path
.join(dir_src
, '*')):
204 f
= os
.path
.basename(f
)
206 files
.do_copy(os
.path
.join(dir_src
, f
), os
.path
.join(dir_dest
, f
))
207 except (IOError, os
.error
), (errno
, strerror
):
209 messages
.error('Error regenerating vfs file',
210 '%s (%s)' % (strerror
, errno
))
213 ######################################################################