Welcome to mirror list, hosted at ThFree Co, Russian Federation.

versioning.py « netrender - git.blender.org/blender-addons.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 31bb2f8b8292b729a9decce9081ef318a864a755 (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
# ##### BEGIN GPL LICENSE BLOCK #####
#
#  This program is free software; you can redistribute it and/or
#  modify it under the terms of the GNU General Public License
#  as published by the Free Software Foundation; either version 2
#  of the License, or (at your option) any later version.
#
#  This program is distributed in the hope that it will be useful,
#  but WITHOUT ANY WARRANTY; without even the implied warranty of
#  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#  GNU General Public License for more details.
#
#  You should have received a copy of the GNU General Public License
#  along with this program; if not, write to the Free Software Foundation,
#  Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
#
# ##### END GPL LICENSE BLOCK #####

import os
import re
import subprocess

from netrender.utils import *

class AbstractVCS:
    name = "ABSTRACT VCS" 
    def __init__(self):
        pass
    
    def update(self, info):
        """update(info)
        Update a working copy to the specified revision.
        If working copy doesn't exist, do a full get from server to create it.
        [info] model.VersioningInfo instance, specifies the working path, remote path and version number."""
        pass
    
    def revision(self, path):
        """revision(path)
        return the current revision of the specified working copy path"""
        pass
    
    def path(self, path):
        """path(path)
        return the remote path of the specified working copy path"""
        pass
    
class Subversion(AbstractVCS):
    name = "Subversion"
    def __init__(self):
        super().__init__()
        self.version_exp = re.compile("([0-9]*)") 
        self.path_exp = re.compile("URL: (.*)") 

    def update(self, info):
        if not os.path.exists(info.wpath):
            base, folder = os.path.split(info.wpath)

            with DirectoryContext(base):
                subprocess.call(["svn", "co", "%s@%s" % (info.rpath, str(info.revision)), folder])
        else:
            with DirectoryContext(info.wpath):
                subprocess.call(["svn", "up", "--accept", "theirs-full", "-r", str(info.revision)])
            
    def revision(self, path):
        if not os.path.exists(path):
            return

        with DirectoryContext(path):
            stdout = subprocess.check_output(["svnversion"])
            
            match = self.version_exp.match(str(stdout, encoding="utf-8"))
            
            if match:
                return match.group(1)
            
    def path(self, path):
        if not os.path.exists(path):
            return

        with DirectoryContext(path):
            stdout = subprocess.check_output(["svn", "info"])
            
            match = self.path_exp.search(str(stdout, encoding="utf-8"))
            
            if match:
                return match.group(1)

class Git(AbstractVCS):
    name = "Git"
    def __init__(self):
        super().__init__()
        self.version_exp = re.compile("^commit (.*)") 

    def update(self, info):
        if not os.path.exists(info.wpath):
            base, folder = os.path.split(info.wpath)

            with DirectoryContext(base):
                subprocess.call(["git", "clone", "%s" % (info.rpath), folder])

        with DirectoryContext(info.wpath):
            subprocess.call(["git", "checkout", str(info.revision)])
            
    def revision(self, path):
        if not os.path.exists(path):
            return

        with DirectoryContext(path):
            stdout = subprocess.check_output(["git", "show"])
            
            match = self.version_exp.search(str(stdout, encoding="utf-8"))
            
            if match:
                return match.group(1)
            
    def path(self, path):
        if not os.path.exists(path):
            return

        # find something that could somehow work for git (fun times)
        return path

SYSTEMS = {
            Subversion.name: Subversion(),
            Git.name: Git()
           }