Skip to content

Commit f507963

Browse files
committed
PEP8 changes.
1 parent 8f5495e commit f507963

14 files changed

+99
-94
lines changed

CountMillionCharacter.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -287,9 +287,9 @@
287287
ARCHBISHOP OF YORK
288288
Before, and greet his grace: my lord, we come.
289289
Exeunt'''
290-
count = { }
290+
count = {}
291291
for character in info.upper():
292-
count[character]=count.get(character,0)+1
292+
count[character] = count.get(character, 0) + 1
293293

294294
value = pprint.pformat(count)
295295
print(value)

CountMillionCharacters-2.0.py

+1
Original file line numberDiff line numberDiff line change
@@ -20,5 +20,6 @@ def main():
2020
value = pprint.pformat(count)
2121
print(value)
2222

23+
2324
if __name__ == "__main__":
2425
main()

backup_automater_services.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,21 @@
88

99
# Description : This will go through and backup all my automator services workflows
1010

11+
import datetime # Load the library module
12+
import os # Load the library module
1113
import shutil # Load the library module
12-
import datetime # Load the library module
13-
import os # Load the library module
1414

15-
today = datetime.date.today() # Get Today's date
15+
today = datetime.date.today() # Get Today's date
1616
todaystr = today.isoformat() # Format it so we can use the format to create the directory
1717

1818
confdir = os.getenv("my_config") # Set the variable by getting the value from the OS setting
1919
dropbox = os.getenv("dropbox") # Set the variable by getting the value from the OS setting
2020
conffile = ('services.conf') # Set the variable as the name of the configuration file
2121
conffilename = os.path.join(confdir, conffile) # Set the variable by combining the path and the file name
2222
sourcedir = os.path.expanduser('~/Library/Services/') # Source directory of where the scripts are located
23-
destdir = os.path.join(dropbox, "My_backups"+"/"+"Automater_services"+todaystr+"/") # Combine several settings to create
24-
23+
destdir = os.path.join(dropbox, "My_backups" + "/" +
24+
"Automater_services" + todaystr + "/") # Combine several settings to create
25+
2526
# the destination backup directory
2627
for file_name in open(conffilename): # Walk through the configuration file
2728
fname = file_name.strip() # Strip out the blank lines from the configuration file

batch_file_rename.py

+7-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
once you pass the current and new extensions
77
'''
88

9-
__author__ = 'Craig Richards'
9+
__author__ = 'Craig Richards'
1010
__version__ = '1.0'
1111

1212
import os
@@ -28,8 +28,8 @@ def batch_rename(work_dir, old_ext, new_ext):
2828
newfile = filename.replace(old_ext, new_ext)
2929
# Write the files
3030
os.rename(
31-
os.path.join(work_dir, filename),
32-
os.path.join(work_dir, newfile)
31+
os.path.join(work_dir, filename),
32+
os.path.join(work_dir, newfile)
3333
)
3434

3535

@@ -40,12 +40,12 @@ def main():
4040
# Set the variable work_dir with the first argument passed
4141
work_dir = sys.argv[1]
4242
# Set the variable old_ext with the second argument passed
43-
old_ext = sys.argv[2]
43+
old_ext = sys.argv[2]
4444
# Set the variable new_ext with the third argument passed
45-
new_ext = sys.argv[3]
46-
45+
new_ext = sys.argv[3]
46+
4747
batch_rename(work_dir, old_ext, new_ext)
4848

49+
4950
if __name__ == '__main__':
5051
main()
51-

check_file.py

+8-8
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
11
# Script Name : check_file.py
22
# Author : Craig Richards
3-
# Created : 20 May 2013
4-
# Last Modified :
3+
# Created : 20 May 2013
4+
# Last Modified :
55
# Version : 1.0
66

77
# Modifications : with statement added to ensure correct file closure
88

99
# Description : Check a file exists and that we can read the file
1010

11-
from __future__ import print_function
11+
from __future__ import print_function
1212
import sys # Import the Modules
1313
import os # Import the Modules
1414

1515
# Prints usage if not appropriate length of arguments are provided
1616
def usage():
1717
print('[-] Usage: python check_file.py <filename1> [filename2] ... [filenameN]')
1818
exit(0)
19-
19+
2020

