~jens-persson/quickly/version-control

« back to all changes in this revision

Viewing changes to quickly/vchelpers.py

  • Committer: jens persson
  • Date: 2010-01-14 21:59:26 UTC
  • Revision ID: jens@kirk-20100114215926-r0p6tmnk0u55ky11
First shot att adding support for diffrent vc systems

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
from quickly import configurationhandler
 
2
import subprocess
 
3
 
 
4
class revisionsystem(object):
 
5
    def __init__(self):
 
6
        if not configurationhandler.project_config:
 
7
            configurationhandler.loadConfig()
 
8
        if not configurationhandler.global_config:
 
9
            configurationhandler.loadConfig(get_global=True)
 
10
 
 
11
        revision_system = configurationhandler.global_config.get('revision_system', 'bzr')
 
12
        print ">>", revision_system
 
13
        revision_system = configurationhandler.project_config.get('revision_system', revision_system)
 
14
        print ">>", revision_system
 
15
        self.handler = handlers[revision_system]()
 
16
    def init(self):
 
17
        self.handler.init()
 
18
    def commit(self, comment):
 
19
        self.handler.commit(comment)
 
20
    def add_files(self, files=None):
 
21
        self.handler.add_files(files)
 
22
    def tag(self, comment):
 
23
        self.handler.tag()
 
24
    def get_files_to_ignore(self):
 
25
        self.handler.get_files_to_ignore()
 
26
 
 
27
class vcs_base_handler(object):
 
28
    def __init__(self, binary):
 
29
        self.binary=binary
 
30
    def init(self):
 
31
        subprocess.call([self.binary, "init"])
 
32
        self.add_files()
 
33
 
 
34
    def commit(self,comment):
 
35
        subprocess.call([self.binary, "commit", "-m", comment])
 
36
 
 
37
    def add_files(self, files=None):
 
38
        if files == None:
 
39
            subprocess.call([self.binary, "add"])
 
40
        else:
 
41
            subprocess.call([self.binary, "add"] + files)
 
42
 
 
43
    def tag(self, comment):
 
44
        subprocess.call([self.binary, "tag", comment])
 
45
 
 
46
    def get_files_to_ignore(self):
 
47
        return ["."+self.binary]
 
48
 
 
49
class bzr_handler(vcs_base_handler):
 
50
    def __init__(self):
 
51
        super(bzr_handler, self).__init__("bzr")
 
52
 
 
53
class hg_handler(vcs_base_handler):
 
54
    def __init__(self):
 
55
        super(hg_handler, self).__init__("hg")
 
56
 
 
57
class svn_handler(object):
 
58
    def __init__(self):
 
59
        raise NotImplementedError
 
60
 
 
61
    def init(self):
 
62
        # subprocess.call(["hg", "init"])
 
63
        self.add()
 
64
 
 
65
    def commit(self,comment):
 
66
        subprocess.call(["svn", "commit", "-m", comment])
 
67
 
 
68
    def add_files(self, files):
 
69
        if files == None:
 
70
            files = subprocess.call(["svn", "add"])
 
71
        else:
 
72
            subprocess.call(["svn", "add"] + files)
 
73
 
 
74
    def tag(self, comment):
 
75
        subprocess.call(["svn", "tag", comment])
 
76
 
 
77
    def get_files_to_ignore(self):
 
78
        return [".svn"]
 
79
 
 
80
handlers = {
 
81
        'bzr': bzr_handler,
 
82
        'hg': hg_handler,
 
83
        'svn': svn_handler,
 
84
        }