Monday, February 25, 2013

LnzScript 0.5 released

Announcing a new release of LnzScipt:



Some LnzScipt functions used to depend on a tool called nircmd. In this release, Clipboard.saveImage, Screen.convertImage, and Screen.saveScreenshot were rewritten from scratch, and nircmd is no longer necessary.

Also, the API Reference now looks a lot better. It still uses a client-side XSL transform, it's nice to use the same xml file for rendering docs in the browser, rendering docs in a little C# tool that comes with LnzScript, and rendering tooltip documentation within the LnzScript Editor.

See screencasts and revamped documentation here.

Sunday, February 17, 2013

Exporting a remote Subversion repo

I wrote a script to create a backup of a complete remote svn repo, containing all revisions. It looks like there's a project rsvndump that does something similar, but I knew that what I wanted could be done in a few lines of Python.

Change the first few lines, and then run the script.
url='https://url.of.repo/svn/'
output=r'C:\full\path\to\desired\output'
username='user.name'

import os, subprocess, shutil
from os.path import join, exists

def runwithshell(listArgs):
  print('  '.join(listArgs))
  popen = subprocess.Popen(listArgs, shell=True, stdout=subprocess.PIPE)
  stdout = popen.communicate()[0]
  return stdout.rstrip(), popen.returncode

def run_assertsuccess(cmd):
  assert '|' in cmd
  cmd = cmd.split('|')
  stdout, ret = runwithshell(cmd)
  assert ret == 0

def go():
  assert exists(output)
  os.chdir(output)
  run_assertsuccess('svnadmin|create|lrepo')
  if os.name=='nt':
    assert ':' in output, 'want full path'
    fout=open('lrepo/hooks/pre-revprop-change.bat','w')
    fout.write('')
    fout.close()
  else:
    assert output.startswith('/'), 'want full path'
    fout=open('lrepo/hooks/pre-revprop-change','w')
    fout.write('#!/bin/sh\nexit 0;')
    fout.close()
    run_assertsuccess('chmod|+x|localrepos/hooks/pre-revprop-change')
    
  run_assertsuccess('svnsync|init|--username|'+username+'|file:///'+output+'\lrepo|'+url)
  run_assertsuccess('svnsync|sync|--username|'+username+'|file:///'+output+'\lrepo')

def createExportDump():
  assert exists(output)
  os.chdir(output)
  run_assertsuccess('svnadmin|dump|.\lrepo|--incremental|>|out.dump')



if __name__=='__main__':
  go()
  createExportDump()
  print('saved to out.dump')



Later, to restore from the dump, use:
# svnadmin create newrepo
# svnadmin load ./newrepo < out.dump
References: How do I download my Subversion history