Re: Working with ePub: generate .toc and .opf files?

2012-08-17 Thread Eelco Deuling
Hello,

I have done some work and made some progress with it. The following script 
is a test-script to generate the manifest part of the content.opf:

---

#!/usr/bin/env python 

 
# call the operating system (?) 
 
import os 

 
# create the directory structure 
 
My_Epub = epub
if not os.path.exists(My_Epub): 
os.mkdir(My_Epub) 

root_path = ./epub/ 
folders = [META-INF, OEBPS, OEBPS/texts, OEBPS/css, OEBPS/media, 
OEBPS/fonts] 
for folder in folders: 
   os.mkdir(os.path.join(root_path,folder)) 

 
# create the mimetype file 
 
with open(os.path.join(My_Epub, mimetype), w) as fp: 
fp.write(application/epub+zip) 

 
# create the container xml file 
 
My_Container_xml = ?xml version=1.0 ? 
container version=1.0 
xmlns=urn:oasis:names:tc:opendocument:xmlns:container 
rootfiles 
rootfile full-path=OEBPS/content.opf 
media-type=application/oebps-package+xml / 
/rootfiles 
/container 
 

with open(os.path.join(My_Epub, META-INF, container.xml),w) as fp: 
fp.write(My_Container_xml) 

 
# create first parts of toc.ncx, content.opf and nav.xhtml
 
with open(os.path.join(My_Epub, OEBPS, toc.ncx), w) as fp: 
fp.write() 
with open(os.path.join(My_Epub, OEBPS, content.opf), w) as fp: 
fp.write() 
with open(os.path.join(My_Epub, OEBPS, nav.xhtml), w) as fp: 
fp.write() 

---

I do feel I did this not very 'nice', but (again) it works.Any suggestions 
to improve it will be more than welcome.

With regards,

Eelco Deuling

-- 
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.
Follow @bbedit on Twitter: http://www.twitter.com/bbedit





Re: Working with ePub: generate .toc and .opf files?

2012-08-17 Thread Eelco Deuling
Sorry: this part I had posted already!

This is the second part:

---

import os
import re

##
# remove OSX .DS_Store files
##

for root, dirs, files in os.walk('./'):
if '.DS_Store' in files:
os.remove(os.path.join(root, '.DS_Store'))

##
# create a temporary file
# for the directory list
##

f = open('myfile_01.tmp', 'w')

for root, dirs, files in os.walk('./'):
 for name in files:
File_Path = os.path.join(root, name)
 s = File_Path + '/\r'
f.write(s)

f.close()

##
# remove and replace text
# copy result to a new file
##

f1 = open('myfile_01.tmp', 'r')
f2 = open('myfile_02.tmp', 'w')
for line in f1:
f2.write(line.replace('./', 'item id=##-ID-## href='))
f1.close()
f2.close()

##
# Add proper mime-types
# The registry is at http://www.iana.org/assignments/media-types/
##

def replace_words(text, My_Dictionary):
rc = re.compile('|'.join(map(re.escape, My_Dictionary)))
def translate(match):
return My_Dictionary[match.group(0)]
return rc.sub(translate, text)

fin = open('myfile_02.tmp', 'r')
str2 = fin.read()
fin.close()
 
My_Dictionary = {
# text_files
'.html': '.html media-type=application/xhtml+xml',
'.xhtml': '.xhtml media-type=application/xhtml+xml',
'.xml': '.xml media-type=text/xml',
# css files
'.css': '.css media-type=text/css',
# image files
'.gif': '.gif media-type=image/gif',
'.jpg': '.jpg media-type=image/jpeg',
'.jpeg': '.jpeg media-type=image/jpeg',
'.png': '.png media-type=image/png',
'.svg': '.svg media-type=image/svg+xml',
# font files: ttf is not officially supported: woff is!
'.otf': '.otf media-type=application/x-font-otf',
'.woff': '.ttf media-type=application/x-font-woff',
'.ttf': '.ttf media-type=application/x-font-ttf',
# Javascript
'.js': '.js media-type=application/javascript',
# html5 audio and video
'.mp4': '.mp4 media-type=audio/mp4',
'.mp3': '.mp3 media-type=audio/mpeg',
'.m4v': '.m4v media-type=video/mpeg4',
'.webm': '.webm media-type=video/webm',
'.ogg': '.ogg media-type=audio/ogg'
}
 
