Here is a Python3 script that does VMS like auto file versioning using a time stamp appended to the original file name when saved.
I've put a bunch of commentary into the script and run a half dozen such scripts on my ubuntu machine with only the directories being different in each different version of the script so that I am simultaneously versioning multiple directories. No real penalty to the machines performance.
!/usr/bin/env python3
print ("PROJECT FILES VERSIONING STARTED")
print ("version_creation.py") #place all this code into script of this name
print ("run as.. 'python3 version_creation.py' from command line")
print ("ctrl 'c' to stop")
print (" ")
print ("To run program in background type below to command line and then close the window. ")
print ("nohup python3 version_creation.py")
print ("....to stop process go menu/administration/system monitor... and kill python3")
print (" ")
print ("Always save files to the 'ProjectFiles' directory and the version files ")
print (" will also be created in that directory.")
print (" ")
print (" ")
print (" ")
print (" ")
import shutil
import os
import time
--- set the time interval to check for new files (in seconds) below
- this interval should be smaller than the interval new files appear!
t = 10
--- set the source directory (dr1) and target directory (dr2)
dr1 = "/path/to/source_directory"
dr2 = "/path/to/target_directory"
import glob
import os
dr1 = "/home/michael/ProjectFiles" #both originals and versions will be saved to this directory
dr2 = "/home/michael/ProjectFileVersions"
while True:
if os.listdir(dr1) == []:
print ("Empty")
n = 100
else:
list_of_files = glob.glob(dr1+'/*') # * means all if need specific format then *.csv
latest_file_path = max(list_of_files, key=os.path.getctime)
print ("1 Latest_file_path = ", latest_file_path)
originalname = latest_file_path.split('/')[-1]
print ("2 originalname = ", originalname)
filecreation = (os.path.getmtime(latest_file_path))
print ("filecreation = ",filecreation)
now = time.time()
fivesec_ago = now - 5 # Number of seconds
print ("fivesec_ago = ", fivesec_ago)
timedif = fivesec_ago - filecreation #time between file creation
print ("timedif = ", timedif)
if timedif <= 5: #if file created less than 5 seconds ago
nameroot = originalname.split(".")[-0]
print ("3 nameroot= ", nameroot)
extension = os.path.splitext(originalname)[1][1:]
print ("4 extension = ", extension)
curdatetime = time.strftime('%Y%m%d-%H%M%S')
print ("5 curdatetime = ", curdatetime)
newassembledname = (nameroot + "_" + curdatetime + "." + extension)
print ("6 newassembledname = ", newassembledname)
source = dr1+"/"+originalname
print ("7 source = ", source)
target = dr1+"/"+newassembledname
print ("8 target = ", target)
shutil.copy(source, target)
time.sleep(t)
share
the below was put in earlier and works but i like the above python script much better......(been using python for about 3 hours)
#!/usr/bin/env python3
print ("PROJECT FILES VERSIONING STARTED")
print ("projectfileversioning.py")
print ("run as.. 'python3 projectfileversioning.py' from command line")
print ("ctrl 'c' to stop")
print (" ")
print ("To run program in background type below to command line and then close the window. ")
print ("nohup python3 projectfileversioning.py")
print ("....to stop process go menu/administration/system monitor... and kill python")
print (" ")
print ("Always save files to the 'ProjectFiles' directory and the file ")
print (" will be redirected to the ProjectFileVersions where")
print (" time stamped versions will also be created.")
print (" ")
print ("If you like you may then copy/move the versioned and original file from 'ProjectFileVersions' to ")
print ("any other directory you like.")
import shutil
import os
import time
#--- set the time interval to check for new files (in seconds) below
#- this interval should be smaller than the interval new files appear!
t = 10
#--- set the source directory (dr1) and target directory (dr2)
#dr1 = "/path/to/source_directory"
#dr2 = "/path/to/target_directory"
import glob
import os
dr1 = "/home/michael/ProjectFiles"
dr2 = "/home/michael/ProjectFileVersions"
while True:
if os.listdir(dr1) == []:
n = 100
else:
list_of_files = glob.glob(dr1+'/*') # * means all if need specific format then *.csv
latest_file_path = max(list_of_files, key=os.path.getctime)
print ("1 Latest_file_path = ", latest_file_path)
originalname = latest_file_path.split('/')[-1]
print ("2 originalname = ", originalname)
nameroot = originalname.split(".")[-0]
print ("3 nameroot= ", nameroot)
extension = os.path.splitext(originalname)[1][1:]
print ("4 extension = ", extension)
curdatetime = time.strftime('%Y%m%d-%H%M%S')
print ("5 curdatetime = ", curdatetime)
newassembledname = (nameroot + "_" + curdatetime + "." + extension)
print ("6 newassembledname = ", newassembledname)
source = dr1+"/"+originalname
print ("7 source = ", source)
target = dr2+"/"+originalname
print ("8 target = ", target)
shutil.copy(source, target)
source = dr1+"/"+originalname
print ("9 source = ", source)
target = dr2+"/"+newassembledname
print ("10 target = ", target)
shutil.move(source, target)
time.sleep(t)
#share
related: flashbake
– Dan D. – 2011-12-16T10:06:31.870http://sourceforge.net/apps/mediawiki/fuse/index.php?title=VersioningFileSystems – SleighBoy – 2011-12-16T11:14:26.293
Is there a special requirement about which software you use? Because if you're only looking to track changes you do manually (by editing files), Eclipse has this feature built-in, it's called "local history". – Stefan Seidel – 2013-02-06T10:48:00.433
@StefanSeidel I'm not the topic-starter, but I would prefer no-IDE solution. – Michael Pankov – 2013-02-06T12:57:00.393