Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 11 additions & 8 deletions keepercommander/importer/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -400,15 +400,18 @@ def __init__(self):

def execute(self, name, **kwargs):
# type: (str, ...) -> Iterable[Union[Record, SharedFolder, File]]
try:
json.loads(name)
path = name
except ValueError as e:
path = os.path.expanduser(name)
if not os.path.isfile(path):
ext = self.extension()
if ext:
path = path + '.' + ext

path = os.path.expanduser(name)
if not os.path.isfile(path):
ext = self.extension()
if ext:
path = path + '.' + ext

if not os.path.isfile(path):
raise CommandError('import', f'File \'{name}\' does not exist')
if not os.path.isfile(path):
raise CommandError('import', f'File \'{name}\' does not exist')

yield from self.do_import(path, **kwargs)

Expand Down
33 changes: 20 additions & 13 deletions keepercommander/importer/json/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -162,19 +162,26 @@ def prepare(self):
class KeeperJsonImporter(BaseFileImporter, KeeperJsonMixin):
def do_import(self, filename, **kwargs):
users_only = kwargs.get('users_only') or False
if not os.path.isfile(filename):
zip_name = pathlib.Path(filename).with_suffix('.zip').name
if os.path.isfile(zip_name):
if zipfile.is_zipfile(zip_name):
filename = zip_name
file_path = pathlib.Path(filename)
zip_archive = file_path.suffix == '.zip'
if zip_archive:
with zipfile.ZipFile(filename, 'r') as zf:
export = json.loads(zf.read('export.json'))
else:
with open(filename, "r", encoding='utf-8') as jf:
export = json.load(jf)
try:
export = json.loads(filename)
zip_archive = False
logging.info("Extracted JSON from object")
except ValueError as e:
if not os.path.isfile(filename):
zip_name = pathlib.Path(filename).with_suffix('.zip').name
if os.path.isfile(zip_name):
if zipfile.is_zipfile(zip_name):
filename = zip_name
file_path = pathlib.Path(filename)
zip_archive = file_path.suffix == '.zip'
if zip_archive:
with zipfile.ZipFile(filename, 'r') as zf:
export = json.loads(zf.read('export.json'))
logging.info("Extracted JSON from archive")
else:
with open(filename, "r", encoding='utf-8') as jf:
export = json.load(jf)
logging.info("Extracted JSON from file")

records = None
folders = None
Expand Down
Loading