#!/usr/bin/env python # -*- coding: utf-8 -*- import os import shutil def copy(src, dst, ignore=None): if os.path.isdir(src): shutil.copytree(src, dst, True, ignore) else: shutil.copy(src, dst) def open_file(path, mode='r'): if mode == 'w' or os.path.isfile(path): return open(path, mode) else: return None def write_file(path, content): fd = open_file(path, mode='w') if fd: fd.write(content.encode('utf-8')) fd.close() return path else: return None def read_file(path): content = '' fd = open_file(path) if fd: content = fd.read() fd.close() return content else: print("Error: could not open %s" % path) return content def read_file_lines(path): content = [] fd = open_file(path) if fd: content = fd.readlines() fd.close() return content def get_lines(content): ''' return list of content split by line. Leading/trailing blank lines are not reserved. ''' return content.strip().split('\n')