-
Notifications
You must be signed in to change notification settings - Fork 0
/
merger.py
72 lines (62 loc) · 2.31 KB
/
merger.py
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
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import os
from shutil import rmtree
import time
import subprocess as sp
from subprocess import PIPE
import tempfile
import pysvn
from urllib.parse import urlparse
from config_monitoring import svn_login, svn_password
class SvnClient:
def __init__(self):
self.login = svn_login
self.password = svn_password
self.timeout = 300
def connect(self):
client = pysvn.Client()
client.callback_ssl_server_trust_prompt = lambda dummy: (True, 0, False)
cancel_at = time.time() + self.timeout
client.callback_cancel = lambda: time.time() > cancel_at
client.set_auth_cache(False)
client.set_store_passwords(False)
client.set_interactive(False)
client.set_default_username(self.login)
client.set_default_password(self.password)
return client
def checkout(self, svn_url, folder):
client = SvnClient.connect(self)
try:
client.checkout(svn_url, folder)
return True
except:
return False
class Merger(SvnClient):
def __init__(self):
super().__init__()
def svnWrapper(self, br, tr, cwd):
p = sp.Popen(['svn', 'merge', tr, '--username', self.login, '--password', self.password, '--non-interactive', '--no-auth-cache'],
cwd=cwd, stdout=PIPE, stderr=PIPE, shell=True, universal_newlines=True)
out, err = p.communicate()
mergeResult = out + err
msg = 'Web button: more trunk merged into {0}'.format(br)
p = sp.Popen(
['svn', 'commit', '-m', msg, '--username', self.login, '--password', self.password, '--non-interactive', '--no-auth-cache'],
cwd=cwd, stdout=PIPE, stderr=PIPE, shell=True, universal_newlines=True)
out, err = p.communicate()
commitResult = out + err
return mergeResult + commitResult
def mergeGo(self, branch):
url = ''
path = urlparse(branch).path.split('/')
trunk = os.path.join(url, path[1], path[2], 'trunk').replace('\\', '/')
tempDir = tempfile.mkdtemp()
self.checkout(branch, tempDir)
result = self.svnWrapper(branch, trunk, tempDir)
rmtree(tempDir)
return result
if __name__ == '__main__':
branch = ''
m = Merger()
m.mergeGo(branch)