1 | """ |
---|
2 | Scrip to clone tagged version of bumps to SasView build system |
---|
3 | |
---|
4 | bumps must be at the same level as the Jenkins %WORKSPACE (i.e. Jenkins_job_name) |
---|
5 | |
---|
6 | ../Jenkins_job_name/ == ../%WORKSPACE/ |
---|
7 | |
---|
8 | ../Jenkins_job_name/ - Working dir for Jenkins jobs |
---|
9 | |
---|
10 | ../Jenkins_job_name/build_tools/ - working directory for build files |
---|
11 | |
---|
12 | ../bumps/ - directory for bumps files. |
---|
13 | - see ../Jenkins_job_name/docs/sphinx-docs/build-sphinx.py |
---|
14 | |
---|
15 | """ |
---|
16 | |
---|
17 | |
---|
18 | import subprocess |
---|
19 | import os |
---|
20 | import shutil |
---|
21 | import errno, stat |
---|
22 | |
---|
23 | |
---|
24 | BUMPS_BRANCH = "v0.7.5.5" |
---|
25 | BUMPS_REPO = 'https://github.com/bumps/bumps' |
---|
26 | CURRENT_SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__)) |
---|
27 | BUMPS_TARGET = os.path.join(CURRENT_SCRIPT_DIR, "..", "..", "bumps") |
---|
28 | |
---|
29 | |
---|
30 | if os.path.isdir(BUMPS_TARGET): |
---|
31 | os.chdir(BUMPS_TARGET) |
---|
32 | out_tag=subprocess.check_output(["git","tag"]) |
---|
33 | os.chdir(CURRENT_SCRIPT_DIR) |
---|
34 | if (out_tag.rstrip() in BUMPS_BRANCH): |
---|
35 | print "bumps version " + BUMPS_BRANCH + " is allready on disk - exit git clone bumps" |
---|
36 | quit() |
---|
37 | |
---|
38 | |
---|
39 | |
---|
40 | |
---|
41 | |
---|
42 | def _remove_dir(dir_path): |
---|
43 | """Removes the given directory.""" |
---|
44 | if os.path.isdir(dir_path): |
---|
45 | print "Removing \"%s\"... " % dir_path |
---|
46 | shutil.rmtree(dir_path,ignore_errors=False,onerror=errorRemoveReadonly) |
---|
47 | |
---|
48 | |
---|
49 | |
---|
50 | def errorRemoveReadonly(func, path, exc): |
---|
51 | excvalue = exc[1] |
---|
52 | if func in (os.rmdir, os.remove) and excvalue.errno == errno.EACCES: |
---|
53 | # change the file to be readable,writable,executable: 0777 |
---|
54 | os.chmod(path, stat.S_IRWXU | stat.S_IRWXG | stat.S_IRWXO) |
---|
55 | # retry |
---|
56 | func(path) |
---|
57 | else: |
---|
58 | print "Error" |
---|
59 | |
---|
60 | |
---|
61 | |
---|
62 | def clean(): |
---|
63 | """ |
---|
64 | Clean the Bumps target directory. |
---|
65 | """ |
---|
66 | print "=== Remove old Bumps Target ===" |
---|
67 | _remove_dir(BUMPS_TARGET) |
---|
68 | |
---|
69 | |
---|
70 | clean() |
---|
71 | |
---|
72 | |
---|
73 | |
---|
74 | |
---|
75 | |
---|
76 | p = subprocess.Popen(["git","clone", "--branch="+BUMPS_BRANCH,"--depth=1", BUMPS_REPO, BUMPS_TARGET], |
---|
77 | stdin=subprocess.PIPE, |
---|
78 | stdout=subprocess.PIPE) |
---|
79 | |
---|
80 | output = p.communicate('S\nL\n')[0] |
---|
81 | print output |
---|