# # # patch "README" # from [cb698a1ab982cb7b97b3797274da7f16d9369302] # to [939848f90065a823533afc8bc8cc378888b5ab55] # # patch "tracmtn/automate.py" # from [391729a1cc7e1fb0d63cdcce168e57e421de28c0] # to [e690c76f9e846869da4ce989ef87b775484e99b8] # ============================================================ --- README cb698a1ab982cb7b97b3797274da7f16d9369302 +++ README 939848f90065a823533afc8bc8cc378888b5ab55 @@ -18,13 +18,12 @@ Prerequisites - * A Monotone 0.29 (or later) binary. 0.31 (or later) is recommended, - because it has some important improvements for the 'automate stdio' - subcommand used by TracMonotone. + * A Monotone 0.46 (or later) binary. * Python 2.4. - * An installation of Trac. You can either use 0.10.X or 0.11b1. + * An installation of Trac. You can either use 0.10.X or 0.11.X, but + support for 0.10.X is likely to be dropped soon. * Python setuptools >= 0.6. ============================================================ --- tracmtn/automate.py 391729a1cc7e1fb0d63cdcce168e57e421de28c0 +++ tracmtn/automate.py e690c76f9e846869da4ce989ef87b775484e99b8 @@ -45,6 +45,7 @@ class Automate(object): (binary, '--norc', '--root=.', '--automate-stdio-size=1048576', '--db=%s' % database, 'automate', 'stdio'), stdin=PIPE, stdout=PIPE, stderr=None) + self.headers = self.read_headers() self.lock = Lock() def _write(self, data): @@ -59,6 +60,10 @@ class Automate(object): """Read maxlen bytes from automate process.""" return self.process.stdout.read(maxlen) + def _readline(self, maxlen = -1): + """Read a line, or at most maxlen bytes.""" + return self.process.stdout.readline(maxlen) + def _read_until_colon(self): """Return bytes until and excluding next colon.""" result = '' @@ -74,21 +79,19 @@ class Automate(object): def _read_packet(self): """Read exactly one chunk of Monotone automate output.""" _ = self._read_until_colon() # ignore the cmd number - status = int(self._read_until_colon()) cont = self._read_until_colon() size = int(self._read_until_colon()) val = self._read(size) - return status, cont, val + return cont, val def _get_result(self): """Read and concatenate the result packets.""" result = '' while True: - status, cont, val = self._read_packet() - result += val + cont, val = self._read_packet() if cont == 'l': - break - return status, result + return int(val), result + result += val def _write_cmd(self, cmd, args, opts): """Assemble the cmdline from command, args and opts and send @@ -114,6 +117,16 @@ class Automate(object): self._write(cmdstring) self._flush() + def read_headers(self): + headers = {} + while True: + line = self._readline().rstrip('\n') + if not line: + break + key, value = map(lambda s: s.strip(), line.split(':')) + headers[key] = value + return headers + def command(self, cmd, args=[], opts={}): """Send a command to mtn. Returns a tuple (status, result).""" # critical region: only one thread may send a command and read