Package: slipsomat
slipsomatis a small tool for pulling and pushing letters to Alma using
Selenium browser automation. It allows to you to keep an up-to-date local
copy of all the letters, so you can keep them under version control. And
by storing checksums of all the letters, it can warn you if you're about
to overwrite a letter that has been modified by someone else without pulling
in their changes.This tool exists because Alma doesn't provide a way to synchronize the letters,
only a web form to edit them. With over 100 different letters, editing them
using a web form (with no syntax highlighting) is very tedious. We have also
brought this up on Ideas Exchange – feel free to add your vote toour idea there.SetupSlipsomat should work with Python 3.5 and later on most platforms.
Please use ourissue trackerto report any problems.Install with pip:pip install -U slipsomatOnce installed, you can runslipsomatfrom any directory containing aslipsomat.cfgconfig file.
To get started, create an empty directory with aslipsomat.cfgfile with the
following contents:[login]
auth_type=
domain=
instance=
institution=
username=
password=

[selenium]
browser=firefox
default_timeout=20

[window]
width=1300
height=700where you fill in the blank values.Setauth_type=Feideif you authenticate using Feide SAML. Setauth_type=SAMLfor Shibboleth or other SAML providers (submit an issue if it doesn't work with
your provider!).
Setauth_type=basicto use the standard Alma login.domainis your Feide domain, e.g.uio.no. If you don't use Feide as your
SAML provider, you can leave this empty.instanceis the Alma instance name, which is the first part of your ALMA URL.
If your Alma URL isbibsys-k.alma.exlibrisgroup.com, thenbibsys-kis the
instance name.institutionthe Alma institution name, e.g.47BIBSYS_UBOusernameis your username.passwordcan be left blank if you want to be asked for it each time. This
is the recommended solution, since the password is stored in plain text.browsercan be set tofirefox,chromeorphantomjs. The corresponding
driver must be installed (GeckoDriver for Firefox, ChromeDriver for Chrome).
I've had success with all three browsers, but from time to time a browser can
start crashing or freezing at some point. First thing to try then is to upgrade
both Selenium and the browser driver. If there's still problems, switch to
another browser for some time. Ifthatdoesn't help, there might be an issue
with slipsomat. Please file an issue.DebuggingIf you haveinquirerinstalled (does not work on Windows), slipsomat will give
you some options for starting a debug session if the script crashes.Getting startedTheslipsomatcommand will give you an interactive shell where you can type various
commands. Typehelpfor an overview.To get started in an empty directory, typepullto pull in all the XSLT files from your Alma
instance and store them in a folder namedxsl(will be created if not there already).
Optionally, typedefaultsto pull in all default letters too. Note that astatus.jsonfile
is also created. This holds the checksums for all the letters, allowing the script to easily keep
track of which files have been modified (locally or in Alma).Once you have a directory with all your files you're free to put them under version control
if you like. Here's the repo we use for our files:https://github.com/scriptotek/alma-letters-uboWorkflowIn a workspace directory (a directory having aslipsomat.cfgfile):Start by doinggit pullto pull in changes from other users.slipsomatto start the scriptOptional: the slipsomat commandpullwill check if any files have been updated
directly in Alma (without usingslipsomat), fetch those and updatestatus.json.
Comparison is done by comparing the update date in Alma with the update date instatus.json.
Alma does not provide time granularity for updates, only date, so for files that have been
modified today, the script will open the letter in Alma to get the text and calculate a
checksum to compare with the checksum instatus.json.
Note: If you skip this step,slipsomatwill still warn you if you try to push a
letter that have been modified remotely (checksums not matching), but then you will
have to merge manually.After having made modifications to one or more letters, run the slipsomat commandpushto push the updates to Alma. Comparison is done by comparing checksums of the local files
with the checksums instatus.json. Before making any changes, the script will print a list
of files and confirm that you want to upload these.After having tested the modifications, do agit commit(remember to include the updatedstatus.json) andgit pushThe shell has a command history, and tab completion. For exampletest Ful<tab><tab>.Updating default lettersUse theslipsomatcommanddefaultsto pull in all default letters.
Note that the command takes quite some time to run, since all letters have to
be checked as Alma provides no information whatsoever on when the default
letters were last updated.Testing the output of a letterAlma lets you test the output on the Notification Template page, but doing this
manually each time is boring, so slipsomat provides you with thetestcommand
to automate that.Create a folder called "test-data" in the same folder as theslipsomat.cfgfile.
Add one or more XML files you want to test there.Startslipsomatand run the commandtest filename.xmlwherefilename.xmlis a file in the "test-data" folder. This will upload the
XML file to the Notification Template page and store the resulting HTML output
and a screenshot in the "test-data" folder.To test multiple files at the same time, you can use Unix style pathname pattern
expansion ("globbing"). E.g. to test all XML files in the "test-data" folder, use the*wildcard character:test *.xmlBy default, the command will use English as the letter language. To test
another language, just append@and the language code to the filename.
Example:test filename.xml@nnYou can even test multiple languages in one go by specifying multiple language
codes separated by comma like so:test filename.xml@en,no,nnThis can also be used in combination with globbing. To test all XML files in the
"test-data" folder in three languages:test *.xml@en,no,nnSee alsoopen issuesthealma-letters-ubo repofor our XSLT filesDevelopmentEditable installIf you want aneditable installthat you can hack on yourself:git clone https://github.com/scriptotek/alma-slipsomat.git
cd alma-slipsomat
pip install -U -e .Using slipsomat as a Python libraryGiven that you have created aslipsomat.cfgfile, here's how to start
experimenting:fromselenium.webdriver.common.byimportByfromselenium.webdriver.supportimportexpected_conditionsasECfromslipsomat.workerimportWorkerfromslipsomat.slipsomatimportTemplateConfigurationTableworker=Worker('slipsomat.cfg')# Start the browser and log in using the credentials from slipsomat.cfgworker.connect()# Open and parse the letters tabletable=TemplateConfigurationTable(worker)# Open the default version of the SmsFulCancelRequestLetter lettertable.open_default_letter('xsl/letters/sms/SmsFulCancelRequestLetter.xsl')# Use Selenium to click some elementwait=worker.waiter()element=wait.until(EC.element_to_be_clickable((By.XPATH,'//button[@aria-label="Open Alma configuration"]')))element.click()Note: During development, it might be a good idea to setdefault_timeoutinslipsomat.cfgto a small value (like 3 seconds) to avoid having to wait a
long time every time you write a wrong selector.