1#!/usr/bin/env python3 2# Copyright 2016 The Chromium Authors 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6"""Delete a file. 7 8This module works much like the rm posix command. 9""" 10 11 12import argparse 13import os 14import sys 15 16 17def Main(): 18 parser = argparse.ArgumentParser() 19 parser.add_argument('files', nargs='+') 20 parser.add_argument('-f', '--force', action='store_true', 21 help="don't err on missing") 22 parser.add_argument('--stamp', required=True, help='touch this file') 23 args = parser.parse_args() 24 for f in args.files: 25 try: 26 os.remove(f) 27 except OSError: 28 if not args.force: 29 print("'%s' does not exist" % f, file=sys.stderr) 30 return 1 31 32 with open(args.stamp, 'w'): 33 os.utime(args.stamp, None) 34 35 return 0 36 37 38if __name__ == '__main__': 39 sys.exit(Main()) 40