66import logging
77from fs .constants import max_sectors , sector_size
88import time
9- import datetime
9+ from datetime import datetime
10+ from fs .core_types import File
1011
1112# was originally named fuse.py until i realized it conflicted with fusepy
1213
@@ -35,7 +36,10 @@ def recurse_path(spath, node):
3536 return None
3637
3738def date2utc (dt ):
38- return (dt - datetime .datetime (1970 , 1 , 1 )).total_seconds ()
39+ if dt is None :
40+ #logging.error("dt is None!")
41+ return time .time ()
42+ return (dt - datetime (1970 , 1 , 1 )).total_seconds ()
3943
4044
4145# TODO make this more fitting....
@@ -65,16 +69,15 @@ def _file_view_repr(node):
6569 )"""
6670 return node .name
6771
68- class PartView (Operations ):
69- def __init__ (self , part ):
70- self .part = part
72+ class AbstractView (Operations ):
73+ def __init__ (self ):
7174 self .fd = 0
7275 self .files = {}
73-
76+
77+ def get_part_from_path (self , path ):
78+ raise NotImplementedError
7479 def get_file_from_path (self , path ):
75- spath = split_all_path (path )
76- # todo include lost files as well
77- return recurse_path (spath , self .part .root )
80+ raise NotImplementedError
7881
7982 def readdir (self , path , offset ):
8083 file = self .get_file_from_path (path )
@@ -111,6 +114,8 @@ def getattr(self, path, fh=None):
111114 attrs ["st_blocks" ] = (attrs ["st_size" ] + (attrs ["st_blksize" ] - 1 )) // attrs ["st_blksize" ]
112115
113116 mac = file .get_mac ()
117+ #print(path)
118+ #print(mac)
114119 if mac is not None :
115120 attrs ["st_mtime" ] = date2utc (mac [0 ])
116121 attrs ["st_atime" ] = date2utc (mac [1 ])
@@ -119,6 +124,7 @@ def getattr(self, path, fh=None):
119124 attrs ["st_mtime" ] = time .time ()
120125 attrs ["st_atime" ] = time .time ()
121126 attrs ["st_ctime" ] = time .time ()
127+ #logging.error("No Time!")
122128
123129 return attrs
124130
@@ -128,9 +134,10 @@ def open(self, path, flags):
128134 file = self .get_file_from_path (path )
129135 if file is None :
130136 raise FuseOSError (ENOENT )
137+ part = self .get_part_from_path (path )
131138
132139 try :
133- content = file .get_content (self . part )
140+ content = file .get_content (part )
134141 except NotImplementedError :
135142 logging .error (u'Restore of #%s is not supported' , file .index )
136143 raise FuseOSError (EIO )
@@ -155,7 +162,7 @@ def open(self, path, flags):
155162 raise FuseOSError(EIO)"""
156163
157164 binout = bytes (binarray )
158- print (type (binout ))
165+ # print(type(binout))
159166
160167 self .fd += 1
161168 self .files [self .fd ] = (file , binout )
@@ -170,3 +177,53 @@ def read(self, path, size, offset, fh):
170177 if content is None :
171178 raise FuseOSError (EIO )
172179 return content [offset :offset + size ]
180+
181+ class PartView (AbstractView ):
182+ def __init__ (self , part , root ):
183+ AbstractView .__init__ (self )
184+ self .part = part
185+ self .root = root
186+
187+ def get_part_from_path (self , path ):
188+ return self .part
189+ def get_file_from_path (self , path ):
190+ spath = split_all_path (path )
191+ return recurse_path (spath , self .root )
192+
193+
194+ class MultiPartView (AbstractView ):
195+ def __init__ (self , parts , shorthands , rebuilt ):
196+ AbstractView .__init__ (self )
197+ self .partdict = {}
198+ self .root = File (0 , "ROOT" , 0 , True )
199+ #self.root.set_mac(datetime.now(), datetime.now(), datetime.now())
200+ self .build_tree (parts , shorthands , rebuilt )
201+
202+ def build_tree (self , parts , shorthands , rebuilt ):
203+ for i in xrange (len (shorthands )):
204+ i , par = shorthands [i ]
205+ part = parts [par ]
206+ if par not in rebuilt :
207+ print 'Rebuilding partition...'
208+ part .rebuild ()
209+ rebuilt .add (par )
210+ print 'Done'
211+ partname = 'Partition ' + str (i )
212+ file = File (0 , partname , 0 , True )
213+ #file.set_mac(datetime.now(), datetime.now(), datetime.now())
214+
215+ file .add_child (part .root )
216+ file .add_child (part .lost )
217+ self .root .add_child (file )
218+
219+ self .partdict [partname ] = part
220+
221+
222+ def get_part_from_path (self , path ):
223+ spath = split_all_path (path )
224+ return self .partdict [spath [1 ]]
225+
226+ def get_file_from_path (self , path ):
227+ spath = split_all_path (path )
228+ # todo include lost files as well?
229+ return recurse_path (spath , self .root )
0 commit comments