Several fixes. "styles" directory was not present before copying

files into. Correction of filename in copyright part. Eliminate
store_file and replaced by copy_file (takes care of directory creation
and error message.)
	* src/plugins/NarrativeWeb.py


svn: r10870
This commit is contained in:
Kees Bakker 2008-07-17 11:54:33 +00:00
parent 445da31691
commit 63a936c593

View File

@ -301,7 +301,7 @@ class BasePage:
of.write('%s' % cright) of.write('%s' % cright)
elif 0 < copy_nr < 7: elif 0 < copy_nr < 7:
text = _CC[copy_nr] text = _CC[copy_nr]
fname = build_url_fname("somerights20.gif", 'images', self.up) fname = self.build_url_fname("somerights20.gif", 'images', self.up)
text = text % {'gif_fname' : fname} text = text % {'gif_fname' : fname}
of.write(text) of.write(text)
of.write('</p>\n') of.write('</p>\n')
@ -461,7 +461,7 @@ class BasePage:
try: try:
lnkref = (self.report.cur_fname, self.page_title, self.gid) lnkref = (self.report.cur_fname, self.page_title, self.gid)
self.report.add_lnkref_to_photo(photo, lnkref) self.report.add_lnkref_to_photo(photo, lnkref)
(real_path, newpath) = self.report.copy_media(photo) real_path, newpath = self.report.prepare_copy_media(photo)
of.write('\t<div class="snapshot">\n') of.write('\t<div class="snapshot">\n')
# TODO. Check if build_url_fname can be used. # TODO. Check if build_url_fname can be used.
newpath = '/'.join(['..']*3 + [newpath]) newpath = '/'.join(['..']*3 + [newpath])
@ -507,7 +507,7 @@ class BasePage:
try: try:
lnkref = (self.report.cur_fname, self.page_title, self.gid) lnkref = (self.report.cur_fname, self.page_title, self.gid)
self.report.add_lnkref_to_photo(photo, lnkref) self.report.add_lnkref_to_photo(photo, lnkref)
(real_path, newpath) = self.report.copy_media(photo) real_path, newpath = self.report.prepare_copy_media(photo)
descr = " ".join(wrapper.wrap(title)) descr = " ".join(wrapper.wrap(title))
# TODO. Check if build_url_fname can be used. # TODO. Check if build_url_fname can be used.
newpath = '/'.join(['..']*3 + [newpath]) newpath = '/'.join(['..']*3 + [newpath])
@ -1200,7 +1200,7 @@ class MediaPage(BasePage):
thmb_path, 320): thmb_path, 320):
try: try:
path = self.report.build_path('preview', photo.handle) path = self.report.build_path('preview', photo.handle)
self.report.store_file(thmb_path, os.path.join(path, photo.handle) + '.png') self.report.copy_file(thmb_path, os.path.join(path, photo.handle) + '.png')
os.unlink(thmb_path) os.unlink(thmb_path)
except IOError: except IOError:
path = os.path.join('images', 'document.png') path = os.path.join('images', 'document.png')
@ -1323,18 +1323,7 @@ class MediaPage(BasePage):
else: else:
from_path = os.path.join(const.IMAGE_DIR, "document.png") from_path = os.path.join(const.IMAGE_DIR, "document.png")
# FIXME. Why not use store_file()? self.report.copy_file(from_path, to_path)
if self.report.archive:
self.report.archive.add(from_path, to_path)
else:
to_dir = os.path.join(self.html_dir, to_dir)
dest = os.path.join(self.html_dir, to_path)
if not os.path.isdir(to_dir):
os.makedirs(to_dir)
try:
shutil.copyfile(from_path, dest)
except IOError:
print "Could not copy file"
class SurnameListPage(BasePage): class SurnameListPage(BasePage):
ORDER_BY_NAME = 0 ORDER_BY_NAME = 0
@ -2312,11 +2301,11 @@ class IndividualPage(BasePage):
family = db.get_family_from_handle(family_handle) family = db.get_family_from_handle(family_handle)
for step_child_ref in family.get_child_ref_list(): for step_child_ref in family.get_child_ref_list():
step_child_handle = step_child_ref.ref step_child_handle = step_child_ref.ref
if step_child_handle not in sibling and \ if step_child_handle not in sibling and \
step_child_handle not in half_siblings and \ step_child_handle not in half_siblings and \
step_child_handle != self.person.handle: step_child_handle != self.person.handle:
# we have a new step sibling # we have a new step sibling
step_siblings.add(step_child_handle) step_siblings.add(step_child_handle)
# now that we have all of the step-siblings, print them out # now that we have all of the step-siblings, print them out
if len(step_siblings) > 0: if len(step_siblings) > 0:
@ -2716,8 +2705,7 @@ class NavWebReport(Report):
for f in imgs: for f in imgs:
from_path = os.path.join(const.IMAGE_DIR, f) from_path = os.path.join(const.IMAGE_DIR, f)
to_path = os.path.join("images", f) self.copy_file(from_path, f, "images")
self.store_file(from_path, to_path)
place_list = {} place_list = {}
source_list = {} source_list = {}
@ -2751,16 +2739,10 @@ class NavWebReport(Report):
Copy the CSS files to the target directory. Copy the CSS files to the target directory.
""" """
if self.archive: fname = os.path.join(const.DATA_DIR, css_file)
fname = os.path.join(const.DATA_DIR, css_file) self.copy_file(fname, _NARRATIVESCREEN, "styles")
self.archive.add(fname, _NARRATIVESCREEN) fname = os.path.join(const.DATA_DIR, "Web_Print-Default.css")
fname = os.path.join(const.DATA_DIR, "Web_Print-Default.css") self.copy_file(fname, _NARRATIVEPRINT, "styles")
self.archive.add(fname, _NARRATIVEPRINT)
else:
shutil.copyfile(os.path.join(const.DATA_DIR, css_file),
os.path.join(self.html_dir, "styles", _NARRATIVESCREEN))
shutil.copyfile(os.path.join(const.DATA_DIR, "Web_Print-Default.css"),
os.path.join(self.html_dir, "styles", _NARRATIVEPRINT))
def person_pages(self, ind_list, place_list, source_list): def person_pages(self, ind_list, place_list, source_list):
@ -2864,8 +2846,8 @@ class NavWebReport(Report):
mime_type = obj.get_mime_type() mime_type = obj.get_mime_type()
if mime_type and mime_type.startswith("image"): if mime_type and mime_type.startswith("image"):
try: try:
(newpath, thumb_path) = self.copy_media(obj) newpath, thumb_path = self.prepare_copy_media(obj)
self.store_file(Utils.media_path_full(db, obj.get_path()), self.copy_file(Utils.media_path_full(db, obj.get_path()),
newpath) newpath)
of.write('\t<img') of.write('\t<img')
if height: if height:
@ -2975,53 +2957,36 @@ class NavWebReport(Report):
else: else:
photo_list[handle] = [lnkref] photo_list[handle] = [lnkref]
def copy_media(self, photo): def prepare_copy_media(self, photo):
handle = photo.get_handle() handle = photo.get_handle()
ext = os.path.splitext(photo.get_path())[1] ext = os.path.splitext(photo.get_path())[1]
real_path = os.path.join(self.build_path('images', handle), handle + ext) real_path = os.path.join(self.build_path('images', handle), handle + ext)
thumb_path = os.path.join(self.build_path('thumb', handle), handle + '.png') thumb_path = os.path.join(self.build_path('thumb', handle), handle + '.png')
return (real_path, thumb_path) return real_path, thumb_path
def copy_file(self, from_fname, to_fname, to_dir=''): def copy_file(self, from_fname, to_fname, to_dir=''):
""" """
Copy a file from a source to a (report) destination. Copy a file from a source to a (report) destination.
If to_dir is not present and if the target is not an archive, If to_dir is not present and if the target is not an archive,
then the destination directory will be created. then the destination directory will be created.
Normally 'to_fname' will be just a filename, without directory path.
'to_dir' is the relative path name in the destination root. It will
be prepended before 'to_fname'.
""" """
if self.archive: if self.archive:
dest = os.path.join(to_dir, to_fname) dest = os.path.join(to_dir, to_fname)
self.archive.add(from_fname, dest) self.archive.add(from_fname, dest)
else: else:
dest = os.path.join(self.html_dir, to_dir) dest = os.path.join(self.html_dir, to_dir, to_fname)
if not os.path.isdir(dest):
os.makedirs(dest)
dest = os.path.join(dest, to_fname)
if from_fname != dest:
self.store_file(from_fname, dest)
elif self.warn_dir:
WarningDialog(
_("Possible destination error") + "\n" +
_("You appear to have set your target directory "
"to a directory used for data storage. This "
"could create problems with file management. "
"It is recommended that you consider using "
"a different directory to store your generated "
"web pages."))
self.warn_dir = False
def store_file(self, from_path, to_path): destdir = os.path.dirname(dest)
""" if not os.path.isdir(destdir):
Store the file in the destination. os.makedirs(destdir)
"""
if self.archive: if from_fname != dest:
self.archive.add(str(from_path), str(to_path)) shutil.copyfile(from_fname, dest)
else:
dest = os.path.join(self.html_dir, to_path)
dirname = os.path.dirname(dest)
if not os.path.isdir(dirname):
os.makedirs(dirname)
if from_path != dest:
shutil.copyfile(from_path, dest)
elif self.warn_dir: elif self.warn_dir:
WarningDialog( WarningDialog(
_("Possible destination error") + "\n" + _("Possible destination error") + "\n" +