fix import_from_path, add bytes mode to Path.read, and add clear_table to database.session
This commit is contained in:
parent
2bc9fd9745
commit
65a513916b
|
@ -163,8 +163,8 @@ def import_from_path(mod_path):
|
||||||
|
|
||||||
mod_path = Path(mod_path)
|
mod_path = Path(mod_path)
|
||||||
|
|
||||||
if mod_path.isdir:
|
if mod_path.is_dir():
|
||||||
path = mod_path.join('__init__.py')
|
path = mod_path.joinpath('__init__.py')
|
||||||
name = path.name
|
name = path.name
|
||||||
|
|
||||||
else:
|
else:
|
||||||
|
|
|
@ -119,9 +119,9 @@ class Path(str):
|
||||||
return open(self, *args, **kwargs)
|
return open(self, *args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
def read(self):
|
def read(self, byte=False):
|
||||||
fd = open(self)
|
fd = open(self)
|
||||||
data = fd.read()
|
data = fd.read('rb' if byte else 'r')
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
return data
|
return data
|
||||||
|
|
|
@ -323,6 +323,10 @@ class SqlSession(object):
|
||||||
self.execute(f'ALTER TABLE {tbl}_temp RENAME TO {tbl}')
|
self.execute(f'ALTER TABLE {tbl}_temp RENAME TO {tbl}')
|
||||||
|
|
||||||
|
|
||||||
|
def clear_table(self, table):
|
||||||
|
self.execute(f'DELETE FROM {table}')
|
||||||
|
|
||||||
|
|
||||||
class CustomRows(object):
|
class CustomRows(object):
|
||||||
def get(self, name):
|
def get(self, name):
|
||||||
return getattr(self, name, self.Row)
|
return getattr(self, name, self.Row)
|
||||||
|
|
Loading…
Reference in a new issue