1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23 from translate.storage.versioncontrol import run_command
24 from translate.storage.versioncontrol import GenericRevisionControlSystem
25
26
28 """check if darcs is installed"""
29 exitcode, output, error = run_command(["darcs", "--version"])
30 return exitcode == 0
31
32
33 -class darcs(GenericRevisionControlSystem):
34 """Class to manage items under revision control of darcs."""
35
36 RCS_METADIR = "_darcs"
37 SCAN_PARENTS = True
38
39 - def update(self, revision=None):
40 """Does a clean update of the given path
41
42 @param revision: ignored for darcs
43 """
44
45 command = ["darcs", "revert", "--repodir", self.root_dir,
46 "-a", self.location_rel]
47 exitcode, output_revert, error = run_command(command)
48 if exitcode != 0:
49 raise IOError("[Darcs] error running '%s': %s" % (command, error))
50
51 command = ["darcs", "pull", "--repodir", self.root_dir, "-a"]
52 exitcode, output_pull, error = run_command(command)
53 if exitcode != 0:
54 raise IOError("[Darcs] error running '%s': %s" % (command, error))
55 return output_revert + output_pull
56
57 - def commit(self, message=None, author=None):
58 """Commits the file and supplies the given commit message if present"""
59 if message is None:
60 message = ""
61
62 command = ["darcs", "record", "-a", "--repodir", self.root_dir,
63 "--skip-long-comment", "-m", message]
64
65 if author:
66 command.extend(["--author", author])
67
68 command.append(self.location_rel)
69 exitcode, output_record, error = run_command(command)
70 if exitcode != 0:
71 raise IOError("[Darcs] Error running darcs command '%s': %s" \
72 % (command, error))
73
74 command = ["darcs", "push", "-a", "--repodir", self.root_dir]
75 exitcode, output_push, error = run_command(command)
76 if exitcode != 0:
77 raise IOError("[Darcs] Error running darcs command '%s': %s" \
78 % (command, error))
79 return output_record + output_push
80
82 """Get a clean version of a file from the darcs repository
83
84 @param revision: ignored for darcs
85 """
86 import os
87 filename = os.path.join(self.root_dir, self.RCS_METADIR, 'pristine',
88 self.location_rel)
89 try:
90 darcs_file = open(filename)
91 output = darcs_file.read()
92 darcs_file.close()
93 except IOError, error:
94 raise IOError("[Darcs] error reading original file '%s': %s" % \
95 (filename, error))
96 return output
97