mirror of
https://github.com/openzim/zimit.git
synced 2025-09-22 11:22:23 -04:00
Add a way to specify the location of the output folder
This commit is contained in:
parent
8277e3f883
commit
d8cf8dffc2
@ -3,13 +3,15 @@ use = egg:zimit
|
||||
|
||||
zimit.zimwriterfs_bin = /home/alexis/dev/openzim/zimwriterfs/zimwriterfs
|
||||
zimit.httrack_bin = /usr/bin/httrack
|
||||
zimit.output_location = /tmp/
|
||||
zimit.output_url = http://zimit.notmyidea.org/zims
|
||||
|
||||
mail.host = localhost
|
||||
mail.port = 2525
|
||||
mail.default_sender = Zim It!
|
||||
mail.default_sender = zimit@notmyidea.org
|
||||
|
||||
pyramid.includes =
|
||||
pyramid_mailer
|
||||
pyramid_mailer.debug
|
||||
|
||||
[server:main]
|
||||
use = egg:waitress#main
|
||||
|
15
zimit/utils.py
Normal file
15
zimit/utils.py
Normal file
@ -0,0 +1,15 @@
|
||||
import os
|
||||
import shlex
|
||||
import subprocess
|
||||
|
||||
|
||||
def spawn(cmd):
|
||||
"""Quick shortcut to spawn a command on the filesystem"""
|
||||
return subprocess.Popen(shlex.split(cmd))
|
||||
|
||||
|
||||
def ensure_paths_exists(*paths):
|
||||
for path in paths:
|
||||
if not os.path.exists(path):
|
||||
msg = '%s does not exist.' % path
|
||||
raise OSError(msg)
|
@ -1,45 +1,41 @@
|
||||
import os
|
||||
import shlex
|
||||
import os.path
|
||||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import urlparse
|
||||
|
||||
from pyramid_mailer import Mailer
|
||||
from slugify import slugify
|
||||
|
||||
from zimit.messages import ZimReadyMessage
|
||||
|
||||
from zimit import utils
|
||||
|
||||
HTTRACK_BIN = "/usr/bin/httrack"
|
||||
DEFAULT_AUTHOR = "BSF"
|
||||
|
||||
|
||||
def spawn(cmd):
|
||||
"""Quick shortcut to spawn a command on the filesystem"""
|
||||
return subprocess.Popen(shlex.split(cmd))
|
||||
|
||||
|
||||
class ZimCreator(object):
|
||||
|
||||
def __init__(self, settings):
|
||||
if 'zimit.zimwriterfs_bin' not in settings:
|
||||
raise ValueError('Please define zimit.zimwriterfs_bin config.')
|
||||
|
||||
if not os.path.exists(settings['zimit.zimwriterfs_bin']):
|
||||
msg = '%s does not exist.' % settings['zimit.zimwriterfs_bin']
|
||||
raise OSError(msg)
|
||||
|
||||
zimwriterfs_bin = settings['zimit.zimwriterfs_bin']
|
||||
httrack_bin = settings.get('zimit.httrack_bin', HTTRACK_BIN)
|
||||
if not os.path.exists(httrack_bin):
|
||||
raise OSError('%s does not exist.' % httrack_bin)
|
||||
output_location = settings.get('zimit.output_location')
|
||||
|
||||
utils.ensure_paths_exists(
|
||||
zimwriterfs_bin, httrack_bin, output_location)
|
||||
|
||||
self.zimwriterfs_bin = settings.get('zimit.zimwriterfs_bin')
|
||||
self.httrack_bin = httrack_bin
|
||||
self.author = settings.get('zimit.default_author', DEFAULT_AUTHOR)
|
||||
self.output_location = settings.get('zimit.output_location')
|
||||
self.output_url = settings.get('zimit.output_url')
|
||||
self.settings = settings
|
||||
|
||||
def download_website(self, url):
|
||||
path = tempfile.mkdtemp("website")
|
||||
p = spawn("%s --path %s %s" % (self.httrack_bin, path, url))
|
||||
p = utils.spawn("%s --path %s %s" % (self.httrack_bin, path, url))
|
||||
p.wait()
|
||||
shutil.copy('./favicon.ico', path)
|
||||
return path
|
||||
@ -49,21 +45,23 @@ class ZimCreator(object):
|
||||
config.update({
|
||||
'bin': self.zimwriterfs_bin,
|
||||
'location': html_location,
|
||||
'output': zim_file,
|
||||
'output': os.path.join(self.output_location, zim_file),
|
||||
'icon': 'favicon.ico',
|
||||
'publisher': self.author,
|
||||
})
|
||||
|
||||
# Spawn zimwriterfs with the correct options.
|
||||
p = spawn(('{bin} -w "{welcome}" -l "{language}" -t "{title}"'
|
||||
' -d "{description}" -f {icon} -c "{author}"'
|
||||
' -p "{publisher}" {location} {output}').format(**config))
|
||||
p = utils.spawn(
|
||||
('{bin} -w "{welcome}" -l "{language}" -t "{title}"'
|
||||
' -d "{description}" -f {icon} -c "{author}"'
|
||||
' -p "{publisher}" {location} {output}').format(**config))
|
||||
p.wait()
|
||||
return zim_file
|
||||
|
||||
def send_email(self, email, zim_file):
|
||||
mailer = Mailer.from_settings(self.settings)
|
||||
msg = ZimReadyMessage(email, zim_file)
|
||||
zim_file_url = urlparse.urljoin(self.output_url, zim_file)
|
||||
msg = ZimReadyMessage(email, zim_file_url)
|
||||
mailer.send_immediately(msg)
|
||||
|
||||
def create_zim_from_website(self, config):
|
||||
|
Loading…
x
Reference in New Issue
Block a user