Skip to content

Commit 0f47eb3

Browse files
author
Jared Manning
committed
Remove unecessary step by combining functions.
1 parent 70271c5 commit 0f47eb3

File tree

1 file changed

+25
-26
lines changed

1 file changed

+25
-26
lines changed

check_file.py

+25-26
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,28 @@
99
# Description : Check a file exists and that we can read the file
1010

1111
import sys # Import the Modules
12-
import os # Import the Modules
13-
14-
# Readfile Functions which open the file that is passed to the script
15-
16-
def readfile(filename):
17-
f = open(filename, 'r')
18-
line = f.read()
19-
print line
20-
21-
def main():
22-
if len(sys.argv) == 2: # Check the arguments passed to the script
23-
filename = sys.argv[1] # The filename is the first argument
24-
if not os.path.isfile(filename): # Check the File exists
25-
print '[-] ' + filename + ' does not exist.'
26-
exit(0)
27-
if not os.access(filename, os.R_OK): # Check you can read the file
28-
print '[-] ' + filename + ' access denied'
29-
exit(0)
30-
else:
31-
print '[-] Usage: ' + str(sys.argv[0]) + ' <filename>' # Print usage if not all parameters passed/Checked
32-
exit(0)
33-
print '[+] Reading from : ' + filename # Display Message and read the file contents
34-
readfile(filename)
35-
36-
if __name__ == '__main__':
37-
main()
12+
import os # Import the Modules
13+
14+
# Readfile Functions which open the file that is passed to the script
15+
16+
def readfile(filename):
17+
line = open(filename, 'r').read()
18+
print line
19+
20+
def main():
21+
if len(sys.argv) == 2: # Check the arguments passed to the script
22+
filename = sys.argv[1] # The filename is the first argument
23+
if not os.path.isfile(filename): # Check the File exists
24+
print '[-] ' + filename + ' does not exist.'
25+
exit(0)
26+
if not os.access(filename, os.R_OK): # Check you can read the file
27+
print '[-] ' + filename + ' access denied'
28+
exit(0)
29+
else:
30+
print '[-] Usage: ' + str(sys.argv[0]) + ' <filename>' # Print usage if not all parameters passed/Checked
31+
exit(0)
32+
print '[+] Reading from : ' + filename # Display Message and read the file contents
33+
readfile(filename)
34+
35+
if __name__ == '__main__':
36+
main()

0 commit comments

Comments
 (0)