| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright 2012 The LUCI Authors. All rights reserved. | 2 # Copyright 2012 The LUCI Authors. All rights reserved. |
| 3 # Use of this source code is governed by the Apache v2.0 license that can be | 3 # Use of this source code is governed under the Apache License, Version 2.0 |
| 4 # found in the LICENSE file. | 4 # that can be found in the LICENSE file. |
| 5 | 5 |
| 6 """Uses different APIs to touch a file.""" | 6 """Uses different APIs to touch a file.""" |
| 7 | 7 |
| 8 import os | 8 import os |
| 9 import sys | 9 import sys |
| 10 | 10 |
| 11 | 11 |
| 12 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) | 12 BASE_DIR = os.path.dirname(os.path.abspath(__file__)) |
| 13 | 13 |
| 14 | 14 |
| 15 def main(): | 15 def main(): |
| 16 print 'Only look if a file exists but do not open it.' | 16 print 'Only look if a file exists but do not open it.' |
| 17 assert len(sys.argv) == 2 | 17 assert len(sys.argv) == 2 |
| 18 path = os.path.join(BASE_DIR, 'test_file.txt') | 18 path = os.path.join(BASE_DIR, 'test_file.txt') |
| 19 command = sys.argv[1] | 19 command = sys.argv[1] |
| 20 if command == 'access': | 20 if command == 'access': |
| 21 return not os.access(path, os.R_OK) | 21 return not os.access(path, os.R_OK) |
| 22 elif command == 'isfile': | 22 elif command == 'isfile': |
| 23 return not os.path.isfile(path) | 23 return not os.path.isfile(path) |
| 24 elif command == 'stat': | 24 elif command == 'stat': |
| 25 return not os.stat(path).st_size | 25 return not os.stat(path).st_size |
| 26 return 1 | 26 return 1 |
| 27 | 27 |
| 28 | 28 |
| 29 if __name__ == '__main__': | 29 if __name__ == '__main__': |
| 30 sys.exit(main()) | 30 sys.exit(main()) |
| OLD | NEW |