Skip to content

Instantly share code, notes, and snippets.

@chuckcoggins
Created November 1, 2020 20:45
Show Gist options
  • Save chuckcoggins/3023aa54c0a26324a6d76efd63b97d9a to your computer and use it in GitHub Desktop.
Save chuckcoggins/3023aa54c0a26324a6d76efd63b97d9a to your computer and use it in GitHub Desktop.
Stopping Services + Patching Files
# Importing the modules
import os
import shutil
from pip._vendor.colorama import Fore, Style, init
import subprocess
import time
init()
# Services Shutdown
print(Fore.RED + "\n Auto Patcher")
print(Style.RESET_ALL)
print(Fore.GREEN + "\n ....Shutting down Services.....")
print(Style.RESET_ALL)
# stop windows services
args = ['sc', 'stop', '2018Server']
result = subprocess.run(args)
args = ['sc', 'stop', 'TTC_AppService']
result = subprocess.run(args)
args = ['sc', 'stop', 'TTC_ClockHost']
result = subprocess.run(args)
args = ['sc', 'stop', 'TTDBSyncServer']
result = subprocess.run(args)
args = ['sc', 'stop', 'TTNotify']
result = subprocess.run(args)
# 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....")
src_dir = os.getcwd()
# Moving the TT2018 Folder
tt_source_dir = src_dir + "\TT2018"
tt_target_dir = 'C:\\Testing\\'
file_names = os.listdir(tt_source_dir)
for file_name in file_names:
shutil.copy2(os.path.join(tt_source_dir, file_name), tt_target_dir)
print(Fore.GREEN + "\n ....TT2018 Files Patched")
# Moving the WebPortal Folder
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")
# Moving the SupClient Folder
print(Fore.GREEN + "\n ....Patching the Supervisor Client Time Zone files....")
sc_source_dir = src_dir + "\SupClientTimeZonePatch"
sc_target_dir = 'C:\\Testing\\Client\\'
file_names = os.listdir(sc_source_dir)
for file_name in file_names:
shutil.copy2(os.path.join(sc_source_dir, file_name), sc_target_dir)
print(Fore.GREEN + "\n ....Supervisor Client Patched")
# Moving the DBSyncServer Folder
print(Fore.GREEN + "\n ....Patching DBSyncServer to 2018.40....")
dss_source_dir = src_dir + "\DBSyncServer"
dss_target_dir = 'C:\\Program Files (x86)\\Connect\\DBSyncServer\\'
file_names = os.listdir(dss_source_dir)
for file_name in file_names:
shutil.copy2(os.path.join(dss_source_dir, file_name), dss_target_dir)
print(Fore.GREEN + "\n ....DBSyncServer Patched")
# Moving the DBSyncAdmin Folder
print(Fore.GREEN + "\n ....Patching DBSyncServerAdmin to 2018.40....")
dba_source_dir = src_dir + "\DBSyncAdmin"
dba_target_dir = 'C:\\Program Files (x86)\\Connect\\DBSyncServerAdmin\\'
file_names = os.listdir(dba_source_dir)
for file_name in file_names:
shutil.copy2(os.path.join(dba_source_dir, file_name), dba_target_dir)
print(Fore.GREEN + "\n ....DBSyncServerAdmin Patched")
# Moving the AppService Folder
print(Fore.GREEN + "\n ....Patching AppService to 2018.40....")
apps_source_dir = src_dir + "\AppService"
apps_target_dir = 'C:\\Program Files (x86)\\Connect\\AppService\\'
file_names = os.listdir(apps_source_dir)
for file_name in file_names:
shutil.copy2(os.path.join(apps_source_dir, file_name), apps_target_dir)
print(Fore.GREEN + "\n ....AppService Patched")
# Pause for 5 Seconds
print(Fore.GREEN + "\n ....Waiting 5 Seconds.......")
print(Style.RESET_ALL)
time.sleep(5)
# start windows services
print(Fore.GREEN + "\n ....Starting Windows Services....")
print(Style.RESET_ALL)
args = ['sc', 'start', '2018Server']
result = subprocess.run(args)
args = ['sc', 'start', 'TTC_AppService']
result = subprocess.run(args)
args = ['sc', 'start', 'TTC_ClockHost']
result = subprocess.run(args)
args = ['sc', 'start', 'TTDBSyncServer']
result = subprocess.run(args)
args = ['sc', 'start', 'TTNotify']
result = subprocess.run(args)
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')
@chuckcoggins
Copy link
Author

This is version 1 of my auto patcher program for work.
I created this in my spare time. I am currently trying to teach myself Python and the idea of this popped in my head for my first project.
Patching files is something I and my team needs to do so I created a program to make this process easier.

Version 2 is in the works where I use a function and make the Copy command part of that function so there is a lot less code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment