mirror of
https://github.com/wassname/FanFicFare.git
synced 2026-09-09 11:14:08 +08:00
Add post_process_apply_filename_safepattern setting (default:true).
This commit is contained in:
+4
-1
@@ -378,7 +378,10 @@ def do_download(arg,
|
||||
output_filename = write_story(configuration, adapter, options.format, options.metaonly)
|
||||
|
||||
if not options.metaonly and adapter.getConfig('post_process_cmd'):
|
||||
metadata = adapter.story.getAllMetadata()
|
||||
if adapter.getConfig('post_process_apply_filename_safepattern',True):
|
||||
metadata = adapter.story.get_filename_safe_metadata()
|
||||
else:
|
||||
metadata = adapter.story.getAllMetadata()
|
||||
metadata['output_filename'] = output_filename
|
||||
call(string.Template(adapter.getConfig('post_process_cmd')).substitute(metadata), shell=True)
|
||||
|
||||
|
||||
@@ -189,11 +189,17 @@ extratags: FanFiction
|
||||
## prevent excessive wait when your network or the site is down.
|
||||
connect_timeout:60.0
|
||||
|
||||
## For use only with stand-alone CLI version--run a command on the
|
||||
## generated file after it's produced. All of the titlepage_entries
|
||||
## values are available, plus output_filename.
|
||||
## For use only with CLI version--run a command on the generated file
|
||||
## after it's produced. All of the titlepage_entries values are
|
||||
## available, plus output_filename.
|
||||
#post_process_cmd: addbook -f "${output_filename}" -t "${title}"
|
||||
|
||||
## Some operating systems and command shells have problems with some
|
||||
## characters. When true, the output_filename_safepattern will be
|
||||
## applied to each metadata item passed to post_process_cmd before
|
||||
## it's called.
|
||||
post_process_apply_filename_safepattern:true
|
||||
|
||||
## Use regular expressions to find and replace (or remove) metadata.
|
||||
## For example, you could change Sci-Fi=>SF, remove *-Centered tags,
|
||||
## etc. See http://docs.python.org/library/re.html (look for re.sub)
|
||||
|
||||
+17
-9
@@ -997,20 +997,28 @@ class Story(Configurable):
|
||||
|
||||
return retval
|
||||
|
||||
def get_filename_safe_metadata(self):
|
||||
origvalues = self.getAllMetadata()
|
||||
values={}
|
||||
pattern = re_compile(self.getConfig("output_filename_safepattern",
|
||||
r"(^\.|/\.|[^a-zA-Z0-9_\. \[\]\(\)&'-]+)"),
|
||||
"output_filename_safepattern")
|
||||
for k in origvalues.keys():
|
||||
if k == 'formatext': # don't do file extension--we set it anyway.
|
||||
values[k]=self.getMetadata(k)
|
||||
else:
|
||||
values[k]=re.sub(pattern,'_', removeAllEntities(self.getMetadata(k)))
|
||||
return values
|
||||
|
||||
def formatFileName(self,template,allowunsafefilename=True):
|
||||
values = origvalues = self.getAllMetadata()
|
||||
# fall back default:
|
||||
if not template:
|
||||
template="${title}-${siteabbrev}_${storyId}${formatext}"
|
||||
|
||||
if not allowunsafefilename:
|
||||
values={}
|
||||
pattern = re_compile(self.getConfig("output_filename_safepattern",r"(^\.|/\.|[^a-zA-Z0-9_\. \[\]\(\)&'-]+)"),"output_filename_safepattern")
|
||||
for k in origvalues.keys():
|
||||
if k == 'formatext': # don't do file extension--we set it anyway.
|
||||
values[k]=self.getMetadata(k)
|
||||
else:
|
||||
values[k]=re.sub(pattern,'_', removeAllEntities(self.getMetadata(k)))
|
||||
if allowunsafefilename:
|
||||
values = self.getAllMetadata()
|
||||
else:
|
||||
values = self.get_filename_safe_metadata()
|
||||
|
||||
return string.Template(template).substitute(values).encode('utf8')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user