[actions] implement 'flag … = skip' (#8960)
This commit is contained in:
@@ -10173,7 +10173,7 @@ Description
|
||||
|
||||
| Expected syntax is ``<flag>[ = <value>]`` (e.g. ``post = stop``)
|
||||
| ``<flag>`` can be one of ``file``, ``post``, ``child``, ``download``
|
||||
| ``<value>`` can be one of ``stop``, ``abort``, ``terminate``, ``restart`` (default ``stop``)
|
||||
| ``<value>`` can be one of ``stop``, ``abort``, ``terminate``, ``restart``, ``skip`` (default ``stop``)
|
||||
``wait``:
|
||||
| Sleep for a given Duration_ or
|
||||
| wait until Enter is pressed when no argument was given.
|
||||
|
||||
@@ -231,7 +231,13 @@ def action_flag(opts):
|
||||
r"(?i)(file|post|child|download)(?:\s*[= ]\s*(.+))?"
|
||||
).match(opts).groups()
|
||||
flag = flag.upper()
|
||||
value = "stop" if value is None else value.lower()
|
||||
|
||||
if value is None:
|
||||
value = "stop"
|
||||
elif value == "skip":
|
||||
value = "stop" if flag == "DOWNLOAD" else False
|
||||
else:
|
||||
value = value.lower()
|
||||
|
||||
def _flag(args):
|
||||
util.FLAGS.__dict__[flag] = value
|
||||
|
||||
@@ -385,10 +385,9 @@ class HttpDownloader(DownloaderBase):
|
||||
def receive(self, fp, content, bytes_total, bytes_start):
|
||||
write = fp.write
|
||||
for data in content:
|
||||
write(data)
|
||||
|
||||
if FLAGS.DOWNLOAD is not None:
|
||||
FLAGS.process("DOWNLOAD")
|
||||
return FLAGS.process("DOWNLOAD")
|
||||
write(data)
|
||||
|
||||
def _receive_rate(self, fp, content, bytes_total, bytes_start):
|
||||
rate = self.rate() if self.rate else None
|
||||
@@ -399,14 +398,13 @@ class HttpDownloader(DownloaderBase):
|
||||
time_start = time.monotonic()
|
||||
|
||||
for data in content:
|
||||
if FLAGS.DOWNLOAD is not None:
|
||||
return FLAGS.process("DOWNLOAD")
|
||||
time_elapsed = time.monotonic() - time_start
|
||||
bytes_downloaded += len(data)
|
||||
|
||||
write(data)
|
||||
|
||||
if FLAGS.DOWNLOAD is not None:
|
||||
FLAGS.process("DOWNLOAD")
|
||||
|
||||
if progress is not None:
|
||||
if time_elapsed > progress:
|
||||
self.out.progress(
|
||||
|
||||
@@ -224,12 +224,18 @@ class Job():
|
||||
|
||||
elif process is None:
|
||||
continue
|
||||
elif FLAGS.POST is False:
|
||||
FLAGS.POST = process = None
|
||||
continue
|
||||
|
||||
elif msg == Message.Url:
|
||||
if self.metadata_url:
|
||||
kwdict[self.metadata_url] = url
|
||||
self.update_kwdict(kwdict)
|
||||
if self.pred_url(url, kwdict):
|
||||
if FLAGS.FILE is False:
|
||||
FLAGS.FILE = None
|
||||
continue
|
||||
self.handle_url(url, kwdict)
|
||||
if FLAGS.FILE is not None:
|
||||
FLAGS.process("FILE")
|
||||
@@ -239,6 +245,9 @@ class Job():
|
||||
if self.metadata_url:
|
||||
kwdict[self.metadata_url] = url
|
||||
if self.pred_queue(url, kwdict):
|
||||
if FLAGS.CHILD is False:
|
||||
FLAGS.CHILD = None
|
||||
continue
|
||||
self.handle_queue(url, kwdict)
|
||||
if FLAGS.CHILD is not None:
|
||||
FLAGS.process("CHILD")
|
||||
|
||||
@@ -677,6 +677,8 @@ class Flags():
|
||||
|
||||
def process(self, flag):
|
||||
value = self.__dict__[flag]
|
||||
if value is False: # flag was set to "skip"
|
||||
return "skip"
|
||||
self.__dict__[flag] = None
|
||||
|
||||
if value == "abort":
|
||||
|
||||
Reference in New Issue
Block a user