refactor: use file api to read import data (#18379) (#18382)

* refactor: use file api for reading data in import

* fix: remove unused import

Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>

Co-authored-by: Faris Ansari <netchampfaris@users.noreply.github.com>
Co-authored-by: Raffael Meyer <14891507+barredterra@users.noreply.github.com>
(cherry picked from commit 702e8674f94fde353ac12885f5782ea73ef75b6f)

Co-authored-by: Ankush Menat <ankush@frappe.io>
This commit is contained in:
mergify[bot] 2022-10-11 21:59:43 +05:30 committed by GitHub
parent 4863ba154e
commit f0952d0fbb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 4 deletions

View file

@ -121,6 +121,7 @@ jobs:
DB: mariadb
- name: Verify yarn.lock
if: ${{ steps.check-build.outputs.build == 'strawberry' }}
run: |
cd ~/frappe-bench/apps/frappe
yarn install --immutable --immutable-cache --check-cache

View file

@ -572,12 +572,15 @@ class ImportFile:
######
def read_file(self, file_path):
def read_file(self, file_path: str):
extn = os.path.splitext(file_path)[1][1:]
file_content = None
with open(file_path, mode="rb") as f:
file_content = f.read()
file_name = frappe.db.get_value("File", {"file_url": file_path})
if file_name:
file = frappe.get_doc("File", file_name)
file_content = file.get_content()
return file_content, extn

View file

@ -422,7 +422,6 @@ class File(Document):
return os.path.exists(self.get_full_path())
def get_content(self) -> bytes:
"""Returns [`file_name`, `content`] for given file name `fname`"""
if self.is_folder:
frappe.throw(_("Cannot get file contents of a Folder"))