Extensions: change the constant for the complete status
[blender-addons-contrib.git] / netrender / versioning.py
blobcae75bf6e97eafa1f814a5c85700163f085df26c
1 # ##### BEGIN GPL LICENSE BLOCK #####
3 # This program is free software; you can redistribute it and/or
4 # modify it under the terms of the GNU General Public License
5 # as published by the Free Software Foundation; either version 2
6 # of the License, or (at your option) any later version.
8 # This program is distributed in the hope that it will be useful,
9 # but WITHOUT ANY WARRANTY; without even the implied warranty of
10 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 # GNU General Public License for more details.
13 # You should have received a copy of the GNU General Public License
14 # along with this program; if not, write to the Free Software Foundation,
15 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 # ##### END GPL LICENSE BLOCK #####
19 import os
20 import re
21 import subprocess
23 from netrender.utils import *
25 class AbstractVCS:
26 name = "ABSTRACT VCS"
27 def __init__(self):
28 pass
30 def update(self, info):
31 """update(info)
32 Update a working copy to the specified revision.
33 If working copy doesn't exist, do a full get from server to create it.
34 [info] model.VersioningInfo instance, specifies the working path, remote path and version number."""
35 pass
37 def revision(self, path):
38 """revision(path)
39 return the current revision of the specified working copy path"""
40 pass
42 def path(self, path):
43 """path(path)
44 return the remote path of the specified working copy path"""
45 pass
47 class Subversion(AbstractVCS):
48 name = "Subversion"
49 description = "Use the Subversion version control system"
50 def __init__(self):
51 super().__init__()
52 self.version_exp = re.compile("([0-9]*)")
53 self.path_exp = re.compile("URL: (.*)")
55 def update(self, info):
56 if not os.path.exists(info.wpath):
57 base, folder = os.path.split(info.wpath)
59 with DirectoryContext(base):
60 subprocess.call(["svn", "co", "%s@%s" % (info.rpath, str(info.revision)), folder])
61 else:
62 with DirectoryContext(info.wpath):
63 subprocess.call(["svn", "up", "--accept", "theirs-full", "-r", str(info.revision)])
65 def revision(self, path):
66 if not os.path.exists(path):
67 return
69 with DirectoryContext(path):
70 stdout = subprocess.check_output(["svnversion"])
72 match = self.version_exp.match(str(stdout, encoding="utf-8"))
74 if match:
75 return match.group(1)
77 def path(self, path):
78 if not os.path.exists(path):
79 return
81 with DirectoryContext(path):
82 stdout = subprocess.check_output(["svn", "info"])
84 match = self.path_exp.search(str(stdout, encoding="utf-8"))
86 if match:
87 return match.group(1)
89 class Git(AbstractVCS):
90 name = "Git"
91 description = "Use the Git distributed version control system"
92 def __init__(self):
93 super().__init__()
94 self.version_exp = re.compile("^commit (.*)")
96 def update(self, info):
97 if not os.path.exists(info.wpath):
98 base, folder = os.path.split(info.wpath)
100 with DirectoryContext(base):
101 subprocess.call(["git", "clone", "%s" % (info.rpath), folder])
103 with DirectoryContext(info.wpath):
104 subprocess.call(["git", "checkout", str(info.revision)])
106 def revision(self, path):
107 if not os.path.exists(path):
108 return
110 with DirectoryContext(path):
111 stdout = subprocess.check_output(["git", "show"])
113 match = self.version_exp.search(str(stdout, encoding="utf-8"))
115 if match:
116 return match.group(1)
118 def path(self, path):
119 if not os.path.exists(path):
120 return
122 # find something that could somehow work for git (fun times)
123 return path
125 SYSTEMS = {
126 Subversion.name: Subversion(),
127 Git.name: Git()
130 ITEMS = (
131 (Subversion.name, Subversion.name, Subversion.description),
132 (Git.name, Git.name, Git.description),