plugin interface changed: now we use classes (inherited by CryptoBoxPlugin) instead of plain scripts
added some log entries use threading module instead of "fork" for background formatting redirection for "network" plugin fixed empty return value of plugins defaults to plugin overview page
This commit is contained in:
parent
52ccaeb530
commit
56e954d1c4
11 changed files with 545 additions and 436 deletions
|
@ -1,49 +1,64 @@
|
|||
import subprocess
|
||||
import os
|
||||
import CryptoBoxPlugin
|
||||
|
||||
|
||||
def doAction(hdf, cbox, store=None, year=0, month=0, day=0, hour=0, minute=0):
|
||||
import datetime
|
||||
__prepareFormData(hdf, cbox)
|
||||
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:
|
||||
hdf["Data.Warning"] = "Plugins.date.InvalidDate"
|
||||
class date(CryptoBoxPlugin.CryptoBoxPlugin):
|
||||
|
||||
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"
|
||||
else:
|
||||
self.__prepareFormData()
|
||||
return "form_date"
|
||||
|
||||
|
||||
def getStatus(self):
|
||||
return str(self.__getCurrentDate())
|
||||
|
||||
|
||||
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
|
||||
|
||||
|
||||
def __getCurrentDate(self):
|
||||
import datetime
|
||||
return datetime.datetime(2000,1,1).now()
|
||||
|
||||
|
||||
def __setDate(self, date):
|
||||
import subprocess
|
||||
import os
|
||||
proc = subprocess.Popen(
|
||||
shell = False,
|
||||
args = [
|
||||
cbox.prefs["Programs"]["super"],
|
||||
cbox.prefs["Programs"]["CryptoBoxRootActions"],
|
||||
self.cbox.prefs["Programs"]["super"],
|
||||
self.cbox.prefs["Programs"]["CryptoBoxRootActions"],
|
||||
"plugin",
|
||||
os.path.join(os.path.dirname(__file__), "root_action.py"),
|
||||
"%02d%02d%02d%02d%d" % (month, day, hour, minute, year)])
|
||||
os.path.join(self.pluginDir, "root_action.py"),
|
||||
date])
|
||||
proc.communicate()
|
||||
if proc.returncode == 0:
|
||||
return "form_system"
|
||||
else:
|
||||
hdf["Data.Warning"] = "Plugins.date.InvalidDate"
|
||||
return "form_date"
|
||||
else:
|
||||
return "form_date"
|
||||
|
||||
|
||||
def getStatus(cbox):
|
||||
return str(__getCurrentDate())
|
||||
|
||||
|
||||
def __prepareFormData(hdf, cbox):
|
||||
date = __getCurrentDate()
|
||||
hdf["Data.Plugins.date.year"] = date.year
|
||||
hdf["Data.Plugins.date.month"] = date.month
|
||||
hdf["Data.Plugins.date.day"] = date.day
|
||||
hdf["Data.Plugins.date.hour"] = date.hour
|
||||
hdf["Data.Plugins.date.minute"] = date.minute
|
||||
|
||||
|
||||
def __getCurrentDate():
|
||||
import datetime
|
||||
return datetime.datetime(2000,1,1).now()
|
||||
return proc.returncode == 0
|
||||
|
||||
|
|
|
@ -23,7 +23,14 @@ Text.Months {
|
|||
12 = December
|
||||
}
|
||||
|
||||
WarningMessage.InvalidDate {
|
||||
Title = Invalid value
|
||||
Text = An invalid value for date or time was supplied. Please try again.
|
||||
SuccessMessage.DateChanged {
|
||||
Title = Date changed
|
||||
Text = The date was changed successfully.
|
||||
}
|
||||
|
||||
WarningMessage {
|
||||
InvalidDate {
|
||||
Title = Invalid value
|
||||
Text = An invalid value for date or time was supplied. Please try again.
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue