Skip to content

Commit 2740c65

Browse files
committed
Minor Bugfixes and Print Additions
1 parent 5c0a1c7 commit 2740c65

File tree

3 files changed

+31
-16
lines changed

3 files changed

+31
-16
lines changed

README

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,10 @@ orders easily and automatically from a development to a production website and v
2525
--- TODO ---
2626

2727
- Feature
28+
- Automatica flush of MySQL Log
2829
- Lock Functionality
2930
- Silent Running and Verbose
31+
- Per Database Ignore certain SQL Commands otherwise recorded (CREATE TEMPORARY TABLE etc)
3032

3133
- sqlrun.py
3234
- If there is a start transaction at the end of the command file with some

monitor.py

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@
5454
# ##############################
5555

5656
# Stop script if no option is passed for the file location
57-
if not args.location:
57+
if not args.run_only and not args.location:
5858
parser.error("Log file not defined correctly (Use -f)")
5959

6060
# ################################
@@ -568,29 +568,29 @@ def main():
568568
pass
569569
print
570570

571+
# ######################################
572+
# --- IF LOG FILE DOES NOT EXIST ---
573+
# ######################################
574+
575+
else:
576+
print("File does not exist or is a directory")
571577

572578
# #####################
573579
# --- RUN FILE ---
574580
# #####################
575581

576-
# If the run flag was set then run the database changes as per the configuration
577-
if args.run or args.run_only:
578-
for user in configuration:
579-
runsql.runSQL(user, configuration)
580-
581-
582+
# If the run flag was set then run the database changes as per the configuration
583+
if args.run or args.run_only:
582584

583-
print("Total time of execution: " + str(datetime.now() - startTime))
585+
for user in configuration:
586+
runsql.runSQL(user, configuration)
584587

585588

589+
# ######################
590+
# --- SHOW RUNTIME ---
591+
# ######################
586592

587-
588-
# ######################################
589-
# --- IF LOG FILE DOES NOT EXIST ---
590-
# ######################################
591-
592-
else:
593-
print("File does not exist or is a directory")
593+
print("Total time of execution: " + str(datetime.now() - startTime))
594594

595595
# ########################
596596
# --- EXECUTE MAIN ---

runsql.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
from enum import Enum
88
from enum import IntEnum
99

10+
# Import custom modules
11+
import conf
12+
1013
# ##############################
1114
# --- SCRIPT REQUIREMENTS ---
1215
# ##############################
@@ -43,8 +46,9 @@ def runSQL(user, configuration):
4346
db = MySQLdb.connect('localhost', dbuser, dbpass, database)
4447
cursor = db.cursor()
4548

46-
# Setup error and filename variables
49+
# Setup error, counter and filename variables
4750
err = 0
51+
count = 0
4852
tmp_file = configuration[user][conf.CONFIG.Export.value] + "_tmp"
4953

5054
# Open the file containing sql commands ##########################NEEDS TO BE ADDED TO CONFIGURATION
@@ -60,6 +64,7 @@ def runSQL(user, configuration):
6064
# Try executing the command
6165
try:
6266
cursor.execute(line)
67+
count += 1
6368

6469
# Should an error occur we stop processing commands by setting err to 1 and write the line to our tmp file
6570
# To stop on a warning as well we should add ,MySQLdb.Warning inside brackets
@@ -90,9 +95,17 @@ def runSQL(user, configuration):
9095
os.rename(configuration[user][conf.CONFIG.Export.value], configuration[user][conf.CONFIG.Export.value] + "_backup")
9196
os.rename(tmp_file, configuration[user][conf.CONFIG.Export.value])
9297

98+
print("Encountered Error...")
99+
print("Ran " + str(count) + " Queries before Error")
100+
print("Created backup of file executed")
101+
print("Saved remaining queries (including errored) as file run.")
102+
93103
# Otherwise if there were no errors just delete both files
94104
else:
95105

96106
os.remove(configuration[user][conf.CONFIG.Export.value])
97107
os.remove(tmp_file)
98108

109+
print("Ran " + str(count) + "Queries...")
110+
print("Completed Successfully")
111+

0 commit comments

Comments
 (0)