2006-09-25 14:21:39 +02:00
|
|
|
import CryptoBoxPlugin
|
|
|
|
|
|
|
|
|
|
|
|
class date(CryptoBoxPlugin.CryptoBoxPlugin):
|
|
|
|
|
2006-10-09 18:43:14 +02:00
|
|
|
pluginCapabilities = [ "system" ]
|
|
|
|
requestAuth = False
|
2006-10-11 17:50:24 +02:00
|
|
|
rank = 10
|
2006-10-09 18:43:14 +02:00
|
|
|
|
2006-09-25 14:21:39 +02:00
|
|
|
def doAction(self, store=None, year=0, month=0, day=0, hour=0, minute=0):
|
|
|
|
import datetime
|
|
|
|
if store:
|
|
|
|
try:
|
|
|
|
year, month, day = int(year), int(month), int(day)
|
|
|
|
hour, minute = int(hour), int(minute)
|
|
|
|
new_date = datetime.datetime(year, month, day, hour, minute)
|
|
|
|
except ValueError:
|
|
|
|
self.hdf["Data.Warning"] = "Plugins.date.InvalidDate"
|
|
|
|
self.__prepareFormData()
|
|
|
|
return "form_date"
|
|
|
|
date = "%02d%02d%02d%02d%d" % (month, day, hour, minute, year)
|
|
|
|
if self.__setDate(date):
|
|
|
|
self.cbox.log.info("changed date to: %s" % date)
|
|
|
|
self.hdf["Data.Success"] = "Plugins.date.DateChanged"
|
|
|
|
return None
|
|
|
|
else:
|
|
|
|
## a failure should usually be an invalid date (we do not check it really)
|
|
|
|
self.cbox.log.info("failed to set date: %s" % date)
|
|
|
|
self.hdf["Data.Warning"] = "Plugins.date.InvalidDate"
|
|
|
|
self.__prepareFormData()
|
|
|
|
return "form_date"
|
2006-09-13 12:38:05 +02:00
|
|
|
else:
|
2006-09-25 14:21:39 +02:00
|
|
|
self.__prepareFormData()
|
2006-09-14 14:33:01 +02:00
|
|
|
return "form_date"
|
2006-09-12 10:55:20 +02:00
|
|
|
|
|
|
|
|
2006-09-25 14:21:39 +02:00
|
|
|
def getStatus(self):
|
|
|
|
return str(self.__getCurrentDate())
|
|
|
|
|
2006-09-12 10:55:20 +02:00
|
|
|
|
2006-09-25 14:21:39 +02:00
|
|
|
def __prepareFormData(self):
|
|
|
|
date = self.__getCurrentDate()
|
|
|
|
self.hdf[self.hdf_prefix + "year"] = date.year
|
|
|
|
self.hdf[self.hdf_prefix + "month"] = date.month
|
|
|
|
self.hdf[self.hdf_prefix + "day"] = date.day
|
|
|
|
self.hdf[self.hdf_prefix + "hour"] = date.hour
|
|
|
|
self.hdf[self.hdf_prefix + "minute"] = date.minute
|
2006-09-12 10:55:20 +02:00
|
|
|
|
2006-09-14 14:33:01 +02:00
|
|
|
|
2006-09-25 14:21:39 +02:00
|
|
|
def __getCurrentDate(self):
|
|
|
|
import datetime
|
|
|
|
return datetime.datetime(2000,1,1).now()
|
|
|
|
|
2006-09-14 14:33:01 +02:00
|
|
|
|
2006-09-25 14:21:39 +02:00
|
|
|
def __setDate(self, date):
|
|
|
|
import subprocess
|
|
|
|
import os
|
|
|
|
proc = subprocess.Popen(
|
|
|
|
shell = False,
|
|
|
|
args = [
|
|
|
|
self.cbox.prefs["Programs"]["super"],
|
|
|
|
self.cbox.prefs["Programs"]["CryptoBoxRootActions"],
|
|
|
|
"plugin",
|
|
|
|
os.path.join(self.pluginDir, "root_action.py"),
|
|
|
|
date])
|
|
|
|
proc.communicate()
|
|
|
|
return proc.returncode == 0
|
2006-09-12 10:55:20 +02:00
|
|
|
|