Changeset 512 for CMT


Ignore:
Timestamp:
Jun 18, 2009, 11:25:40 AM (15 years ago)
Author:
rybkin
Message:

See C.L. 401

Location:
CMT/HEAD
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • CMT/HEAD/ChangeLog

    r507 r512  
     12009-06-18    <rybkin@lal.in2p3.fr> 401
     2       
     3        * mgr/cmt_svn_checkout.py: Introduce function trunk_tag to determine
     4        the tag of the module's trunk
     5       
    162009-05-23    <rybkin@lal.in2p3.fr> 400
    27       
  • CMT/HEAD/mgr/cmt_svn_checkout.py

    r501 r512  
    2323"""
    2424
    25 __version__ = '0.1.5'
    26 __date__ = 'Tue May 05 2009'
     25__version__ = '0.2.0'
     26__date__ = 'Thu Jun 18 2009'
    2727__author__ = 'Grigory Rybkin'
    2828
     
    3333import os.path
    3434import urlparse
     35import tempfile
    3536
    3637self = 'cmt_svn_checkout.py'
     
    210211        self.modules.append(module)
    211212
     213    def info_receiver(self, path, info, pool):
     214        self.path = path
     215        self.info = info
     216
     217    def cmp(self, path1, path2, client_context):
     218        outfile = tempfile.TemporaryFile('wb')
     219        errfile = tempfile.TemporaryFile('wb')
     220        outb = outfile.tell()
     221        errb = errfile.tell()
     222        client.diff([]
     223                    , path1
     224                    , self.head_revision
     225                    , path2
     226                    , self.head_revision
     227                    , True, True, False
     228                    , outfile
     229                    , errfile
     230                    , client_context())
     231
     232        # position at the end of the file
     233        outfile.seek(0, 2)
     234        errfile.seek(0, 2)
     235        oute = outfile.tell()
     236        erre = errfile.tell()
     237
     238        if erre > errb: return 2
     239        elif oute > outb: return 1
     240        else: return 0
     241
     242    def trunk_tag(self, module, client_context):
     243        """Attempt to determine the tag of the module's trunk.
     244       
     245        Return the tag if its contents are the same as those of the trunk, and
     246        its last_changed_rev is greater than the trunk created_rev, None otherwise.
     247        """
     248        try:
     249            trunk = core.svn_path_canonicalize(posixpath.join(module.url, self.trunk))
     250            client.info(trunk,
     251                        self.head_revision,
     252                        self.head_revision,
     253                        self.info_receiver,
     254                        False,
     255                        client_context())
     256           
     257            tags = core.svn_path_canonicalize(posixpath.join(module.url, self.tags))
     258            tags_dirent = client.ls(tags,
     259                                    self.head_revision,
     260                                    False,
     261                                    client_context())
     262           
     263            rev_tag = dict([(tags_dirent[p].created_rev, p) for p in tags_dirent if tags_dirent[p].kind == core.svn_node_dir])
     264            revs = rev_tag.keys()
     265            revs.sort()
     266            revs.reverse()
     267
     268            for rev in revs:
     269                if rev < self.info.last_changed_rev: break
     270                tag = core.svn_path_canonicalize(posixpath.join(tags, rev_tag[rev]))
     271                if 0 == self.cmp(trunk, tag, client_context):
     272                    return rev_tag[rev]
     273
     274            return None
     275        except core.SubversionException, e:
     276            return None
     277
    212278    def initialize(self, cmt_context, client_context):
    213279        sc = 0
     
    238304            if self.version is None:
    239305                m.head = True
    240                 tags = core.svn_path_canonicalize(posixpath.join(m.url, self.tags))
    241                 try:
    242                     #print 'client.ls2:', tags
    243                     ls_tags = client.ls2(tags,
    244                                          self.head_revision,
    245                                          self.head_revision,
    246                                          False,
    247                                          client_context())
    248                     rev_tag = dict([(ls_tags[p].created_rev, p) for p in ls_tags if ls_tags[p].kind == core.svn_node_dir])
    249 #                rev_latest = max(rev_tag.keys())
    250 #                tag_latest = rev_tag[rev_latest]
    251                     m.version = rev_tag[max(rev_tag.keys())]
    252                 except core.SubversionException, e:
    253                     error(e)
    254                     #print >> sys.stderr, e
    255                     m.version = 'HEAD'
    256                 except ValueError, e: # max() arg is an empty sequence
    257                     #print >> sys.stderr, e
    258                     m.version = 'HEAD'
     306                m.version = self.trunk_tag(m, client_context) or 'HEAD'
    259307            else:
    260308                m.head = False
Note: See TracChangeset for help on using the changeset viewer.