Register Guidelines E-Books Search Today's Posts Mark Forums Read

Go Back   MobileRead Forums > E-Book Software > Calibre > Development

Notices

Reply
 
Thread Tools Search this Thread
Old 10-15-2016, 02:32 AM   #1
duxxil
Junior Member
duxxil began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Oct 2016
Device: none
Cool How to update one .pyo file in pylib.zip?

I've made a little patch for calibre, importing book using hardlink instead of copy.

After runnig calibre with my source code by setting CALIBRE_DEVELOP_FROM, I got the .pyo file.
I want to use this .pyo file to update the pylib.zip in the calibre binary directory.

I've tried WinRAR and the zip in Ubuntu, but it can not run well. And also tried the setup.py script in the calibre sources, but stopped at the private QT header problems.

Does anyone know how to repack the .zip file?
I would be very grateful if anyone give me some advice.

Or if you have a good calibre develop environment, just apply my patch and build the zip for me.

Code:
     
    import book using hardlink instead of copy

diff --git a/src/calibre/db/backend.py b/src/calibre/db/backend.py
index 357f690..463f690 100644
--- a/src/calibre/db/backend.py
+++ b/src/calibre/db/backend.py
@@ -1493,11 +1493,9 @@ class DB(object):
                         traceback.print_exc()
 
         if (not getattr(stream, 'name', False) or not samefile(dest, stream.name)):
-            with lopen(dest, 'wb') as f:
-                shutil.copyfileobj(stream, f)
-                size = f.tell()
-            if mtime is not None:
-                os.utime(dest, (mtime, mtime))
+            hardlink_file(stream.name, dest)
+            stream.seek(0, os.SEEK_END)
+            size = stream.tell()
         elif os.path.exists(dest):
             size = os.path.getsize(dest)
             if mtime is not None:
Someone had already talked about a similar question.
Make calibre installer for Window

Last edited by duxxil; 10-15-2016 at 02:36 AM.
duxxil is offline   Reply With Quote
Advert
Old 10-15-2016, 03:38 AM   #2
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 31,726
Karma: 8696042
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
Just unzip, replace the file, and re-zip, making sure to disable compression when zipping.
kovidgoyal is offline   Reply With Quote
Old 10-15-2016, 07:15 AM   #3
duxxil
Junior Member
duxxil began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Oct 2016
Device: none
Red face Thants for your replay. I've tried, but might not in the right way.

Quote:
Originally Posted by kovidgoyal View Post
Just unzip, replace the file, and re-zip, making sure to disable compression when zipping.

Thants for your replay.

I've tried, but might not in the right way, it cannot run the right way like using source code by setting CALIBRE_DEVELOP_FROM.

