Statistiques
| Révision :

root / ase / svnversion_io.py @ 1

Historique | Voir | Annoter | Télécharger (1,3 ko)

1
# Copyright (C) 2003  CAMP
2
# Please see the accompanying LICENSE file for further information.
3

    
4
from os import path
5
try:
6
    from subprocess import Popen, PIPE
7
except ImportError:
8
    from os import popen3
9
else:
10
    def popen3(cmd):
11
        p = Popen(cmd, shell=True, close_fds=True,
12
                  stdin=PIPE, stdout=PIPE, stderr=PIPE)
13
        return p.stdin, p.stdout, p.stderr
14

    
15
def write_svnversion(svnversion, dir):
16
    svnversionfile = path.join(dir, 'svnversion.py')
17
    f = open(svnversionfile,'w')
18
    f.write('svnversion = "%s"\n' % svnversion)
19
    f.close()
20
    print 'svnversion = ' +svnversion+' written to '+svnversionfile
21
    # assert svn:ignore property if the installation is under svn control
22
    # because svnversion.py has to be ignored by svn!
23
    cmd = popen3('svn propset svn:ignore svnversion.py '+dir)[1]
24
    output = cmd.read()
25
    cmd.close()
26

    
27
def get_svnversion_from_svn(dir):
28
    # try to get the last svn version number from svnversion
29
    cmd = popen3('svnversion -n '+dir)[1] # assert we are in the project dir
30
    output = cmd.read().strip()
31
    cmd.close()
32
    if output.startswith('exported'):
33
        # we build from exported source (e.g. rpmbuild)
34
        output = None
35
    return output
36

    
37
svnversion = get_svnversion_from_svn(dir='ase')
38
if svnversion:
39
    write_svnversion(svnversion, dir='ase')