File: dd.py

package info (click to toggle)
python3-dmm 0.1.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 540 kB
  • sloc: python: 441; makefile: 2
file content (30 lines) | stat: -rw-r--r-- 901 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
"""
Python wrapper for dd, usually to create large empty disk image
"""

import subprocess

def create_file(ifile, ofile, bs, count, timeout):
    """
    Create or overwrite a file using dd.

    As with dd:

    - ifile: inputfile
    - ofile: outputfile
    - bs: size of block
    - count: how many blocks should be written
    - timeout: make the operation timeout after amount of seconds
    """
    dd_output = subprocess.run(["/usr/bin/dd",
                        "if=" + ifile,
                        "of=" + ofile,
                        "bs=" +  bs,
                        "count=" + count],
                        check=True,
                        timeout=timeout,
                        stdout=subprocess.PIPE,
                        stderr=subprocess.PIPE,
                        universal_newlines=True,)
    return (dd_output.returncode, dd_output.stdout, dd_output.stderr)