summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--mytasks.py64
-rwxr-xr-xraidguessfs.py15
2 files changed, 61 insertions, 18 deletions
diff --git a/mytasks.py b/mytasks.py
index 6c03262..9ec40b7 100644
--- a/mytasks.py
+++ b/mytasks.py
@@ -18,22 +18,32 @@
# You should have received a copy of the GNU General Public License
# along with RaidGuessFS. If not, see <http://www.gnu.org/licenses/>
-import logging
+import multiprocessing, logging
+import mydisks
+
+def do_find_files(d,state):
+ state['TODO'] = 'Not yet implemented'
+
+
+def do_find_bootsect(d,state):
+ state['TODO'] = 'Not yet implemented'
+
+
class MyTasks():
"""Auxiliary class, managing long or background tasks"""
TASK_NAMES = [ 'find_bootsect', 'find_files' ]
- def __init__(self, *args, **kwargs):
+ def __init__(self, mydisks):
self.tasks = []
+ self.d = mydisks
self.find_files_pathlist = []
-
- def get_task_start(self):
- return 'Write a task_name in this pseudo-file to start it\n'
-
- def get_task_kill(self):
- return 'Write a task_name in this pseudo-file to kill it\n'
+ m = multiprocessing.Manager()
+ self.find_bootsect_state = m.dict()
+ self.find_bootsect_process = None
+ self.find_files_state = m.dict()
+ self.find_files_process = None
def get_find_files_pathlist(self):
return self.find_files_pathlist
@@ -41,18 +51,44 @@ class MyTasks():
def get_find_files_pathlist_str(self):
return '\n'.join(self.find_files_pathlist)
- def set_task_start(self, task_name):
- raise Exception('Not yet implemented')
+ def task_start(self, task_name):
+ if task_name == 'find_files':
+ self.find_files_process = multiprocessing.Process(
+ target = do_find_files,
+ args = (self.d, self.find_files_state)
+ )
+ self.find_files_process.start()
+ elif task_name == 'find_bootsect':
+ self.find_bootsect_process = multiprocessing.Process(
+ target = do_find_bootsect,
+ args = (self.d, self.find_bootsect_state)
+ )
+ self.find_bootsect_process.start()
+ else:
+ raise ValueError('Valid task names are : %s'%','.join(MyTasks.TASK_NAMES))
- def set_task_kill(self, task_name):
- raise Exception('Not yet implemented')
+ def task_kill(self, task_name):
+ if task_name == 'find_bootsect':
+ if self.find_bootsect_process != None and self.find_bootsect_process.is_alive():
+ self.find_bootsect_process.terminate()
+ elif task_name == 'find_files':
+ if self.find_files_process != None and self.find_files_process.is_alive():
+ self.find_files_process.terminate()
+ else:
+ raise ValueError('Valid task names are : %s'%','.join(MyTasks.TASK_NAMES))
def set_find_files_pathlist(self, new_find_files_pathlist):
self.find_files_pathlist = new_find_files_pathlist
def read_find_bootsect(self):
- return 'This task is not started\n'
+ if self.find_bootsect_process == None:
+ return 'This task has never been started\n'
+ else:
+ return 'TODO\n%s\n'%self.find_bootsect_state
def read_find_files(self):
- return 'This task is not started\n'
+ if self.find_files_process == None:
+ return 'This task has never been started\n'
+ else:
+ return 'TODO\n%s\n'%self.find_files_state
diff --git a/raidguessfs.py b/raidguessfs.py
index ac56278..5aa8347 100755
--- a/raidguessfs.py
+++ b/raidguessfs.py
@@ -53,7 +53,7 @@ class RaidGuessFS(fuse.Fuse):
self.raid = myraid.MyRaid()
self.bmp = mybinview.MyBinView()
self.st = mystat.MyStat()
- self.tasks = mytasks.MyTasks()
+ self.tasks = mytasks.MyTasks(self.d)
self.bmp.refresh_bmp()
@@ -73,7 +73,7 @@ class RaidGuessFS(fuse.Fuse):
self.raid.get_raid_start, self.raid.get_raid_end, self.raid.get_raid_chunk_size,
self.raid.get_raid_disk_order_str, self.raid.get_raid_layout,
self.bmp.get_bmp_height, self.bmp.get_bmp_width, self.bmp.get_bmp_start_offset,
- self.tasks.get_task_start, self.tasks.get_task_kill, self.tasks.get_find_files_pathlist_str,
+ self.get_task_start, self.get_task_kill, self.tasks.get_find_files_pathlist_str,
]
self.settings_updaters = [
@@ -81,9 +81,10 @@ class RaidGuessFS(fuse.Fuse):
self.update_raid_start, self.update_raid_end, self.update_raid_chunk_size, self.update_raid_disk_order,
self.raid.set_raid_layout,
self.update_bmp_height, self.update_bmp_width, self.update_bmp_start_offset,
- self.tasks.set_task_start, self.tasks.set_task_kill, self.update_task_find_files_pathlist,
+ self.tasks.task_start, self.tasks.task_kill, self.update_task_find_files_pathlist,
]
+
self.dentries = {
'/' : [ fuse.Direntry(name) for name in ['config','disk','raid','tasks','visual'] ],
'/config': [ fuse.Direntry(name) for name in self.settings ],
@@ -215,11 +216,17 @@ class RaidGuessFS(fuse.Fuse):
self.tasks.set_find_files_pathlist(l)
logging.debug("Exit. update_task_find_files_pathlist(%s)"%arg)
+ def get_task_start(self):
+ return 'Write a task_name in this pseudo-file to start it\n'
+
+ def get_task_kill(self):
+ return 'Write a task_name in this pseudo-file to kill it\n'
+
+
########################################################
# Actual File System operations implementation follows #
########################################################
-
def fsinit(self):
"""Make some run-time initalisations after argument parsing"""
logging.info("Mounting filesystem...")