mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-03-17 23:33:43 +01:00
Cleaned up __init__.py for main module
This commit is contained in:
20
ebook_converter/utils/directory.py
Normal file
20
ebook_converter/utils/directory.py
Normal file
@@ -0,0 +1,20 @@
|
||||
import os
|
||||
|
||||
|
||||
class CurrentDir(object):
|
||||
|
||||
def __init__(self, path):
|
||||
self.path = path
|
||||
self.cwd = None
|
||||
|
||||
def __enter__(self, *args):
|
||||
self.cwd = os.getcwd()
|
||||
os.chdir(self.path)
|
||||
return self.cwd
|
||||
|
||||
def __exit__(self, *args):
|
||||
try:
|
||||
os.chdir(self.cwd)
|
||||
except EnvironmentError:
|
||||
# The previous CWD no longer exists
|
||||
pass
|
||||
@@ -15,8 +15,9 @@ from threading import Thread
|
||||
from ebook_converter.constants_old import plugins
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter.utils.config_base import tweaks
|
||||
from ebook_converter.utils.filenames import atomic_rename
|
||||
from ebook_converter.utils import directory
|
||||
from ebook_converter.utils import encoding as uenc
|
||||
from ebook_converter.utils.filenames import atomic_rename
|
||||
from ebook_converter.utils.imghdr import what
|
||||
|
||||
# Utilities {{{
|
||||
@@ -646,11 +647,10 @@ def encode_jpeg(file_path, quality=80):
|
||||
def test(): # {{{
|
||||
# TODO(gryf): move this test to separate file.
|
||||
from ebook_converter.ptempfile import TemporaryDirectory
|
||||
from ebook_converter import CurrentDir
|
||||
from glob import glob
|
||||
# TODO(gryf): make the sample image out of pillow or smth
|
||||
# img = image_from_data(I('lt.png', data=True, allow_user_override=False))
|
||||
with TemporaryDirectory() as tdir, CurrentDir(tdir):
|
||||
with TemporaryDirectory() as tdir, directory.CurrentDir(tdir):
|
||||
save_image(img, 'test.jpg')
|
||||
ret = optimize_jpeg('test.jpg')
|
||||
if ret is not None:
|
||||
|
||||
Reference in New Issue
Block a user