# call the function and get the changed text
str3 = replace_words(str2, My_Dictionary)
 
# write changed text back out
fout = open('myfile_03.tmp', 'w')
fout.write(str3)
fout.close()

# append the text from the third temp_file to .xml

fin2 = open('myfile_03.tmp', 'r')
str4 = fin2.read()
fin2.close()

fout2 = open('test.xml', 'a')
fout2.write(str4)
fout2.close()

##
# remove the temporary Files
##

filelist = [ f for f in os.listdir('./') if f.endswith('.tmp') ]
for f in filelist:
os.remove(f)

---

-- 
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.
Follow @bbedit on Twitter: http://www.twitter.com/bbedit





Re: Working with ePub: generate .toc and .opf files?

2012-08-17 Thread Maarten Sneep

On 17 aug. 2012, at 15:01, Eelco Deuling deulingee...@gmail.com wrote:

 Sorry: this part I had posted already!
 
 This is the second part:

(I'm not a python code checker ;-)

# make sure you import all at the top of your file
# see PEP8

import os
import re

##
# remove OSX .DS_Store files
##

for root, dirs, files in os.walk(os.path.curdir): # Use the standard library
if '.DS_Store' in files:
os.remove(os.path.join(root, '.DS_Store'))

##
# create a temporary file
# for the directory list
##

#1: Don't mix spaces and tabs, ever in python. It'll make you unhappy.
#2: Again: use standard lib
#3: This is only an intermediate file to list the 'other files' for later 
processing. 
#   Better collect the info in a list, or generate the final format
#4: I wonder if there are too many assumptions here. os.walk returns the 
complete tree
#   starting from root. It appears you only want the files within the current 
dir

filelist = ['item id=##-ID-## href={0}/'.format(f) 
for f in os.listdir(os.path.curdir) 
if os.path.isfile(f)]

str2 = \r.join(filelist)

##
# Add proper mime-types
# The registry is at http://www.iana.org/assignments/media-types/
##

# This is rather dirty hacking. Be sure to document where you found this, or 
else how you came up with it.
# you are using regexes, a dot will match any char. 
# Note that there is a function that just returns the extension of a file in 
os.path. 
# That is probably more robust that re.

def replace_words(text, My_Dictionary):
rc = re.compile('|'.join(map(re.escape, My_Dictionary)))
def translate(match):
return My_Dictionary[match.group(0)]
return rc.sub(translate, text)
 
My_Dictionary = {
# text_files
'.html': '.html media-type=application/xhtml+xml',
'.xhtml': '.xhtml media-type=application/xhtml+xml',
'.xml': '.xml media-type=text/xml',
# css files
'.css': '.css media-type=text/css',
# image files
'.gif': '.gif media-type=image/gif',
'.jpg': '.jpg media-type=image/jpeg',
'.jpeg': '.jpeg media-type=image/jpeg',
'.png': '.png media-type=image/png',
'.svg': '.svg media-type=image/svg+xml',
# font files: ttf is not officially supported: woff is!
'.otf': '.otf media-type=application/x-font-otf',
'.woff': '.ttf media-type=application/x-font-woff',
'.ttf': '.ttf media-type=application/x-font-ttf',
# Javascript
'.js': '.js media-type=application/javascript',
# html5 audio and video
'.mp4': '.mp4 media-type=audio/mp4',
'.mp3': '.mp3 media-type=audio/mpeg',
'.m4v': '.m4v media-type=video/mpeg4',
'.webm': '.webm media-type=video/webm',
'.ogg': '.ogg media-type=audio/ogg'
}
 
# call the function and get the changed text
str3 = replace_words(str2, My_Dictionary)

# after all this, str4 is exactly the same as str3, isn't it?

# write changed text back out
#fout = open('myfile_03.tmp', 'w')
#fout.write(str3)
#fout.close()

# append the text from the third temp_file to .xml

#fin2 = open('myfile_03.tmp', 'r')
#str4 = fin2.read()
#fin2.close()

fout2 = open('test.xml', 'a')
fout2.write(str3)
fout2.close()

##
# remove the temporary Files
##

[os.remove(f) for f in os.listdir(os.path.curdir) if f.endswith('.tmp') ]

-- 
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.
Follow @bbedit on Twitter: http://www.twitter.com/bbedit





Re: Working with ePub: generate .toc and .opf files?

2012-08-17 Thread Eelco Deuling
Hello Maarten,

…maybe you are not a Python code checker but I do appreciate your help.
(hell… I am not a programmer and decided during my first and only lesson of 
Pascal that I would never get it- 20 years ago).

Thank you for your patience :-)

