Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/datamanager.py
diff options
context:
space:
mode:
Diffstat (limited to 'datamanager.py')
-rw-r--r--datamanager.py190
1 files changed, 111 insertions, 79 deletions
diff --git a/datamanager.py b/datamanager.py
index 4732e72..95fc039 100644
--- a/datamanager.py
+++ b/datamanager.py
@@ -53,9 +53,11 @@ DEFAULTTOOLBAR = ACTIVITYTOOLBAR
class DataManager(activity.Activity):
def __init__(self, handle):
+
global store
- print 'activity started'
global SERIALNUMBER
+ global quitflag
+
activity.Activity.__init__(self, handle)
self.set_title("Datamanager")
f = open('/ofw/serial-number', 'r')
@@ -63,6 +65,7 @@ class DataManager(activity.Activity):
f.close()
SERIALNUMBER = t[:11]
print 'serial-number', SERIALNUMBER
+ quitflag = False
subprocess.call("mkdir -p " + WORKPATH, shell=True)
#Create the usage toolbar
self.usageTB = UsageToolbar(self)
@@ -90,17 +93,24 @@ class DataManager(activity.Activity):
global SERIALNUMBER
global store
global online
- action_request = 5
- status = 4
+ global quitflag
f = open(file_path, 'w')
f.write('this is a dummy file')
f.close()
- if not online:
- return True
- self.viewer.set_label('closing - online')
- print 'can_close online'
+ if quitflag:
+ return
+ else:
+ quitflag = True
+ action_request = 5
+ status = 4
+ today = strftime(DATEFORMAT)[:10]
+ if online:
+ self.viewer.set_label('closing - online')
+ print 'can_close online'
#now the real work begins
remove_list = []
+ wcount = 0
+ acount = 0
for row in store:
self.viewer.set_label('reviewing status: ' + row[0])
#action_request = 0: no action
@@ -108,92 +118,98 @@ class DataManager(activity.Activity):
#action_request = +1: upload
#action_request = -1: remove
if row[status] == 'White':
- row[action_request] = -1
+ print 'today', today, 'mtime', row[3]
+ if row[3].find(today) < 0:
+ row[action_request] = -1
+ wcount += 1
if row[status] == 'Red':
row[action_request] = +1
if row[action_request] < 0:
+ acount += 1
remove_list.append(row[0])
- if row[action_request] == 1 and row[status] == 'Red':
- #upload it
- self.viewer.set_label('reviewing status: ' + row[0] + ' upload')
- mname = row[0] + '.metadata'
- fname = row[0]
- srcm = LOCALPATH / mname
- srcf = LOCALPATH / fname
- if srcm.exists() and srcf.exists():
+ if online:
+ if row[action_request] == 1 and row[status] == 'Red':
+ #upload it
+ self.viewer.set_label('reviewing status: ' + row[0] + ' upload')
+ mname = row[0] + '.metadata'
+ fname = row[0]
+ srcm = LOCALPATH / mname
+ srcf = LOCALPATH / fname
+ if srcm.exists() and srcf.exists():
+ pfx = SERIALNUMBER + '@schoolserver:'
+ dst = STOREPATH / SERIALNUMBER
+ cmd = 'scp ' + srcm + ' ' + pfx + dst
+ print 'metadata upload', cmd
+ subprocess.call(cmd, shell=True)
+ cmd = 'scp ' + srcf + ' ' + pfx + dst
+ print 'file upload', cmd
+ subprocess.call(cmd, shell=True)
+ else:
+ print 'upload request but no document', row[1], srcf
+ if row[action_request] > 1 and row[status] == "Green":
+ #download from schoolserver
+ self.viewer.set_label('reviewing status: ' + row[0] + ' download')
+ mname = row[0] + '.metadata'
+ fname = row[0]
+ dst = LOCALPATH
+ pfx = SERIALNUMBER + '@schoolserver:'
+ src = STOREPATH / SERIALNUMBER / mname
+ cmd = 'scp ' + pfx + src + ' ' + dst
+ print 'metadata download', cmd
+ subprocess.call(cmd, shell=True)
+ src = STOREPATH / SERIALNUMBER / fname
+ cmd = 'scp ' + pfx + src + ' ' + dst
+ print 'file download', cmd
+ subprocess.call(cmd, shell=True)
+ if row[action_request] > 1 and row[status] == "cyan":
+ #download from Commons
+ self.viewer.set_label('reviewing status: ' + row[0] + ' download')
+ #if mime_type is activity - install it
+ mname = row[0] + '.metadata'
+ fname = row[0]
+ dst = LOCALPATH
+ pfx = SERIALNUMBER + '@schoolserver:'
+ src = COMMONSPATH / mname
+ cmd = 'scp ' + pfx + src + ' ' + dst
+ print 'metadata download', cmd
+ subprocess.call(cmd, shell=True)
+ src = COMMONSPATH / fname
+ cmd = 'scp ' + pfx + src + ' ' + dst
+ print 'file download', cmd
+ subprocess.call(cmd, shell=True)
+ if row[action_request] == 1 and row[status] == 'cyan':
+ #upload entry to Commons
+ self.viewer.set_label('reviewing status: ' + row[0] + ' upload')
+ #if mime_type is activity - install it
+ mname = row[0] + '.metadata'
+ fname = row[0]
+ dst = COMMONSPATH / mname
pfx = SERIALNUMBER + '@schoolserver:'
- dst = STOREPATH / SERIALNUMBER
- cmd = 'scp ' + srcm + ' ' + pfx + dst
- print 'metadata upload', cmd
+ src = LOCALPATH / mname
+ cmd = 'scp ' + src + ' ' + pfx + dst
+ print 'metadata upload', cmd
subprocess.call(cmd, shell=True)
- cmd = 'scp ' + srcf + ' ' + pfx + dst
+ src = LOCALPATH / fname
+ cmd = 'scp ' + src + ' ' + pfx + dst
print 'file upload', cmd
subprocess.call(cmd, shell=True)
- else:
- print 'upload request but no document', row[1], srcf
- if row[action_request] > 1 and row[status] == "Green":
- #download from schoolserver
- self.viewer.set_label('reviewing status: ' + row[0] + ' download')
- mname = row[0] + '.metadata'
- fname = row[0]
- dst = LOCALPATH
- pfx = SERIALNUMBER + '@schoolserver:'
- src = STOREPATH / SERIALNUMBER / mname
- cmd = 'scp ' + pfx + src + ' ' + dst
- print 'metadata download', cmd
- subprocess.call(cmd, shell=True)
- src = STOREPATH / SERIALNUMBER / fname
- cmd = 'scp ' + pfx + src + ' ' + dst
- print 'file download', cmd
- subprocess.call(cmd, shell=True)
- if row[action_request] > 1 and row[status] == "cyan":
- #download from Commons
- self.viewer.set_label('reviewing status: ' + row[0] + ' download')
- #if mime_type is activity - install it
- mname = row[0] + '.metadata'
- fname = row[0]
- dst = LOCALPATH
- pfx = SERIALNUMBER + '@schoolserver:'
- src = COMMONSPATH / mname
- cmd = 'scp ' + pfx + src + ' ' + dst
- print 'metadata download', cmd
- subprocess.call(cmd, shell=True)
- src = COMMONSPATH / fname
- cmd = 'scp ' + pfx + src + ' ' + dst
- print 'file download', cmd
- subprocess.call(cmd, shell=True)
- if row[action_request] == 1 and row[status] == 'cyan':
- #upload entry to Commons
- self.viewer.set_label('reviewing status: ' + row[0] + ' upload')
- #if mime_type is activity - install it
- mname = row[0] + '.metadata'
- fname = row[0]
- dst = COMMONSPATH / mname
- pfx = SERIALNUMBER + '@schoolserver:'
- src = LOCALPATH / mname
- cmd = 'scp ' + src + ' ' + pfx + dst
- print 'metadata upload', cmd
- subprocess.call(cmd, shell=True)
- src = LOCALPATH / fname
- cmd = 'scp ' + src + ' ' + pfx + dst
- print 'file upload', cmd
- subprocess.call(cmd, shell=True)
#now remove
self.viewer.set_label('removing files ...')
-
+ print 'removing:' , len(remove_list)
+ print 'white entries:', wcount
+ print 'appended:', acount
count = 0
for obj in remove_list:
- pth = LOCALPATH / obj
- if pth.exists():
- pth.remove()
- fn = obj + '.metadata'
- pth = LOCALPATH / fn
- if pth.exists():
- pth.remove()
- #datastore.delete(obj)
- count += 1
+ ds_object = datastore.get(obj)
+ if ds_object:
+ ds_object.destroy()
+ datastore.delete(ds_object.object_id)
+ count += 1
+ else:
+ print 'obj not found', obj
txt = 'done ' + str(count) + ' files deleted'
self.viewer.set_label(txt)
+ print txt
def show_properties(self, widget):
treeView = self.viewer.get_treeView()
@@ -225,6 +241,16 @@ class DataManager(activity.Activity):
row[4] = 'cyan'
row[5] = 1
+ def delete_entry(self, widget):
+ treeView = self.viewer.get_treeView()
+ treeselection = treeView.get_selection()
+ model, selection = treeselection.get_selected()
+ row = model[selection]
+ ds_object = datastore.get(row[0])
+ ds_object.destroy()
+ datastore.delete(ds_object.object_id)
+ model.remove(selection)
+
# based on PyGTK tutorial by jan bodnar, zetcode.com, February 2009
class Listview(gtk.VBox):
def __init__(self):
@@ -562,3 +588,9 @@ class UsageToolbar(gtk.Toolbar):
self.__uploadbtn.connect('clicked', activity.upload_commons)
self.insert(self.__uploadbtn, -1)
self.__uploadbtn.show()
+
+ self.__deletebtn = ToolButton('stock_delete')
+ self.__deletebtn.set_tooltip("Delete entry from local store")
+ self.__deletebtn.connect('clicked', activity.delete_entry)
+ self.insert(self.__deletebtn, -1)
+ self.__deletebtn.show()