2014년 12월 21일 일요일

Editing /usr/bin/brainworkshop and /usr/share/.../brainworkshop.pyw to share BW data between machines using Dropbox

In January 2013, I wrote a post about sharing Brain Workshop data between several machines using Dropbox. I recently tried to follow these same instructions, only to discover that they no longer work.

I spent some time over the weekend coming up with another way to share my BW training data with other machines using Dropbox, and have found a solution that requires light editing of one bash script and a Python source file. This post will assume that there is only one user of Brainworkshop (this user is automatically named default by BW).

First, let's take a look at the important files that brainworkshop package 4.8.4-4 installs on Archlinux:

[archjun@lenovoS310 ~]$ sudo pacman -Ql brainworkshop
[sudo] password for archjun: 
brainworkshop /usr/
brainworkshop /usr/bin/
brainworkshop /usr/bin/brainworkshop
...
brainworkshop /usr/share/brainworkshop/
brainworkshop /usr/share/brainworkshop/brainworkshop.pyw
brainworkshop /usr/share/brainworkshop/data/
brainworkshop /usr/share/brainworkshop/data/Readme-stats.txt
...

btw, commands on other distros to list files installed by pkgName are rpm -ql pkgName (RHEL/CentOS/Fedora etc) and dpkg-query -L pkgName (Debian/Ubuntu).

The file /usr/bin/brainworkshop is simply a bash script that calls /usr/share/brainworkshop/brainworkshop.pyw


#!/bin/sh
python2 /usr/share/brainworkshop/brainworkshop.pyw

A cautionary note -- on Archlinux, invoking python from the CLI will actually bring up the Python 3 REPL, as it is the default in Arch. On other distros, invoking python from the CLI will probably bring up the Python 2 REPL instead. To invoke Python 2 in Arch, you have to explicitly invoke python2 on the CLI or in scripts. The particulars of brainworkshop launch scripts will differ slightly between Linux distros.

I know that the official brainworkshop project is hosted on Sourceforge, but looking through the trunk branch of their SVN repo, I cannot find any brainworkshop.sh bash script file. Apparently the BW launch scripts for Linux are created separately by each distro.

In order to make Brainworkshop store config files and training data in a Dropbox folder instead of locally, we must make some edits to the launch script above. There are several config flags, --configfile, --statsfile, and --datadir that we need to add to our invocation of brainworkshop.pyw. The last flag was added at the end of March 2013, according to the brainworkshop Github repo for Slackware. (Click here for an example of how this flag can be used in a script or when invoking brainworkshop.pyw from the CLI). Below you can see my edited version of /usr/bin/brainworkshop.sh that specifies a Dropbox folder as the location for saving data and configuration files:

#!/bin/sh
BRW_CONFIGFILE=$HOME/Dropbox/.brainworkshop/data/.brainworkshop.ini
BRW_STATFILE=$HOME/Dropbox/.brainworkshop/data/.brainworkshop.stats
BRW_DATADIR=$HOME/Dropbox/.brainworkshop/data/

python2 /usr/share/brainworkshop/brainworkshop.pyw --configfile $BRW_CONFIGFILE --statsfile $BRW_STATFILE --datadir $BRW_DATADIR

But we are still not done, as the Python 2 script, brainworkshop.pyw, has slightly different names for the statistics and data files. We will change these manually. The function we need to find is named rewrite_configfile() and it should be around line 691 (Meta-g-g 691 for my fellow Emacs users out there).

Below is an edited version of /usr/share/brainworkshop/brainworkshop.pyw that changes the names of the stats and data files to match the settings in our launch script above:





You will see that I have commented out the following three lines:

#statsfile = 'stats.txt'
...
#STATS_BINARY = 'logfile.dat'
...
#newconfigfile_contents = CONFIGFILE_DEFAULT_CONTENTS.replace('stats.txt', statsfile)

and replaced them with the following (to make stats and data filenames consistent with settings in our custom /usr/bin/brainworkshop.sh)

statsfile = '.brainworkshop.stats'
...
STATS_BINARY = 'default-sessions.dat'
...
newconfigfile_contents = CONFIGFILE_DEFAULT_CONTENTS.replace('.brainworkshop.stats', statsfile)

Now when you open Brain Workshop, it will access data files from Dropbox instead of looking in your home directory!

댓글 없음:

댓글 쓰기