Created
November 5, 2020 00:49
-
-
Save chuckcoggins/58eb28f21d7b4bb750309a28794f8e67 to your computer and use it in GitHub Desktop.
AutoPatcher Version 2
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import shutil | |
from pip._vendor.colorama import Fore, Style, init | |
import subprocess | |
import time | |
init() | |
src_dir = os.getcwd() | |
# Windows Service Stopper | |
def stopServices(svcname): | |
args = ['sc', 'stop', svcname] | |
result = subprocess.run(args) | |
# Windows Service Starter | |
def startServices(svcname): | |
args = ['sc', 'start', svcname] | |
result = subprocess.run(args) | |
# Copy directory Function | |
def copyloop(appdir, target): | |
cp_source_dir = appdir | |
cp_target_dir = target | |
file_names = os.listdir(cp_source_dir) | |
for file_name in file_names: | |
shutil.copy2(os.path.join(cp_source_dir, file_name), cp_target_dir) | |
# Program Begins Here | |
print(Fore.RED + "\n Auto Patcher v.2") | |
print(Style.RESET_ALL) | |
print(Fore.GREEN + "\n ....Shutting down all Services.....") | |
print(Style.RESET_ALL) | |
stopServices(svcname='2018Server') | |
stopServices(svcname='TTC_AppService') | |
stopServices(svcname='TTC_ClockHost') | |
stopServices(svcname='TTDBSyncServer') | |
stopServices(svcname='TTNotify') | |
# Pause for 5 Seconds | |
print(Fore.GREEN + "\n ....Waiting 5 Seconds") | |
print(Style.RESET_ALL) | |
time.sleep(5) | |
# Begin moving files | |
print(Fore.GREEN + "\n ....Patching TT2018 HP & Period Accounting....") | |
copyloop(appdir="C:\\Patches Installer\\", target="C:\\test\\") | |
print(Fore.GREEN + "\n ....TT2018 Files Patched") | |
print(Fore.GREEN + "\n ....Patching the WebPortal....") | |
wp_source_dir = src_dir + "\WebPortal" | |
wp_target_dir = 'C:\\Testing\\Web Portals\\' | |
for source_dir, dirs, file_names in os.walk(wp_source_dir): | |
target_dir = source_dir.replace(wp_source_dir, wp_target_dir, 1) | |
for file_name in file_names: | |
source_file = os.path.join(source_dir, file_name) | |
target_file = os.path.join(target_dir, file_name) | |
if os.path.exists(target_file): | |
# in case of the source and target are the same file | |
if os.path.samefile(source_file, target_file): | |
continue | |
os.remove(target_file) | |
shutil.copy2(source_file, target_dir) | |
print(Fore.GREEN + "\n ....WebPortal Patched") | |
print(Fore.GREEN + "\n ....Patching the Supervisor Client Time Zone files....") | |
copyloop(appdir="C:\\Patches Installer\\TT2018\\", target="C:\\test\\") | |
print(Fore.GREEN + "\n ....Supervisor Client Patched") | |
print(Fore.GREEN + "\n ....Patching DBSyncServer to 2018.40....") | |
copyloop(appdir="C:\\Patches Installer\\Server\\", target="C:\\TimeTrakConnect\\DBSyncServer\\") | |
print(Fore.GREEN + "\n ....DBSyncServer Patched") | |
print(Fore.GREEN + "\n ....Patching DBSyncServerAdmin to 2018.40....") | |
copyloop(appdir="C:\\Patches Installer\\Admin\\", target="C:\\TimeTrakConnect\\DBSyncServerAdmin\\") | |
print(Fore.GREEN + "\n ....DBSyncServerAdmin Patched") | |
print(Fore.GREEN + "\n ....Patching AppService to 2018.40....") | |
copyloop(appdir="C:\\Patches Installer\\AppService\\", target="C:\\TimeTrakConnect\\AppService\\") | |
print(Fore.GREEN + "\n ....AppService Patched") | |
# Pause for 5 Seconds | |
print(Fore.GREEN + "\n ....Waiting 5 Seconds.......") | |
print(Style.RESET_ALL) | |
time.sleep(5) | |
# Starting Windows Services | |
startServices(svcname='2018Server') | |
startServices(svcname='TTC_AppService') | |
startServices(svcname='TTC_ClockHost') | |
startServices(svcname='TTDBSyncServer') | |
startServices(svcname='TTNotify') | |
print(Fore.RED + "\n Auto Patcher is Complete!") | |
print(Style.RESET_ALL) | |
print("\n Made with <3 by Chuck Coggins \n") | |
input('Press ENTER to exit') | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The same thing as version 1 except I learned Functions and I have added what I learned to v. 2