Archiv der Kategorie: Allgemein

Monitor your SVN Repositories with a simple Python script

I have to work with a lot of SVN repositories that do only have a terrible EMail notification. So, it would be nice to have a script that quickly collects the updates of all your repositories by listening you all the commit messages of all new commits.

This can be done using the following simple Python script:

svncheck.py

# This script has some functions to check the svn revision and print the logs since the last update (it updates on
# its way).
# In the base version of this script, the list 'svn_folders' is run through. However you can also print the change log
# for the current working directory with 'printLog(getRevisionDifference())'

import os

# TODO: Enter the paths to your repos here
svn_folders = ["/home/USER/Repos/Repo1", "/home/USER/Repos/Repo2"]

# parses the current local revision
def getRevision():
    stdin, stdout = os.popen2("svn log -l 1")
    stdin.close()
    lines = stdout.readlines()
    if len(lines) == 1:
        return None
    return int(lines[1].split(" ")[0].replace('r',''))


# gets the svn up to date
def update():
    stdin, stdout = os.popen2("svn up")
    stdin.close()
    stdout.readlines() # for waiting for termination


# updates the svn and returns the revision change
def getRevisionDifference():
    revOld = getRevision()
    if revOld is None:
        print 'Not a working directory. Please check your configuration.'
        return
    update()
    revNew = getRevision()
    return revNew - revOld


# prints the log for the last n changes
def printLog(lastN):
    if lastN == 0:
        print "No changes."
        return
    os.system("svn log -l " + str(lastN))


# execute
for svn_folder in svn_folders:
    print svn_folder
    os.chdir(svn_folder)
    printLog(getRevisionDifference()

Simply save it as a .py-file and make it executable with ‚chmod +x svncheck.py‘. Afterwards you can execute it anytime with ‚python svncheck.py‚ (actually on most systems you don’t need the ‚python‚)

The script will go to each repository-folder and for each of these folders:
1. Check the current local revision
2. Update the repository
3. Check the new revision
4. Print the log for the new revisions

Note: This does not automatically send you notifications but only displays changes if executed manually. However, you can quite easily pipe

os.system("svn log -l " + str(lastN)

into some notification program and let the script be executed automatically via a cronjob.

Workaround for Misprints of Samsung XPress M2825ND

I got myself a Samsung XPress M2825ND Mono Laser Printer for little money. Most of the time it does a great job: It is fast, very sharp, and the automatic duplex is a blessing if you have to print many papers. Unfortunately, if printing manipulated PDFs (like 2 pages per side) it doesn’t print properly: It leaves some parts blank. I did not notice any difficulties with ‚clean‘ PDFs like created by Latex (as long as you do not use any further modifications in the print properties).

However, if I do the 2 pages per side modification externally (not in the print configuration) with

 pdfnup --nup 2x1 --landscape --suffix '\''2x1'\'' --scale '\''0.95'\' input.pdf

 and afterwards convert the PDF to PNG and concatenate the PNGs to a PDF again

convert -quality 100 -density 300x300 input.pdf single%05d.png && convert -adjoin single*.png output.pdf && rm single*.png

everything works fine.

Nonetheless, the produced PDF takes much longer to process for the printer. I only apply this method if the normal printing fails (It happens only seldom and if mostly only one page, so the wasted prints are not serious).

Note: I haven’t had any misprints for some time using the newest Samsung drivers and Arch Linux. I only had a problem with „Select page size using document size“ which resulted in very small prints if activated.