Re: simultaneous copy to multiple media



I need a program that simultaneously can copy a single file (1
GB) from my pc to multiple USB-harddrives.

Sounds like a pretty simple simple python script:
-------------------------------------------------------
#!/bin/env python
def spew(source_file_name,
output_file_names,
block_size = 8*1024):
source = file(source_file_name, "rb")
output_files = [file(s, "wb") for s in output_file_names]
s = source.read(block_size)
while s:
for outfile in output_files:
outfile.write(s)
s = source.read(block_size)

for outfile in output_files:
outfile.close()
source.close()

if __name__ == '__main__':
from sys import argv
if len(argv) > 2:
spew(argv[1], argv[2:])
else: #print some usage/help
print "%s source_file dest_file1 [dest_file2 [dest_file3 [...]]]" % argv[0]
-------------------------------------------------------

Just call it with

bash> cd /mnt
bash> python spew.py file1.txt usb1/file1.txt usb2/file2.txt

for as many destinations as you want. Adjust the blocksize as you see fit:

spew(argv[1], argv[2:], 1024*1024)

or whatever your favorite blocksize is.

It's not terribly graceful about error-checking, or prompting if any of the files exist previously, or if it can't write to any of the output files because for any reason (full disk, write-protected disk, destination path doesn't exist, etc). Thus, if there's a problem, you'll get a pretty backtrace that will allow you to solve all your problems ;)

-tkc





.



Relevant Pages

  • Re: help me to find the error
    ... where i can get more basic and detail knowledge of python.. ... and this programme is givving me this error: ... infile = open ... outfile = open ...
    (comp.lang.python)
  • Re: How do I organize my Python application code?
    ... Python is generally organized, in case my code spans multiple files, ... Visaul Studio, so the way their code is organized in a group of header ... That's all there is; there's no header files or declaration files or explicitly maintained object files etc; the program itself is just a bunch of Python files. ... In Eclipse, if you do produce output files, make them ...
    (comp.lang.python)
  • Re: code review
    ... I`m pretty new to developing applications using python and i would ... like advance on this script i recently created which helps linux ... Tips: store the format string in the dict; then you can just do something like fmt % {'infile': infile, 'outfile': outfile} ...
    (comp.lang.python)
  • Re: Insert string into string
    ... and was calling it ... python script.py <xxx.pdb>outfile ... Mensanator's script looks like you can take it "as is". ...
    (comp.lang.python)
  • Re: Performance Issues of MySQL with Python
    ... converting the data to its tuple data type which adds one more ... I found this when I didn't have the priviledge to do "mysql> SELECT * ... FROM TBL INTO OUTFILE;", I used python MySQLdb first, which I later ...
    (comp.lang.python)