cryptonas-branches/pythonrewrite/plugins/date/date.py

49 lines
1.2 KiB
Python
Raw Normal View History

from CryptoBoxExceptions import CBPluginActionError
import subprocess
import os
def prepareForm(hdf, cbox):
date = __getCurrentDate()
hdf["Data.Modules.date.year"] = date.year
hdf["Data.Modules.date.month"] = date.month
hdf["Data.Modules.date.day"] = date.day
hdf["Data.Modules.date.hour"] = date.hour
hdf["Data.Modules.date.minute"] = date.minute
def doAction(cbox, 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:
raise CBPluginActionError, "InvalidDate"
proc = subprocess.Popen(
shell = False,
args = [
cbox.prefs["Programs"]["super"],
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)])
proc.communicate()
if proc.returncode == 0:
return "form_system"
else:
raise CBPluginActionError, "InvalidDate"
else:
return "form_date"
def getStatus(cbox):
return str(__getCurrentDate())
def __getCurrentDate():
import datetime
return datetime.datetime(2000,1,1).now()