-- 
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.
Follow @bbedit on Twitter: http://www.twitter.com/bbedit





Re: Working with ePub: generate .toc and .opf files?

2012-08-10 Thread Eelco Deuling
Hello Wats Martin,

I am sorry if I did sound offensive: that was not my intention. I more or 
less understand what Bookbind tries to do but for me it won't work, 
because Markdown has not enough support for classes, id's etc.

I usually start with a InDesign document (a completed book for print) 
where I use grep to place Markdown tags. I copy/paste the text in BBEdit, 
convert Markdown to HTML and divide the document into chapters. I could do 
this with your program, and for a textbook this would be enough.
After this I start to expand the markup using classes, especially for the 
different kind of images (with text-wrap, as page-sized, etc). If I am 
happy with the result I can pack it as an epub, where I look at this part 
of the process as the last part: like generating the PDF-X1 flattened file 
print houses in the Netherlands demand.

So: I want to be able to make HTML/CSS *before* the generation of the epub, 
in your solution it is generated *during* the process.

-- 
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.
Follow @bbedit on Twitter: http://www.twitter.com/bbedit





Re: Working with ePub: generate .toc and .opf files?

2012-08-10 Thread Watts Martin
Don't worry, I'm not offended. You mostly just made me realize that even 
if Bookbind is mostly done, it needs a lot of documentation work still. :)


But, your workflow sounds *close* to that of the book I wrote Bookbind 
to create, with the exception of the images, as I didn't have any of 
those. My chapters were in Markdown but the front matter was in straight 
HTML, and I wrote my own CSS. Bookbind doesn't generate any CSS at all; 
it just includes the files you point it to. The only files it generates 
are the EPUB-specific ones, and of course HTML files produced by 
processing with Markdown -- but it can include HTML files directly 
without processing them. (And, of course, Markdown can include embedded 
HTML. In my book I occasionally included span class=smallcapsSmall 
Caps/span for certain passages, and that works just fine.)


I don't want to advertise Bookbind, but if nothing else, you might 
want to see if there are bits of code you want to use, since it looked 
like you were also writing in Python.



Eelco Deuling mailto:deulingee...@gmail.com
August 9, 2012 23:01
Hello Wats Martin,

I am sorry if I did sound offensive: that was not my intention. I 
more or less understand what Bookbind tries to do but for me it 
won't work, because Markdown has not enough support for classes, id's etc.


I usually start with a InDesign document (a completed book for 
print) where I use grep to place Markdown tags. I copy/paste the text 
in BBEdit, convert Markdown to HTML and divide the document into 
chapters. I could do this with your program, and for a textbook this 
would be enough.
After this I start to expand the markup using classes, especially for 
the different kind of images (with text-wrap, as page-sized, etc). If 
I am happy with the result I can pack it as an epub, where I look at 
this part of the process as the last part: like generating the PDF-X1 
flattened file print houses in the Netherlands demand.


So: I want to be able to make HTML/CSS *before* the generation of the 
epub, in your solution it is generated *during* the process.

--
--
You received this message because you are subscribed to the
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem,
please email supp...@barebones.com rather than posting to the group.
Follow @bbedit on Twitter: http://www.twitter.com/bbedit



