Guest User

Untitled

a guest
Sep 4th, 2018
108
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.92 KB | None | 0 0
  1. from subprocess import call
  2.  
  3. SVN_CONF = '''[general]
  4. anon-access = none
  5. auth-access = write
  6. password-db = passwd
  7. authz-db = authz
  8. '''
  9.  
  10. SVN_PASSWD = '''[users]
  11. {user} = {password}
  12. '''
  13.  
  14. SVN_AUTHZ = '''[groups]
  15. admin = {user}
  16.  
  17. [/]
  18. * = r
  19. @admin = rw
  20. '''
  21.  
  22. class SVNServer(object):
  23. def __init__(self, root, name, user, password):
  24. self.root = '{0}{1}'.format(root, name)
  25. self.passwd = SVN_PASSWD.format(user = user, password = password)
  26. self.passwd_path = '{0}/conf/passwd'.format(self.root)
  27. self.authz = SVN_AUTHZ.format(user = user)
  28. self.authz_path = '{0}/conf/authz'.format(self.root)
  29. self.conf_path = '{0}/conf/svnserve.conf'.format(self.root)
  30.  
  31. self.log_file = '{0}.log'.format(self.root)
  32. self.pid_file = '{0}.pid'.format(self.root)
  33.  
  34. def __enter__(self):
  35. call(["svnadmin", "create", self.root])
  36. with open(self.passwd_path, 'w') as f:
  37. f.write(self.passwd)
  38. with open(self.authz_path, 'w') as f:
  39. f.write(self.authz)
  40. with open(self.conf_path, 'w') as f:
  41. f.write(SVN_CONF)
  42. call([
  43. "svnserve", "--daemon",
  44. "--root", self.root,
  45. "--log-file", self.log_file,
  46. "--pid-file", self.pid_file
  47. ])
  48. return self
  49.  
  50. def __exit__(self, *args):
  51. try:
  52. with open(self.pid_file, 'r') as f:
  53. call(["kill", "-9", f.read().strip()])
  54. finally:
  55. call(["rm", self.pid_file])
  56. call(["rm", self.log_file])
  57. call(["rm", "-rf", self.root])
  58.  
  59.  
  60. if __name__ == '__main__':
  61. from time import sleep
  62. def keyboard_loop():
  63. while True:
  64. try:
  65. sleep(1)
  66. except KeyboardInterrupt:
  67. break
  68.  
  69. with SVNServer('./', 'myRepos', 'guest', 'guest') as server:
  70. try:
  71. # DO SOMETHING
  72. keyboard_loop()
  73. finally:
  74. # CLEAN
Add Comment
Please, Sign In to add comment