[postprocessor:mtime] add 'value' option (#2739)
This commit is contained in:
@@ -3464,6 +3464,24 @@ Description
|
|||||||
This value must either be a UNIX timestamp or a
|
This value must either be a UNIX timestamp or a
|
||||||
|datetime|_ object.
|
|datetime|_ object.
|
||||||
|
|
||||||
|
Note: This option gets ignored if `mtime.value`_ is set.
|
||||||
|
|
||||||
|
|
||||||
|
mtime.value
|
||||||
|
-----------
|
||||||
|
Type
|
||||||
|
``string``
|
||||||
|
Default
|
||||||
|
``null``
|
||||||
|
Example
|
||||||
|
* ``"{status[date]}"``
|
||||||
|
* ``"{content[0:6]:R22/2022/D%Y%m%d/}"``
|
||||||
|
Description
|
||||||
|
A `format string`_ whose value should be used.
|
||||||
|
|
||||||
|
The resulting value must either be a UNIX timestamp or a
|
||||||
|
|datetime|_ object.
|
||||||
|
|
||||||
|
|
||||||
ugoira.extension
|
ugoira.extension
|
||||||
----------------
|
----------------
|
||||||
|
|||||||
@@ -9,7 +9,7 @@
|
|||||||
"""Use metadata as file modification time"""
|
"""Use metadata as file modification time"""
|
||||||
|
|
||||||
from .common import PostProcessor
|
from .common import PostProcessor
|
||||||
from .. import text, util
|
from .. import text, util, formatter
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
|
|
||||||
|
|
||||||
@@ -17,7 +17,12 @@ class MtimePP(PostProcessor):
|
|||||||
|
|
||||||
def __init__(self, job, options):
|
def __init__(self, job, options):
|
||||||
PostProcessor.__init__(self, job)
|
PostProcessor.__init__(self, job)
|
||||||
self.key = options.get("key", "date")
|
value = options.get("value")
|
||||||
|
if value:
|
||||||
|
self._get = formatter.parse(value, None, util.identity).format_map
|
||||||
|
else:
|
||||||
|
key = options.get("key", "date")
|
||||||
|
self._get = lambda kwdict: kwdict.get(key)
|
||||||
|
|
||||||
events = options.get("event")
|
events = options.get("event")
|
||||||
if events is None:
|
if events is None:
|
||||||
@@ -27,7 +32,7 @@ class MtimePP(PostProcessor):
|
|||||||
job.register_hooks({event: self.run for event in events}, options)
|
job.register_hooks({event: self.run for event in events}, options)
|
||||||
|
|
||||||
def run(self, pathfmt):
|
def run(self, pathfmt):
|
||||||
mtime = pathfmt.kwdict.get(self.key)
|
mtime = self._get(pathfmt.kwdict)
|
||||||
pathfmt.kwdict["_mtime"] = (
|
pathfmt.kwdict["_mtime"] = (
|
||||||
util.datetime_to_timestamp(mtime)
|
util.datetime_to_timestamp(mtime)
|
||||||
if isinstance(mtime, datetime) else
|
if isinstance(mtime, datetime) else
|
||||||
|
|||||||
@@ -350,10 +350,6 @@ class MetadataTest(BasePostprocessorTest):
|
|||||||
|
|
||||||
class MtimeTest(BasePostprocessorTest):
|
class MtimeTest(BasePostprocessorTest):
|
||||||
|
|
||||||
def test_mtime_default(self):
|
|
||||||
pp = self._create()
|
|
||||||
self.assertEqual(pp.key, "date")
|
|
||||||
|
|
||||||
def test_mtime_datetime(self):
|
def test_mtime_datetime(self):
|
||||||
self._create(None, {"date": datetime(1980, 1, 1)})
|
self._create(None, {"date": datetime(1980, 1, 1)})
|
||||||
self._trigger()
|
self._trigger()
|
||||||
@@ -364,11 +360,16 @@ class MtimeTest(BasePostprocessorTest):
|
|||||||
self._trigger()
|
self._trigger()
|
||||||
self.assertEqual(self.pathfmt.kwdict["_mtime"], 315532800)
|
self.assertEqual(self.pathfmt.kwdict["_mtime"], 315532800)
|
||||||
|
|
||||||
def test_mtime_custom(self):
|
def test_mtime_key(self):
|
||||||
self._create({"key": "foo"}, {"foo": 315532800})
|
self._create({"key": "foo"}, {"foo": 315532800})
|
||||||
self._trigger()
|
self._trigger()
|
||||||
self.assertEqual(self.pathfmt.kwdict["_mtime"], 315532800)
|
self.assertEqual(self.pathfmt.kwdict["_mtime"], 315532800)
|
||||||
|
|
||||||
|
def test_mtime_value(self):
|
||||||
|
self._create({"value": "{foo}"}, {"foo": 315532800})
|
||||||
|
self._trigger()
|
||||||
|
self.assertEqual(self.pathfmt.kwdict["_mtime"], 315532800)
|
||||||
|
|
||||||
|
|
||||||
class ZipTest(BasePostprocessorTest):
|
class ZipTest(BasePostprocessorTest):
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user