Jump to content

Move compiled game/db to reading directory/back up the old ones

Recommended Posts

  • VIP

The script moves the compiled game/db to a desired location, and back up the old ones, in a new directory, named by the user (as a commit message u might say)

Could be useful if you don't use  git/symlinks, I myself didn't think about symlinks for game/db,  thanks to ikarus i do now haha.

Prereq: python >3.4

pkg search python

pkg install python_vsr_from_search_output

I've commented in line what values to modify 

To call the script simply do python3.X fileName.py backup_Directory_Name

import os
import shutil
from os import path

class move_Binaries:
	targetDir = "/usr/home/bin(!!!REPLACE)" #Dir path from where the compiled game/db are read (Has to be absolute)
	outputBin = "/usr/src/gameSource/Server/output(!!!REPLACE)" #Dir path for where the gmake output is saved (compiled game/db) Has to be absolute
	backupDir = targetDir + "/backupBin"
	binariesList = ['game','db']

	def __init__(self, backup_Name="NotGiven"):
		if backup_Name != "NotGiven":
			self.backup_Name = backup_Name
			self.backup_Name = backup_Name + '_' + self.getDateIdentifier()

	def move_to_backup(self):
		files = [f for f in os.listdir(self.targetDir) if os.path.isfile(f)]
		dirCreated = self.createDir(self.backupDir, self.backup_Name)
		for f in files:
			for binName in self.binariesList:
				if binName in str(f):
					shutil.move(f"{self.targetDir}/{str(f)}", dirCreated + '/' + str(f))
					print(f"Backed up binaries at: {dirCreated + '/' + str(f)}")

	def move_from_output(self):
		for binName in self.binariesList:
				shutil.move(f"{self.outputBin}/{binName}", self.targetDir + '/' + binName)
				print(f"Moved binaries from {self.outputBin} to {self.targetDir + '/' + binName}")
			except FileNotFoundError :
				print(f"No {binName} file in {self.outputBin} to move")

	def createDir(self, dirLocation, dirName=''):
		dirCreated = dirLocation + r'/' + dirName
		if path.exists(dirCreated):
			return dirCreated
			return dirCreated

	def getDateIdentifier(self):
		from datetime import datetime

		# datetime object containing current date and time
		now = datetime.now()
		# dd/mm/YY H:M:S
		dt_string = now.strftime("%d_%m_%Y_%H_%M_%S")
		return dt_string

if __name__ == "__main__":
	import sys
	move_BinariesInstance = move_Binaries(sys.argv[1])


  • Love 1
Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

Terms of Use / Privacy Policy / Guidelines / We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.