File: files.py

package info (click to toggle)
python-spur 0.3.23-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 216 kB
  • sloc: python: 1,188; makefile: 39
file content (23 lines) | stat: -rw-r--r-- 735 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import os

class FileOperations(object):
    def __init__(self, shell):
        self._shell = shell
        
    def copy_file(self, source, destination=None, dir=None):
        if destination is None and dir is None:
            raise TypeError("Destination required for copy")
            
        if destination is not None:
            self._shell.run(["cp", "-T", source, destination])
        elif dir is not None:
            self._shell.run(["cp", source, "-t", dir])
            
    def write_file(self, path, contents):
        self._shell.run(["mkdir", "-p", os.path.dirname(path)])
        file = self._shell.open(path, "w")
        try:
            file.write(contents)
        finally:
            file.close()