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 -class darcs(GenericRevisionControlSystem): 
 27      """Class to manage items under revision control of darcs.""" 
28   
29      RCS_METADIR = "_darcs" 
30      SCAN_PARENTS = True 
31       
32 -    def update(self, revision=None): 
 33          """Does a clean update of the given path 
34   
35          @param revision: ignored for darcs 
36          """ 
37           
38          command = ["darcs", "revert", "--repodir", self.root_dir,  
39                  "-a", self.location_rel] 
40          exitcode, output_revert, error = run_command(command) 
41          if exitcode != 0: 
42              raise IOError("[Darcs] error running '%s': %s" % (command, error)) 
43           
44          command = ["darcs", "pull", "--repodir", self.root_dir, "-a"] 
45          exitcode, output_pull, error = run_command(command) 
46          if exitcode != 0: 
47              raise IOError("[Darcs] error running '%s': %s" % (command, error)) 
48          return output_revert + output_pull 
 49   
50 -    def commit(self, message=None): 
 51          """Commits the file and supplies the given commit message if present""" 
52          if message is None: 
53              message = "" 
54           
55          command = ["darcs", "record", "-a", "--repodir", self.root_dir, 
56                  "--skip-long-comment", "-m", message, self.location_rel] 
57          exitcode, output_record, error = run_command(command) 
58          if exitcode != 0: 
59              raise IOError("[Darcs] Error running darcs command '%s': %s" \ 
60                      % (command, error)) 
61           
62          command = ["darcs", "push", "-a", "--repodir", self.root_dir] 
63          exitcode, output_push, error = run_command(command) 
64          if exitcode != 0: 
65              raise IOError("[Darcs] Error running darcs command '%s': %s" \ 
66                      % (command, error)) 
67          return output_record + output_push 
 68   
70          """Get a clean version of a file from the darcs repository 
71   
72          @param revision: ignored for darcs 
73          """ 
74          import os 
75          filename = os.path.join(self.root_dir, self.RCS_METADIR, 'pristine', 
76                  self.location_rel) 
77          try: 
78              darcs_file = open(filename) 
79              output = darcs_file.read() 
80              darcs_file.close() 
81          except IOError, error: 
82              raise IOError("[Darcs] error reading original file '%s': %s" % \ 
83                      (filename, error)) 
84          return output 
  85