2121
# Readfile Functions which open the file that is passed to the script
2222
def readfile(filename):
@@ -29,21 +29,21 @@ def main():
2929
filenames = sys.argv[1:]
3030
for filename in filenames: # Iterate for each filename passed in command line argument
3131
if not os.path.isfile(filename): # Check the File exists
32-
print ('[-] ' + filename + ' does not exist.')
32+
print ('[-] ' + filename + ' does not exist.')
3333
filenames.remove(filename) #remove non existing files from filenames list
3434
continue
35-
35+
3636
if not os.access(filename, os.R_OK): # Check you can read the file
3737
print ('[-] ' + filename + ' access denied')
3838
filenames.remove(filename) # remove non readable filenames
3939
continue
4040
else:
4141
usage() # Print usage if not all parameters passed/Checked
42-
42+
4343
# Read the content of each file
4444
for filename in filenames:
4545
print ('[+] Reading from : ' + filename) # Display Message and read the file contents
4646
readfile(filename)
47-
47+
4848
if __name__ == '__main__':
4949
main()

check_internet_con.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import urllib2
22

33
try:
4-
urllib2.urlopen("http://google.com", timeout=2)
5-
print ("working connection")
4+
urllib2.urlopen("http://google.com", timeout=2)
5+
print ("working connection")
66

77
except urllib2.URLError:
8-
print ("No internet connection")
8+
print ("No internet connection")

create_dir_if_not_there.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
try:
1313
home = os.path.expanduser("~") # Set the variable home by expanding the users set home directory
1414
print home # Print the location
15-
16-
if not os.path.exists(home+'/testdir'):
17-
os.makedirs(home+'/testdir') # If not create the directory, inside their home directory
18-
except Exceptions as e:
15+
16+
if not os.path.exists(home + '/testdir'):
17+
os.makedirs(home + '/testdir') # If not create the directory, inside their home directory
18+
except Exception, e:
1919
print e

daily_checks.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -28,21 +28,21 @@ def clear_screen(): # Function to clear the screen
2828
def print_docs(): # Function to print the daily checks automatically
2929
print ("Printing Daily Check Sheets:")
3030
# The command below passes the command line string to open word, open the document, print it then close word down
31-
subprocess.Popen(["C:\\Program Files (x86)\Microsoft Office\Office14\winword.exe", "P:\\\\Documentation\\Daily Docs\\Back office Daily Checks.doc", "/mFilePrintDefault", "/mFileExit"]).communicate()
32-
31+
subprocess.Popen(["C:\\Program Files (x86)\Microsoft Office\Office14\winword.exe", "P:\\\\Documentation\\Daily Docs\\Back office Daily Checks.doc", "/mFilePrintDefault", "/mFileExit"]).communicate()
32+
3333
def putty_sessions(): # Function to load the putty sessions I need
3434
for server in open(conffilename): # Open the file server_list.txt, loop through reading each line - 1.1 -Changed - 1.3 Changed name to use variable conffilename
3535
subprocess.Popen(('putty -load '+server)) # Open the PuTTY sessions - 1.1
3636

3737
def rdp_sessions():
3838
print ("Loading RDP Sessions:")
3939
subprocess.Popen("mstsc eclr.rdp") # Open up a terminal session connection and load the euroclear session
40-
40+
4141
def euroclear_docs():
4242
# The command below opens IE and loads the Euroclear password document
4343
subprocess.Popen('"C:\\Program Files\\Internet Explorer\\iexplore.exe"' '"file://fs1\pub_b\Pub_Admin\Documentation\Settlements_Files\PWD\Eclr.doc"')
4444

45-
# End of the functions
45+
# End of the functions
4646

4747
# Start of the Main Program
4848
def main():
@@ -53,7 +53,7 @@ def main():
5353
clear_screen() # Call the clear screen function
5454

