question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Importing file from shell

See original GitHub issue

I didn’t find anything on that nor in the documentation neither in the source, so I’m currently trying with this code:

from import_export.admin import ImportMixin
from yourapp.models import SomeModelResource

filename='/home/user/filename.csv'
format_number = 0  # CSV
resource = SomeModelResource()

mixin = ImportMixin()
input_format = mixin.get_import_formats()[format_number]()
tmp_storage = mixin.get_tmp_storage_class()(name=filename)
dataset = input_format.create_dataset(tmp_storage.read(input_format.get_read_mode()))

resource.import_data(dataset, dry_run=False, raise_errors=True, file_name=filename)

tmp_storage.remove()

Is there a preferred way to do this? Did I miss it somewhere? Because I’m losing all my RAM + 1G of swap to the confirmation page on a big import. And I don’t think that splitting the file and feeding chunks one by one is an adequate workaround.

Issue Analytics

  • State:open
  • Created 8 years ago
  • Comments:13 (11 by maintainers)

github_iconTop GitHub Comments

1reaction
manelcloscommented, Jan 4, 2018

A PR with tests would be good

1reaction
merwokcommented, Dec 28, 2017

A management command would be great.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Import / Source Files in Bash | dave eddy
Importing files in Bash is a way to take a bash file, and implant (import) it in another script temporarily during runtime.
Read more >
Import a local bash file into another bash file - Stack Overflow
Read and execute commands from FILENAME in the current shell. The entries in $PATH are used to find the directory containing FILENAME.
Read more >
importing data from a text file to a bash script
Here are two solutions: Importing data from an external file into a Bash script: Read the file and store its contents as entries...
Read more >
import command in Linux with Examples - GeeksforGeeks
import command in Linux system is used for capturing a screenshot for any of the active pages we have and it gives the...
Read more >
Import functions and variables into Bash with the source ...
You can use source to "import" a file into your shell environment, just as you might use the include keyword in C or...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found