Rudimentary versioning system

October 19th, 2020 – 11:14 am
Categorized as Computing Notes
Tagged as ,

Some time ago, Python 2 was the default language for use with Linux and Gnome 3. A set of extensions for Gnome, called Nautilus Python existed which allowed one to create customized right click menus. One of these was called “Historical Copy” and it created a lovely copy of the file with a timestamp inserted into the file name. The timestamp was constructed to allow the files to appear easily sorted when perusing directories. Software rot affects all software and especially software that requires Python 2 libraries that maintainers no longer ship on new versions of Linux. To counter this problem, we have a rudimentary versioning system which adheres to the Keep it Sweetly Simple (KISS) principle.

The following code is appended to the .bashrc file in the home directory.

### Historicaly copy rudimentary versioning system
### Saves a historical copy and a note about that copy
### Compressed to 68 character width for website display purposes

historicalcopy() { mkdir -p local-historical-versions &&\
 timestamp=$(date +"%y.%m.%d.%H%M") && read -p\
 "Enter filename:" n && read -p "Enter note: " note &&\
 filename=$(pwd)/$n && file_name=$(basename $filename) &&\
 left_side="${file_name%.*}" && extension="${file_name##*.}" &&\
 cp $filename\
 local-historical-versions/${left_side}-$timestamp.$extension &&\
 cp $filename\
 /var/www/html/hv/archives/${left_side}-$timestamp.$extension &&\
 sed -i "11i${left_side}-${timestamp}.${extension} ${note}"\
 /var/www/html/hv/index.php; }

From the directory with the file to be versioned, the command historicalcopy is typed.  This creates a directory in the current directory called local-historical-versions and copies the historical version into that directory.  It then copies the file to a complete historical versions archive and appends a PHP file in the web-server directory with both a link and comment.  The reason periods are used instead of dashes is because experience demonstrated that my software using Python had difficulty with filenames incorporating dashes.  This naming style is similar to the RPM naming convention which uses name-version-release.  This rudimentary versioning system uses a timestamp as the version number.  There are plenty of more advanced systems such as git, but sometimes we can work more efficiently with a simple direct historical list of what file did what way back when.  This could easily be changed so that an html file is updated in a local directory instead of a PHP file on a web-server.  The PHP file is future usage incorporated with user authentication and a long term code repository.  The code can then be used on OSX and Windows Subsystem Linux by pulling the PHP to the local machine, inserting the necessary file, and then transferring it back to the web-server via SSH.  In a way that seems like Git, but this is for the use case where one wants a simple to use list.

A typical workflow goes something like this.  Open up a terminal and navigate to the directory containing a heavily evolved r script.  Use the historicalcopy command on that script with a note something like “prior to adding the new data frame for time series data on Kentucky unemployment”.  Then open that file in the editor of choice to work on it.  It is very useful for Python programs where huge changes can take place which require significant removal of existing code.  This is the case for one of my projects which has been an ongoing project involving thousands and thousands of lines of code that has evolved over four years.  This simple scheme lets me remember which files had the important code that I still want to use in the future. The flat file format and easy naming convention allows easy migration, backups, and reduces the learning curve.

image