blob: 11e8a6439900406132b7bdaf810aae80ea7b7f5c [file] [log] [blame]
Takuto Ikuta3dab32e02023-01-12 18:52:001#!/usr/bin/env python3
Avi Drissman73a09d12022-09-08 20:33:382# Copyright 2016 The Chromium Authors
thakis0dfb6ba2016-09-23 22:42:323# 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
Raul Tambre9e24293b2019-05-12 06:11:0711
thakis0dfb6ba2016-09-23 22:42:3212import 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:
Raul Tambre9e24293b2019-05-12 06:11:0729 print("'%s' does not exist" % f, file=sys.stderr)
thakis0dfb6ba2016-09-23 22:42:3230 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())