summaryrefslogtreecommitdiff
path: root/src/backend/syncenv.py
blob: 9e41b7850fc37f5fbfdb355b7961da81b170b204 (plain)
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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
#!/usr/bin/python3

import os
import signal
import subprocess
import sisyphus.getfs


def sigint_handler(signal, frame):
    sys.exit(0)


signal.signal(signal.SIGINT, sigint_handler)


def g_repo():
    os.chdir(sisyphus.getfs.g_src_dir)
    lcl_brch = subprocess.check_output(
        ['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
    rmt_brch = subprocess.check_output(
        ['git', 'rev-parse', '--symbolic-full-name', '@{u}'])

    g_exe1 = subprocess.Popen(['git', 'fetch', '--depth=1', 'origin'] +
                              lcl_brch.decode().strip().split() + ['--quiet'], stdout=subprocess.PIPE)
    try:
        g_exe1.wait()
    except KeyboardInterrupt:
        g_exe1.terminate()
        try:
            g_exe1.wait(1)
        except subprocess.TimeoutExpired:
            g_exe1.kill()
        sys.exit()

    g_exe2 = subprocess.Popen(['git', 'reset', '--hard'] + rmt_brch.decode().strip(
    ).replace('refs/remotes/', '').split() + ['--quiet'], stdout=subprocess.PIPE)
    try:
        g_exe2.wait()
    except KeyboardInterrupt:
        g_exe2.terminate()
        try:
            g_exe2.wait()
        except subprocess.TimeoutExpired:
            g_exe2.kill()
        sys.exit()


def r_repo():
    os.chdir(sisyphus.getfs.r_src_dir)
    lcl_brch = subprocess.check_output(
        ['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
    rmt_brch = subprocess.check_output(
        ['git', 'rev-parse', '--symbolic-full-name', '@{u}'])

    g_exe1 = subprocess.Popen(['git', 'fetch', '--depth=1', 'origin'] +
                              lcl_brch.decode().strip().split() + ['--quiet'], stdout=subprocess.PIPE)
    try:
        g_exe1.wait()
    except KeyboardInterrupt:
        g_exe1.terminate()
        try:
            g_exe1.wait(1)
        except subprocess.TimeoutExpired:
            g_exe1.kill()
        sys.exit()

    g_exe2 = subprocess.Popen(['git', 'reset', '--hard'] + rmt_brch.decode().strip(
    ).replace('refs/remotes/', '').split() + ['--quiet'], stdout=subprocess.PIPE)
    try:
        g_exe2.wait()
    except KeyboardInterrupt:
        g_exe2.terminate()
        try:
            g_exe2.wait(1)
        except subprocess.TimeoutExpired:
            g_exe2.kill()
        sys.exit()


def p_cfg_repo():
    os.chdir(sisyphus.getfs.p_cfg_dir)
    lcl_brch = subprocess.check_output(
        ['git', 'rev-parse', '--abbrev-ref', 'HEAD'])
    rmt_brch = subprocess.check_output(
        ['git', 'rev-parse', '--symbolic-full-name', '@{u}'])

    g_exe1 = subprocess.Popen(['git', 'stash'], stdout=subprocess.PIPE)
    try:
        g_exe1.wait()
    except KeyboardInterrupt:
        g_exe1.terminate()
        try:
            g_exe1.wait(1)
        except subprocess.TimeoutExpired:
            g_exe1.kill()
        sys.exit()
    g_exe2 = subprocess.Popen(['git', 'fetch', '--depth=1', 'origin'] +
                              lcl_brch.decode().strip().split() + ['--quiet'], stdout=subprocess.PIPE)
    try:
        g_exe2.wait()
    except KeyboardInterrupt:
        g_exe2.terminate()
        try:
            g_exe2.wait(1)
        except subprocess.TimeoutExpired:
            g_exe2.kill()
        sys.exit()
    g_exe3 = subprocess.Popen(['git', 'reset', '--hard'] + rmt_brch.decode().strip(
    ).replace('refs/remotes/', '').split() + ['--quiet'], stdout=subprocess.PIPE)
    try:
        g_exe3.wait()
    except KeyboardInterrupt:
        g_exe3.terminate()
        try:
            g_exe3.wait(1)
        except subprocess.TimeoutExpired:
            g_exe3.kill()
        sys.exit()
    g_exe4 = subprocess.Popen(
        ['git', 'stash', 'apply'], stdout=subprocess.PIPE)
    try:
        g_exe4.wait()
    except KeyboardInterrupt:
        g_exe4.terminate()
        try:
            g_exe4.wait(1)
        except subprocess.TimeoutExpired:
            g_exe4.kill()
        sys.exit()
    g_exe5 = subprocess.Popen(
        ['git', 'stash', 'clear'], stdout=subprocess.PIPE)
    try:
        g_exe5.wait()
    except KeyboardInterrupt:
        g_exe5.terminate()
        try:
            g_exe5.wait(1)
        except subprocess.TimeoutExpired:
            g_exe5.kill()
        sys.exit()
    g_exe6 = subprocess.Popen(
        ['git', 'gc', '--prune=now', '--quiet'], stdout=subprocess.PIPE)
    try:
        g_exe6.wait()
    except KeyboardInterrupt:
        g_exe6.terminate()
        try:
            g_exe6.wait(1)
        except subprocess.TimeoutExpired:
            g_exe6.kill()
        sys.exit()