Watts Martin mailto:lay...@gmail.com
August 9, 2012 9:33
I'll express a *mild* objection here. :) Bookbind is designed to let 
you use your own stylesheet for a book and even to override individual 
pages if necessary. While the main reason I wrote it is because I 
write prose in Markdown these days, being able to do custom styling 
was pretty important to me; I was a professional typesetter many years 
ago and have done magazine and book design in the past.


Clearly I'm going to have to start writing actual documentation 
sometime soon...


At any rate, I know that Pandoc can also let you include a stylesheet, 
although IIRC it's not as flexible. (But it may -- ahem -- have better 
documentation.)

Eelco Deuling mailto:deulingee...@gmail.com
August 9, 2012 1:29
Hello Maarten,

Thank you for cleaning up my script, and thank you for pointing out 
to http://code.google.com/p/python-epub-builder/ 
http://code.google.com/p/python-epub-builder/.


I did find this myself before, but I staggered mentally when I read 
the introduction in the Wiki to create a epub in five minutes, as I 
hardly understand a word in it (and this is just using the simple API).


The problem is I cannot find a solution that does /just/ what I want 
it to do and /nothing more/. I have tried all the WYSIWYG epub editors 
and generators, and they all fail me some way or another: they mess up 
my CSS, refuse to work with my media or generate a non valid epub.


Most solutions posted here (like the python-epub-builder, Bookbind by 
Watts Martin, etc.) are good to generate epub's from text documents, 
converting those on-the-fly from Markdown or a similar markup 
language. Unfortunately they will not work for me, as they tend to use 
more or less /generic/ CSS and not the /custom/ HTML and CSS I want to 
use (as a designer I want to make not only readable books but they 
should look great as well and every book should have it's own CSS).


With regards,

Eelco
--
--
You received this message because you are subscribed to the
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem,
please email 

Re: Working with ePub: generate .toc and .opf files?

2012-08-10 Thread Eelco Deuling
I am glad you are not offended, and maybe your solution is indeed what I 
need… But I agree you should add some documentation, as I cannot get it to 
work.
Like I said: I am new to Python, and the solution I work on is my first 
effort. I did use parts of Bookbind to write it :-) and I am the first to 
agree I am not good in programming.
I will try again to get Bookbind working.

