1#!/usr/bin/env python 2# Copyright (c) 2016 The Chromium Authors. All rights reserved. 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 11import argparse 12import os 13import sys 14 15 16def Main(): 17 parser = argparse.ArgumentParser() 18 parser.add_argument('files', nargs='+') 19 parser.add_argument('-f', '--force', action='store_true', 20 help="don't err on missing") 21 parser.add_argument('--stamp', required=True, help='touch this file') 22 args = parser.parse_args() 23 for f in args.files: 24 try: 25 os.remove(f) 26 except OSError: 27 if not args.force: 28 print >>sys.stderr, "'%s' does not exist" % f 29 return 1 30 31 with open(args.stamp, 'w'): 32 os.utime(args.stamp, None) 33 34 return 0 35 36 37if __name__ == '__main__': 38 sys.exit(Main()) 39