File: check-libpaw.py

package info (click to toggle)
abinit 9.10.4-3
  • links: PTS, VCS
  • area: main
  • in suites: sid
  • size: 518,712 kB
  • sloc: xml: 877,568; f90: 577,240; python: 80,760; perl: 7,019; ansic: 4,585; sh: 1,925; javascript: 601; fortran: 557; cpp: 454; objc: 323; makefile: 77; csh: 42; pascal: 31
file content (94 lines) | stat: -rwxr-xr-x 2,118 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#!/usr/bin/env python
# encoding=utf8
from __future__ import unicode_literals, division, print_function, absolute_import

import tempfile
from subprocess import Popen
import string
import glob,os
import re
import sys
#reload(sys)
try:
    sys.setdefaultencoding('utf8')
except AttributeError:
    pass
from shutil import rmtree

def main(home_dir=""):
  # create tarball
  sys.stdout.write("Creating tarball...\n")

  if home_dir!="":
    bdir = os.path.join(home_dir,"bindings")
    cmd = "cd "+bdir+" && ./configure && make libpaw-bindings && cp libpaw/*tar.gz /tmp"
  else:
    cmd = "cd bindings && ../../bindings/configure && make libpaw-bindings && cp libpaw/*tar.gz /tmp"
  ou = tempfile.TemporaryFile()
  er = tempfile.TemporaryFile()

  process = Popen(cmd, shell=True, stdout=ou, stderr=er)
  process.wait()
  process.communicate()
  rc=process.returncode
  if rc != 0:
     ou.seek(0)
     er.seek(0)
     sys.stdout.write("%s\n" % ou.read())
     sys.stderr.write("%s\n" % er.read())
     ou.close()
     er.close()
     retval = 1
     return retval

  ou.close()
  er.close()
  sys.stdout.write(" done...\n")

  # test tarball
  sys.stdout.write("\nTesting tarball...\n")

  cmd = "cd /tmp;libpaw=`ls libpaw*.tar.gz`; tar xzf $libpaw; cd libpaw; make"
  ou = tempfile.TemporaryFile()
  er = tempfile.TemporaryFile()

  process = Popen(cmd, shell=True, stdout=ou, stderr=er)
  process.wait()
  process.communicate()
  rc=process.returncode
  if rc != 0:
     ou.seek(0)
     er.seek(0)
     sys.stdout.write("%s\n" % ou.read())
     sys.stderr.write("%s\n" % er.read())
     ou.close()
     er.close()
     retval = 1
     return retval

  ou.seek(0)
  er.seek(0)
  sys.stdout.write("%s\n" % ou.read())
# sys.stderr.write("%s\n" % er.read())
  ou.close()
  er.close()

  # cleaning
  retval = 0
  try:
    rmtree("/tmp/libpaw")
    f = glob.glob("/tmp/libpaw*.tar.gz")
    os.remove(f[0])
  except:
    sys.stderr.write("cleaning error")
    retval = 1

  return retval

if __name__ == "__main__":
  if len(sys.argv) == 1:
    home_dir = "."
  else:
    home_dir = sys.argv[1]

  sys.exit(main(home_dir))