#!/usr/bin/env python # This script copies maven snapshot files that publish to the m2 repository to a directory import fnmatch import os import sys import shutil def copy_snapshot(src, dest, postfix): ending = 'SNAPSHOT' + postfix match = '*' + postfix for root, dirs, files in os.walk(src): files.sort(); filename = 'NULL' dirname = ''; for file in files: if not fnmatch.fnmatch(file, match): continue filename = file # get the lastest xsd file if filename == 'NULL': continue # skip the time stamp, take of the two last - get the target file name list = filename.split('-'); # check if the file's name is end with SNAPSHOT # or removing the last two time stamps if list.pop()!= ending: list.pop(); list.append(ending) srcfile= os.path.join(root,filename) destfile = os.path.join(dest,'-'.join(list)) shutil.copyfile(srcfile,destfile) # disable the output # print 'copy %s to %s' %(srcfile, destfile); def main(): if len(sys.argv) < 4: print 'copy_snapshot.py SRC DES postfix'\ 'copy the last snapshot file from SRC directory to DES directory which ends with the postfix'\ 'with the file name end with SNAPSHOT.postfix' sys.exit(); copy_snapshot(sys.argv[1], sys.argv[2], sys.argv[3]); if __name__ == '__main__': sys.exit(main())