0001-factorize-WorklowStatusItem.compute.patch
wcs/qommon/misc.py | ||
---|---|---|
500 | 500 |
def parse_isotime(s): |
501 | 501 |
t = time.strptime(s, '%Y-%m-%dT%H:%M:%SZ') |
502 | 502 |
return calendar.timegm(t) |
503 | ||
504 | ||
505 |
def compute(expr, do_ezt=True, raises=False, context=None): |
|
506 |
if not isinstance(expr, basestring): |
|
507 |
return expr |
|
508 | ||
509 |
if not expr.startswith('=') and not do_ezt: |
|
510 |
return expr |
|
511 | ||
512 |
vars = get_publisher().substitutions.get_context_variables() |
|
513 |
vars.update(context or {}) |
|
514 | ||
515 |
if not expr.startswith('='): |
|
516 |
try: |
|
517 |
processor = ezt.Template(compress_whitespace=False) |
|
518 |
processor.parse(expr) |
|
519 |
fd = StringIO() |
|
520 |
processor.generate(fd, vars) |
|
521 |
return fd.getvalue() |
|
522 |
except ezt.EZTException: |
|
523 |
if raises: |
|
524 |
raise |
|
525 |
return expr |
|
526 | ||
527 |
try: |
|
528 |
return eval(expr[1:], get_publisher().get_global_eval_dict(), vars) |
|
529 |
except: |
|
530 |
if raises: |
|
531 |
raise |
|
532 |
return expr |
wcs/workflows.py | ||
---|---|---|
29 | 29 | |
30 | 30 |
from quixote import get_request, redirect |
31 | 31 | |
32 |
from qommon.misc import C_, get_as_datetime |
|
32 |
from qommon.misc import C_, get_as_datetime, compute
|
|
33 | 33 |
from qommon.storage import StorableObject |
34 | 34 |
from qommon.form import * |
35 | 35 |
from qommon.humantime import seconds2humanduration |
... | ... | |
1600 | 1600 | |
1601 | 1601 |
@classmethod |
1602 | 1602 |
def compute(cls, var, do_ezt=True, raises=False): |
1603 |
if not isinstance(var, basestring): |
|
1604 |
return var |
|
1605 | ||
1606 |
if not var.startswith('=') and not do_ezt: |
|
1607 |
return var |
|
1608 | ||
1609 |
vars = get_publisher().substitutions.get_context_variables() |
|
1610 |
if not var.startswith('='): |
|
1611 |
try: |
|
1612 |
processor = ezt.Template(compress_whitespace=False) |
|
1613 |
processor.parse(var) |
|
1614 |
fd = StringIO() |
|
1615 |
processor.generate(fd, vars) |
|
1616 |
return fd.getvalue() |
|
1617 |
except ezt.EZTException: |
|
1618 |
if raises: |
|
1619 |
raise |
|
1620 |
return var |
|
1621 | ||
1622 |
try: |
|
1623 |
return eval(var[1:], get_publisher().get_global_eval_dict(), vars) |
|
1624 |
except: |
|
1625 |
if raises: |
|
1626 |
raise |
|
1627 |
return var |
|
1603 |
return compute(var, do_ezt=do_ezt, raises=raises) |
|
1628 | 1604 | |
1629 | 1605 |
def get_substitution_variables(self, formdata): |
1630 | 1606 |
return {} |
1631 |
- |