Op vrijdag 10 augustus 2012 08:11:49 UTC+2 schreef Watts Martin het 
volgende:

 Don't worry, I'm not offended. You mostly just made me realize that even 
 if Bookbind is mostly done, it needs a lot of documentation work still. :)

 But, your workflow sounds *close* to that of the book I wrote Bookbind to 
 create, with the exception of the images, as I didn't have any of those. My 
 chapters were in Markdown but the front matter was in straight HTML, and I 
 wrote my own CSS. Bookbind doesn't generate any CSS at all; it just 
 includes the files you point it to. The only files it generates are the 
 EPUB-specific ones, and of course HTML files produced by processing with 
 Markdown -- but it can include HTML files directly without processing them. 
 (And, of course, Markdown can include embedded HTML. In my book I 
 occasionally included span class=smallcapsSmall Caps/span for certain 
 passages, and that works just fine.)

 I don't want to advertise Bookbind, but if nothing else, you might want 
 to see if there are bits of code you want to use, since it looked like you 
 were also writing in Python.

   Eelco Deuling javascript:
  August 9, 2012 23:01 
 Hello Wats Martin,

 I am sorry if I did sound offensive: that was not my intention. I more or 
 less understand what Bookbind tries to do but for me it won't work, 
 because Markdown has not enough support for classes, id's etc.

 I usually start with a InDesign document (a completed book for print) 
 where I use grep to place Markdown tags. I copy/paste the text in BBEdit, 
 convert Markdown to HTML and divide the document into chapters. I could do 
 this with your program, and for a textbook this would be enough.
 After this I start to expand the markup using classes, especially for the 
 different kind of images (with text-wrap, as page-sized, etc). If I am 
 happy with the result I can pack it as an epub, where I look at this part 
 of the process as the last part: like generating the PDF-X1 flattened file 
 print houses in the Netherlands demand.

 So: I want to be able to make HTML/CSS *before* the generation of the 
 epub, in your solution it is generated *during* the process.
 -- 
 -- 
 You received this message because you are subscribed to the 
 BBEdit Talk discussion group on Google Groups.
 To post to this group, send email to bbe...@googlegroups.com javascript:
 To unsubscribe from this group, send email to
 bbedit+un...@googlegroups.com javascript:
 For more options, visit this group at
 http://groups.google.com/group/bbedit?hl=en
 If you have a feature request or would like to report a problem, 
 please email sup...@barebones.com javascript: rather than posting to 
 the group.
 Follow @bbedit on Twitter: http://www.twitter.com/bbedit
  
  
  
   Watts Martin javascript:
  August 9, 2012 9:33 
  I'll express a *mild* objection here. :) Bookbind is designed to let you 
 use your own stylesheet for a book and even to override individual pages if 
 necessary. While the main reason I wrote it is because I write prose in 
 Markdown these days, being able to do custom styling was pretty important 
 to me; I was a professional typesetter many years ago and have done 
 magazine and book design in the past.

 Clearly I'm going to have to start writing actual documentation sometime 
 soon...

 At any rate, I know that Pandoc can also let you include a stylesheet, 
 although IIRC it's not as flexible. (But it may -- ahem -- have better 
 documentation.)
   Eelco Deuling javascript:
  August 9, 2012 1:29 
 Hello Maarten,

 Thank you for cleaning up my script, and thank you for pointing out to 
 http://code.google.com/p/python-epub-builder/.

 I did find this myself before, but I staggered mentally when I read the 
 introduction in the Wiki to create a epub in five minutes, as I hardly 
 understand a word in it (and this is just using the simple API).

 The problem is I cannot find a solution that does *just* what I want it 
 to do and *nothing more*. I have tried all the WYSIWYG epub editors and 
 generators, and they all fail me some way or another: they mess up my CSS, 
 refuse to work with my media or generate a non valid epub.

 Most solutions posted here (like the python-epub-builder, Bookbind by 
 Watts Martin, etc.) are good to generate epub's from text documents, 
 converting those on-the-fly from Markdown or a similar markup language. 
 Unfortunately they will not work for me, as they tend to use more or less 
 *generic* CSS and not the *custom* HTML and CSS I want to use (as a 
 designer I want to make not only readable books but they should look great 
 as well 

Re: Working with ePub: generate .toc and .opf files?

2012-08-09 Thread Eelco Deuling
Hello Maarten,

Thank you for cleaning up my script, and thank you for pointing out to 
http://code.google.com/p/python-epub-builder/.

I did find this myself before, but I staggered mentally when I read the 
introduction in the Wiki to create a epub in five minutes, as I hardly 
understand a word in it (and this is just using the simple API).

The problem is I cannot find a solution that does *just* what I want it to 
do and *nothing more*. I have tried all the WYSIWYG epub editors and 
generators, and they all fail me some way or another: they mess up my CSS, 
refuse to work with my media or generate a non valid epub.

Most solutions posted here (like the python-epub-builder, Bookbind by Watts 
Martin, etc.) are good to generate epub's from text documents, converting 
those on-the-fly from Markdown or a similar markup language. Unfortunately 
they will not work for me, as they tend to use more or less *generic* CSS 
and not the *custom* HTML and CSS I want to use (as a designer I want to 
make not only readable books but they should look great as well and every 
book should have it's own CSS).

With regards,

Eelco

-- 
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.
Follow @bbedit on Twitter: http://www.twitter.com/bbedit





Re: Working with ePub: generate .toc and .opf files?

2012-08-09 Thread Watts Martin
I'll express a *mild* objection here. :) Bookbind is designed to let you 
use your own stylesheet for a book and even to override individual pages 
if necessary. While the main reason I wrote it is because I write prose 
in Markdown these days, being able to do custom styling was pretty 
important to me; I was a professional typesetter many years ago and have 
done magazine and book design in the past.


Clearly I'm going to have to start writing actual documentation sometime 
soon...


At any rate, I know that Pandoc can also let you include a stylesheet, 
although IIRC it's not as flexible. (But it may -- ahem -- have better 
documentation.)

Eelco Deuling mailto:deulingee...@gmail.com
August 9, 2012 1:29
Hello Maarten,

Thank you for cleaning up my script, and thank you for pointing out 
to http://code.google.com/p/python-epub-builder/ 
http://code.google.com/p/python-epub-builder/.


I did find this myself before, but I staggered mentally when I read 
the introduction in the Wiki to create a epub in five minutes, as I 
hardly understand a word in it (and this is just using the simple API).


The problem is I cannot find a solution that does /just/ what I want 
it to do and /nothing more/. I have tried all the WYSIWYG epub editors 
and generators, and they all fail me some way or another: they mess up 
my CSS, refuse to work with my media or generate a non valid epub.


Most solutions posted here (like the python-epub-builder, Bookbind by 
Watts Martin, etc.) are good to generate epub's from text documents, 
converting those on-the-fly from Markdown or a similar markup 
language. Unfortunately they will not work for me, as they tend to use 
more or less /generic/ CSS and not the /custom/ HTML and CSS I want to 
use (as a designer I want to make not only readable books but they 
should look great as well and every book should have it's own CSS).


With regards,

Eelco
--
--
You received this message because you are subscribed to the
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem,
please email supp...@barebones.com rather than posting to the group.
Follow @bbedit on Twitter: http://www.twitter.com/bbedit



Maarten Sneep mailto:maarten.sn...@xs4all.nl
August 8, 2012 12:31
Hi,

On 8 aug. 2012, at 14:03, Eelco Deulingdeulingee...@gmail.com  wrote:


I have finished part one: make a directory structure and all the necessary 
files for an epub.
As this is my first-ever python script there should be some things wrong, but 
it works:


Let me help you out. The script is not too shabby, but could use some cleanup.


#!/usr/bin/env python
#  This uses the system python. Slightly more flexible.


# call the operating system (?)
#  Load the 'os' module in python.
#  This contains a lot of functionality for interaction with the os

import os


# create the directory structure

My_Epub = epub
if not os.path.exists(My_Epub):
 os.mkdir(My_Epub)

root_path = ./epub/
folders = [META-INF, OEBPS, OEBPS/texts, OEBPS/css, OEBPS/media, 
OEBPS/fonts]
for folder in folders:
os.mkdir(os.path.join(root_path,folder))


# create the mimetype file
#  Use os.path.join() here too
#  Your version didn't close the file (explicitly).
#  It was implicitly closed on script-end.

with open(os.path.join(My_Epub, mimetype), w) as fp:
 fp.write(application/epub+zip)


# create the container xml file

My_Container_xml = ?xml version=1.0 ?
container version=1.0 
xmlns=urn:oasis:names:tc:opendocument:xmlns:container
rootfiles
rootfile full-path=OEBPS/content.opf media-type=application/oebps-package+xml 
/
/rootfiles
/container


with open(os.path.join(My_Epub, META-INF, container.xml),w) as fp:
 fp.write(My_Container_xml)


# create empty toc.ncx and empty content.opf

with open(os.path.join(My_Epub, OEBPS, toc.ncx), w) as fp:
 fp.write()
with open(os.path.join(My_Epub, OEBPS, content.opf), w) as fp:
 fp.write()



This gives me the chance to copy all html files, my css, images, fonts and 
movie files to the right directories.
Now I will have to fill the empty toc.ncx 

Re: Working with ePub: generate .toc and .opf files?

2012-08-08 Thread Eelco Deuling
Hello,

I have finished part one: make a directory structure and all the 
necessary files for an epub.
As this is my first-ever python script there should be some things wrong, 
but it works:


#!/usr/bin/python

# call the operating system (?)

import os

# create the directory structure

My_Epub = epub
if not os.path.isdir(./ + My_Epub + /):
os.mkdir(./ + My_Epub + /)

root_path = ./epub/
folders = [META-INF, OEBPS, OEBPS/texts, OEBPS/css, OEBPS/media, 
OEBPS/fonts]
for folder in folders:
os.mkdir(os.path.join(root_path,folder))

# create the mimetype file

open(My_Epub + /mimetype, w).write(application/epub+zip)

# create the container xml file

My_Container_xml = ?xml version=1.0 ?
container version=1.0 
xmlns=urn:oasis:names:tc:opendocument:xmlns:container
rootfiles
rootfile full-path=OEBPS/content.opf 
media-type=application/oebps-package+xml /
/rootfiles
/container


open(My_Epub + /META-INF/container.xml,w).write(My_Container_xml)

# create empty toc.ncx and empty content.opf

open(My_Epub + /OEBPS/toc.ncx, w).write()
open(My_Epub + /OEBPS/content.opf, w).write()


This gives me the chance to copy all html files, my css, images, fonts and 
movie files to the right directories.
Now I will have to fill the empty toc.ncx and content.opf files with the 
right content: maybe with os.listdir…

This will be continued (hopefully!).
All help would be welcome!

-- 
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.
Follow @bbedit on Twitter: http://www.twitter.com/bbedit





Re: Working with ePub: generate .toc and .opf files?

2012-08-08 Thread Maarten Sneep
Hi,

On 8 aug. 2012, at 14:03, Eelco Deuling deulingee...@gmail.com wrote:

 I have finished part one: make a directory structure and all the necessary 
 files for an epub.
 As this is my first-ever python script there should be some things wrong, but 
 it works:

Let me help you out. The script is not too shabby, but could use some cleanup.


#!/usr/bin/env python
# This uses the system python. Slightly more flexible.


# call the operating system (?)
# Load the 'os' module in python. 
# This contains a lot of functionality for interaction with the os

import os


# create the directory structure

My_Epub = epub
if not os.path.exists(My_Epub):
os.mkdir(My_Epub)

root_path = ./epub/
folders = [META-INF, OEBPS, OEBPS/texts, OEBPS/css, OEBPS/media, 
OEBPS/fonts]
for folder in folders:
   os.mkdir(os.path.join(root_path,folder))


# create the mimetype file
# Use os.path.join() here too
# Your version didn't close the file (explicitly). 
# It was implicitly closed on script-end.

with open(os.path.join(My_Epub, mimetype), w) as fp:
fp.write(application/epub+zip)


# create the container xml file

My_Container_xml = ?xml version=1.0 ?
container version=1.0 
xmlns=urn:oasis:names:tc:opendocument:xmlns:container
rootfiles
rootfile full-path=OEBPS/content.opf 
media-type=application/oebps-package+xml /
/rootfiles
/container


with open(os.path.join(My_Epub, META-INF, container.xml),w) as fp:
fp.write(My_Container_xml)


# create empty toc.ncx and empty content.opf

with open(os.path.join(My_Epub, OEBPS, toc.ncx), w) as fp:
fp.write()
with open(os.path.join(My_Epub, OEBPS, content.opf), w) as fp:
fp.write()


 This gives me the chance to copy all html files, my css, images, fonts and 
 movie files to the right directories.
 Now I will have to fill the empty toc.ncx and content.opf files with the 
 right content: maybe with os.listdir…
 
 This will be continued (hopefully!).
 All help would be welcome!

There is an epub python package. No need to reinvent the wheel. 
http://code.google.com/p/python-epub-builder/
(I've never used this code, no idea how good this is).

Best,

Maarten

-- 
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.
Follow @bbedit on Twitter: http://www.twitter.com/bbedit





Re: Working with ePub: generate .toc and .opf files?

2012-08-06 Thread Eelco Deuling

Thank you Watts Martin and Charlie Garrison, the solutions do more than I 
want, but that does not mean I am not happy with them. I think I have 
enough hooks to copy and paste my own solution together. If it works I 
will post an update: will take some time though!

Op zaterdag 4 augustus 2012 11:32:55 UTC+2 schreef Eelco Deuling het 
volgende:

 I use BBEdit to prepare my ePubs and used eCub to generate the .toc and 
 .opf files.
 However, eCub starts to show it's age: I could not include video and audio 
 files so I switched to Sigil.
 I dislike Sigil because I have to use the naming convention of this 
 program and it is sometimes very slow with large ePub files, because every 
 time you save a project it has to repack the ePub.

 I was wondering if there is a way to generate the .toc and .opf files with 
 BBEdit: I think this could be done with a shell script or a regex text 
 factory that wraps a list (based on file extensions or tags) but I do not 
 know enough to make it work. Is there someone that could help me with 
 this? It would be great if I could use only BBEdit.


-- 
-- 
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.
Follow @bbedit on Twitter: http://www.twitter.com/bbedit





Re: Working with ePub: generate .toc and .opf files?

2012-08-05 Thread Charlie Garrison

Good morning,

On 4/08/12 at 2:32 AM -0700, Eelco Deuling 
deulingee...@gmail.com wrote:


I was wondering if there is a way to generate the .toc and .opf 
files with BBEdit: I think this could be done with a shell 
script or a regex text factory that wraps a list (based on file 
extensions or tags) but I do not know enough to make it work. 
Is there someone that could help me with this? It would be 
great if I could use only BBEdit.


One of the best things about BBEdit is the way it leverages 
scripting languages. And Perl is great at things like this due 
to the CPAN; which has things like EBook::Tools:


  https://metacpan.org/module/EBook::Tools

Use that to make a 'unix script' in BBEdit which creates the 
files for you. I can supply an example perl script (use as 
template for unix script) but I don't know enough about epubs to 
help with that part.



Charlie

--
   Ꮚ Charlie Garrison ♊ garri...@zeta.org.au

O ascii ribbon campaign - stop html mail - www.asciiribbon.org
〠  http://www.ietf.org/rfc/rfc1855.txt

--
--
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.

To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.

Follow @bbedit on Twitter: http://www.twitter.com/bbedit





Re: Working with ePub: generate .toc and .opf files?

2012-08-04 Thread Watts Martin
I haven't tried to integrate this directly into BBEdit, but you could 
try looking at Pandoc or Bookbind, which are both command-line utilities 
for generating EPUB books. Bookbind (which is my own tool) is really 
designed to process Markdown documents but can handle pre-made XHTML 
instead; Pandoc can theoretically use HTML, Markdown, rST, Textile, 
DocBook and LaTeX input files.


[bookbind]: https://github.com/chipotle/bookbind
[pandoc]: http://johnmacfarlane.net/pandoc/


Eelco Deuling mailto:deulingee...@gmail.com
August 4, 2012 2:32
I use BBEdit to prepare my ePubs and used eCub to generate the .toc 
and .opf files.
However, eCub starts to show it's age: I could not include video and 
audio files so I switched to Sigil.
I dislike Sigil because I have to use the naming convention of this 
program and it is sometimes very slow with large ePub files, because 
every time you save a project it has to repack the ePub.


I was wondering if there is a way to generate the .toc and .opf files 
with BBEdit: I think this could be done with a shell script or a regex 
text factory that wraps a list (based on file extensions or tags) but 
I do not know enough to make it work. Is there someone that could help 
me with this? It would be great if I could use only BBEdit.

--
--
You received this message because you are subscribed to the
BBEdit Talk discussion group on Google Groups.
To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem,
please email supp...@barebones.com rather than posting to the group.
Follow @bbedit on Twitter: http://www.twitter.com/bbedit





--
--
You received this message because you are subscribed to the 
BBEdit Talk discussion group on Google Groups.

To post to this group, send email to bbedit@googlegroups.com
To unsubscribe from this group, send email to
bbedit+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/bbedit?hl=en
If you have a feature request or would like to report a problem, 
please email supp...@barebones.com rather than posting to the group.

Follow @bbedit on Twitter: http://www.twitter.com/bbedit