5555
# The command below prints a little welcome message, as well as the script name, the date and time and where it was run from.
56-
print ("Good Morning " + os.getenv('USERNAME') + ", "+
56+
print ("Good Morning " + os.getenv('USERNAME') + ", "+
5757
filename, "ran at", strftime("%Y-%m-%d %H:%M:%S"), "on",platform.node(), "run from",os.getcwd())
5858

5959
print_docs() # Call the print_docs function

dir_test.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# Created : 29th November 2011
44
# Last Modified :
55
# Version : 1.0
6-
# Modifications :
6+
# Modifications :
77

88
# Description : Tests to see if the directory testdir exists, if not it will create the directory for you
99

10-
import os # Import the OS module
10+
import os # Import the OS module
1111

1212
if not os.path.exists('testdir'): # Check to see if it exists
1313
os.makedirs('testdir') # Create the directory

fileinfo.py

+31-26
Original file line numberDiff line numberDiff line change
@@ -13,49 +13,54 @@
1313
from __future__ import print_function
1414
import os
1515
import sys
16-
import stat # index constants for os.stat()
16+
import stat # index constants for os.stat()
1717
import time
1818

1919
try_count = 16
2020
while try_count:
21-
file_name = raw_input("Enter a file name: ") # pick a file you have ...
21+
file_name = raw_input("Enter a file name: ") # pick a file you have
2222
try_count >>= 1
23-
try :
23+
try:
2424
file_stats = os.stat(file_name)
2525
break
2626
except OSError:
27-
print ("\nNameError : [%s] No such file or directory\n" %file_name)
27+
print ("\nNameError : [%s] No such file or directory\n", file_name)
2828

2929
if try_count == 0:
3030
print ("Trial limit exceded \nExiting program")
3131
sys.exit()
3232
# create a dictionary to hold file info
3333
file_info = {
34-
'fname': file_name,
35-
'fsize': file_stats [stat.ST_SIZE],
36-
'f_lm': time.strftime("%d/%m/%Y %I:%M:%S %p",time.localtime(file_stats[stat.ST_MTIME])),
37-
'f_la': time.strftime("%d/%m/%Y %I:%M:%S %p",time.localtime(file_stats[stat.ST_ATIME])),
38-
'f_ct': time.strftime("%d/%m/%Y %I:%M:%S %p",time.localtime(file_stats[stat.ST_CTIME]))
34+
'fname': file_name,
35+
'fsize': file_stats[stat.ST_SIZE],
36+
'f_lm': time.strftime("%d/%m/%Y %I:%M:%S %p",
37+
time.localtime(file_stats[stat.ST_MTIME])),
38+
'f_la': time.strftime("%d/%m/%Y %I:%M:%S %p",
39+
time.localtime(file_stats[stat.ST_ATIME])),
40+
'f_ct': time.strftime("%d/%m/%Y %I:%M:%S %p",
41+
time.localtime(file_stats[stat.ST_CTIME]))
3942
}
43+
4044
print
41-
print ("file name = %(fname)s" % file_info)
42-
print ("file size = %(fsize)s bytes" % file_info)
43-
print ("last modified = %(f_lm)s" % file_info)
44-
print ("last accessed = %(f_la)s" % file_info)
45-
print ("creation time = %(f_ct)s" % file_info)
45+
print ("file name = %(fname)s", file_info)
46+
print ("file size = %(fsize)s bytes", file_info)
47+
print ("last modified = %(f_lm)s", file_info)
48+
print ("last accessed = %(f_la)s", file_info)
49+
print ("creation time = %(f_ct)s", file_info)
4650
print
4751
if stat.S_ISDIR(file_stats[stat.ST_MODE]):
48-
print ("This a directory")
52+
53+
print ("This a directory")
4954
else:
50-
print ("This is not a directory")
51-
print ()
52-
print ("A closer look at the os.stat(%s) tuple:" % file_name)
53-
print (file_stats)
54-
print ()
55-
print ("The above tuple has the following sequence:")
56-
print ("""st_mode (protection bits), st_ino (inode number),
57-
st_dev (device), st_nlink (number of hard links),
58-
st_uid (user ID of owner), st_gid (group ID of owner),
59-
st_size (file size, bytes), st_atime (last access time, seconds since epoch),
60-
st_mtime (last modification time), st_ctime (time of creation, Windows)"""
55+
print ("This is not a directory")
56+
print ()
57+
print ("A closer look at the os.stat(%s) tuple:" % file_name)
58+
print (file_stats)
59+
print ()
60+
print ("The above tuple has the following sequence:")
61+
print ("""st_mode (protection bits), st_ino (inode number),
62+
st_dev (device), st_nlink (number of hard links),
63+
st_uid (user ID of owner), st_gid (group ID of owner),
64+
st_size (file size, bytes), st_atime (last access time, seconds since epoch),
65+
st_mtime (last modification time), st_ctime (time of creation, Windows)"""
6166
)

folder_size.py

+13-11
Original file line numberDiff line numberDiff line change
@@ -8,25 +8,27 @@
88

99
# Description : This will scan the current directory and all subdirectories and display the size.
1010

11-
import os, sys # Load the library module and the sys module for the argument vector
11+
import os
12+
import sys ''' Load the library module and the sys module for the argument vector'''
1213
try:
13-
directory = sys.argv[1] # Set the variable directory to be the argument supplied by user.
14+
directory = sys.argv[1] # Set the variable directory to be the argument supplied by user.
1415
except IndexError:
1516
sys.exit("Must provide an argument.")
16-
dir_size = 0 # Set the size to 0
1717

18-
fsizedicr = {'Bytes': 1, 'Kilobytes': float(1)/1024, 'Megabytes': float(1)/(1024*1024), 'Gigabytes': float(1)/(1024*1024
19-
*
20-
1024)}
21-
18+
dir_size = 0 # Set the size to 0
19+
fsizedicr = {'Bytes': 1,
20+
'Kilobytes': float(1) / 1024,
21+
'Megabytes': float(1) / (1024 * 1024),
22+
'Gigabytes': float(1) / (1024 * 1024
23+
* 1024)}
2224
for (path, dirs, files) in os.walk(directory): # Walk through all the directories. For each iteration, os.walk returns the folders, subfolders and files in the dir.
2325
for file in files: # Get all the files
24-
filename = os.path.join(path, file)
26+
filename = os.path.join(path, file)
2527
dir_size += os.path.getsize(filename) # Add the size of each file in the root dir to get the total size.
26-
27-
fsizeList = [str(round(fsizedicr[key]*dir_size, 2)) + " " + key for key in fsizedicr] # List of units
2828

29-
if dir_size == 0: print ("File Empty") # Sanity check to eliminate corner-case of empty file.
29+
fsizeList = [str(round(fsizedicr[key] * dir_size, 2)) + " " + key for key in fsizedicr] # List of units
30+
31+
if dir_size == 0: print ("File Empty") # Sanity check to eliminate corner-case of empty file.
3032
else:
3133
for units in sorted(fsizeList)[::-1]: # Reverse sort list of units so smallest magnitude units print first.
3234
print ("Folder Size: " + units)

get_info_remoute_srv.py

+8-12
Original file line numberDiff line numberDiff line change
@@ -4,32 +4,28 @@
44
# Last Modified : -
55
# Version : 1.0.0
66

7-
# Modifications :
7+
# Modifications :
88

99
# Description : this will get info about remoute server on linux through ssh connection. Connect these servers must be through keys
1010

1111
import subprocess
12-
import sys
1312

13+
HOSTS = ('proxy1', 'proxy')
1414

15-
HOSTS = ['proxy1', 'proxy']
16-
17-
COMMANDS = ['uname -a', 'uptime']
15+
COMMANDS = ('uname -a', 'uptime')
1816

1917
for host in HOSTS:
2018
result = []
2119
for command in COMMANDS:
22-
ssh = subprocess.Popen(["ssh", "%s" % host, command],
23-
shell=False,
24-
stdout=subprocess.PIPE,
25-
stderr=subprocess.PIPE)
20+
ssh = subprocess.Popen(["ssh", "%s" % host, command],
21+
shell=False,
22+
stdout=subprocess.PIPE,
23+
stderr=subprocess.PIPE)
2624
result.append(ssh.stdout.readlines())
27-
print('--------------- '+host+' --------------- ')
25+
print('--------------- ' + host + ' --------------- ')
2826
for res in result:
2927
if not res:
3028
print(ssh.stderr.readlines())
3129
break
3230
else:
3331
print(res)
34-
35-

get_youtube_view.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
#how much views you want
55
#This only works when video has less than 300 views, it won't work when there are more than 300 views...
66
#due to youtube's policy.
7-
print("Enjoy your Time\n" +time.ctime())
7+
print("Enjoy your Time\n" + time.ctime())
88
for count in range(30):
99
time.sleep(5)
1010
webbrowser.open("https://www.youtube.com/watch?v=o6A7nf3IeeA")

0 commit comments

Comments
 (0)