mirror of
https://github.com/gryf/ebook-converter.git
synced 2026-02-13 12:25:56 +01:00
27 lines
535 B
Python
27 lines
535 B
Python
import os
|
|
import re
|
|
|
|
from functools import partial
|
|
|
|
from ebook_converter import constants_old
|
|
from ebook_converter.utils import entities
|
|
|
|
|
|
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
|