Sunday, May 24, 2009

A Python script used to backup a Perforce server

I use Perforce to manage all my important documents and because they are important I would like to backup the perforce server regularly. Attached below is a simple Python scrip that I wrote to carry out the backup procedure.


#Backup Perforce database

#Author: Song Hu

#Created: May, 2009



"Backup Perforce Database."



def main():

"main function"



#the directory of the backup files

BackupDir = "G:/BackupPerforce/"

#the directory of the p4 server root

P4ROOTDir = "C:/Program Files/Perforce/"



# get the current date and time

from time import strftime

strTime = strftime("%Y-%m-%d_%H%M%S")



#update backup directory according to current date

BackupDir = BackupDir + strTime + '/'

import os

if not os.path.exists(BackupDir):

os.makedirs(BackupDir)



# logging

import logging

logging.basicConfig(level = logging.DEBUG,

format ='%(asctime)s (%(levelname)s) \t: %(message)s',

filename = BackupDir+'log',

filemode = 'w')



# step 1. connect to perforce

logging.info('Connecting to perforce server...')

import sys

#import the perforce modlule

from P4 import P4 , P4Exception



p4 = P4()

p4.port = "your port" #perforce server and port

p4.user = "your account name" #user name, should be admin

p4.client = "your work space" #perforce work space



try:

p4.connect()

except P4Exception:

for e in p4.errors:

logging.error(e)



logging.error('Failed to connect to perforce!')

_close(p4,logging)



return



logging.info('Connected.')



# step 2. verify the integrity of the perforce server

logging.info('Verify the integrity of the perforce server (//...) ... ')

rt = p4.run_verify('-q','//...')

if 0 != len(rt):

logging.error('Failed to verify the data on the perforce server!')

_close(p4,logging)



logging.info('Verification finished.')





# step 3. create perforce checkpoint

logging.info('Create perforce checkpoint...')

prefix = BackupDir + strTime



try:

p4.run("admin", "checkpoint",prefix)

except P4Exception:

for e in p4.errors:

logging.error(e)



logging.error('Failed to create perforce checkpoint!')

_close(p4,logging)

return



logging.info('Checkpoint created.')





# step 4. backup versioned files

logging.info('Backup versioned files...')

import shutil



try:

shutil.copytree(P4ROOTDir + 'depot/',

BackupDir + strTime + '_depot/')

except shutil.Error, er:

for e in er:

logging.error(e)



logging.error('Failed to copy versioned files!')

_close(p4,logging)

except os.error, er:

logging.error(str(er))

logging.error('Failed to copy versioned files!')

_close(p4,logging)

except:

logging.error('Unexpected error!')

logging.error('Failed to copy versioned files!')

_close(p4,logging)

logging.info('Versioned files copied to the directory: ' + BackupDir + strTime + '_depot/')





#clean up

_close(p4,logging)





def _close(p4,logging):

"this function disconnect from perforce server and close the logging"



#close the connection to perforce server

if p4.connected():

p4.disconnect()



logging.info('Disconnected from perforce.')

logging.shutdown()





if __name__ == "__main__":

main()


If everything goes right a backup directory,which is named using the current date and time, will be created and it shold contain:
  • a copy of the directory of the Perforce versioned files,
  • a Perforce checkpoint file (.ckp.n),
  • a Perforce journal file (.jnl.n-1),
  • a log.

Wednesday, January 07, 2009

Calgary Agile Methods User Group & J.B. Rainsberger

There was a Calgary Agile Methods User Group (CAMUG) meeting tonight at the University of Calgary. The talk was given by J.B. Ransberger who is a consultant on Agile software development and was introduced by the meeting host as a "Agile Guru".

The talk was an hour long and turned out to be very educative and entertaining. Instead of teaching the audience how superior Agile methods are, Mr. Ranberger talked about the ways to incorporate Agile into organisations from his own experience.

Wednesday, December 21, 2005

Using an Avatar to Develop a System for the Predication of Human Body Pose from Moments



Tracking people using movie sequences is not straightforward because of the human body’s articulation and the complexity of a person’s movements. In this paper we show how a person’s 3D pose can be reconstructed by using corresponding silhouettes of video sequences from a monocular view. Currently, a virtual avatar is used to train the model for inferring the pose and a different avatar is used to produce novel examples not in the training set in order to evaluate the approach. The approach was subsequently tested using the silhouettes of walking people.
Published on Lecture Notes Computer Science, Springer.