1. I use WinRAR directly replace the .pyo in the pylib.zip(just drag the .pyo into pylib.zip's "calibre/db/" subdirectory).
Code:
 --- the orginal pylib.zip
$ unzip -Z ../pylib.zip  | grep backend -B3
?rw-------  2.0 fat    17915 b- stor 16-Sep-30 08:46 calibre/customize/__init__.pyo
-rw----     2.0 fat        0 b- stor 16-Sep-30 08:46 calibre/db
?rw-------  2.0 fat     9008 b- stor 16-Sep-30 08:46 calibre/db/adding.pyo
?rw-------  2.0 fat    65606 b- stor 16-Sep-30 08:46 calibre/db/backend.pyo

--- pylib.zip after replacing calibre/db/backend.pyo
$ unzip -Z ../pylib-h.zip  | grep backend -B3
?rw-------  2.0 fat    17915 b- stor 16-Sep-30 08:46 calibre/customize/__init__.pyo
-rw----     2.0 fat        0 b- stor 16-Sep-30 08:46 calibre/db
?rw-------  2.0 fat     9008 b- stor 16-Sep-30 08:46 calibre/db/adding.pyo
-rw-a--     3.1 fat    70781 bx stor 16-Oct-13 23:06 calibre/db/backend.pyo

2. Directory structure problem like this cause the pylib.zip cannot extract the path, so I build the directory structure manually before unzip pylib.zip.
This is the detail steps history:
Code:
 $  mkdir pylib && cd pylib
 $  unzip ../*.zip
 $  unzip -l ../*.zip
 $  unzip -l ../pylib.zip | grep -E "[0-9]{4}(-[0-9]{2}){2} [0-9]{2}:[0-9]{2}"  |  sed -e '/\.py/d' -e 's/^[ 0-9:\-]* \(.*\)$/\1/' | xargs mkdir
 $  unzip ../pylib.zip 
 $  cp ../backend.pyo calibre/db/backend.pyo -f
 $  zip -r ../pylib-hardlink.zip . -0

$ unzip -Z pylib-hardlink.zip | grep backend -B3
-rw-------  3.0 unx    11359 bx stor 16-Sep-30 08:46 calibre/db/restore.pyo
-rw-------  3.0 unx    15612 bx stor 16-Sep-30 08:46 calibre/db/utils.pyo
-rw-------  3.0 unx    19342 bx stor 16-Sep-30 08:46 calibre/db/view.pyo
-rw-------  3.0 unx    70781 bx stor 16-Oct-13 23:06 calibre/db/backend.pyo
duxxil is offline   Reply With Quote
Old 10-15-2016, 08:10 AM   #4
kovidgoyal
creator of calibre
kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.kovidgoyal ought to be getting tired of karma fortunes by now.
 
kovidgoyal's Avatar
 
Posts: 31,726
Karma: 8696042
Join Date: Oct 2006
Location: Mumbai, India
Device: Various
I'n afraid I dont have the time to figure out how to use zip tools to replace files in a zip file for you. Just use CALIBRE_DEVELOP_FROM.
kovidgoyal is offline   Reply With Quote
Old 10-15-2016, 10:27 AM   #5
duxxil
Junior Member
duxxil began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Oct 2016
Device: none
I just wanna use hardlink to save my disk space

Quote:
Originally Posted by kovidgoyal View Post
I'n afraid I dont have the time to figure out how to use zip tools to replace files in a zip file for you. Just use CALIBRE_DEVELOP_FROM.
I'm not interested in the zip tools at all, I just wanna use hardlink to save my disk space as many people trying doing this. If you google calibre symlink or hardlink, you'll see.

I suggest to add some opinions about how to setup the book library to the calibre UI, copy, symlink, hardlink or just record the original book path to the book entry.
duxxil is offline   Reply With Quote
Advert
Old 10-15-2016, 09:59 PM   #6
davidfor
Grand Sorcerer
davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.davidfor ought to be getting tired of karma fortunes by now.
 
Posts: 13,292
Karma: 21339656
Join Date: Jul 2011
Location: Sydney, Australia
Device: Kobo: Touch, Glo, Aura H2O, Glo HD, Aura ONE
Quote:
Originally Posted by duxxil View Post
I'm not interested in the zip tools at all, I just wanna use hardlink to save my disk space as many people trying doing this. If you google calibre symlink or hardlink, you'll see.
I'm pretty sure Kovid was saying he didn't have time to teach you how to use your zip tools to produce the pyo file.
Quote:
I suggest to add some opinions about how to setup the book library to the calibre UI, copy, symlink, hardlink or just record the original book path to the book entry.
I can't say there has been much discussion about using links for access to the books, but there has been a lot of discussion about storing the original file name. And there is even a plugin intended for just that purpose.
davidfor is offline   Reply With Quote
Old 10-16-2016, 01:08 AM   #7
duxxil
Junior Member
duxxil began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Oct 2016
Device: none
Quote:
Originally Posted by davidfor View Post
I'm pretty sure Kovid was saying he didn't have time to teach you how to use your zip tools to produce the pyo file.

I can see it. I just state my intention and suggestion. As my first post says, there're many ways that may figure out my problem.
duxxil is offline   Reply With Quote
Old 10-16-2016, 03:50 AM   #8
duxxil
Junior Member
duxxil began at the beginning.
 
Posts: 5
Karma: 10
Join Date: Oct 2016
Device: none
Quote:
Originally Posted by duxxil View Post
After runnig calibre with my source code by setting CALIBRE_DEVELOP_FROM, I got the .pyo file.
I made a mistake here, the .pyo file is not synchronized with the .py
duxxil is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Invalid Zip file?? Joop Library Management 1 02-12-2015 09:58 PM
ZIP file problem BlackJapan Conversion 6 09-19-2014 05:04 AM
pylib.zip and zipfile.py twobits Calibre 4 02-21-2013 03:05 AM
Cannot Read .htm file auto-imported as zip file Jimbo724 Conversion 2 07-24-2012 07:08 AM
Where is the .exe file in the zip Calibre2opds file? chilady1 Related Tools 4 09-17-2011 12:56 PM


All times are GMT -4. The time now is 05:57 PM.


MobileRead.com is a privately owned, operated and funded community.