"""
    libredo/Repotool

    Tool for checking out layers from git.

    (This is not the android repo-tool, but 
    a replacement thereof in the scope of Redomat.)
"""

import time, os

class Repotool:

    def __init__(self, _declaration):
        """
            a builder for yocto using docker to support builds on top of other builds
        """
        self.declaration = _declaration

    def checkout(self, destpath, git_url, revision):
        cmds = []
        cmds.append("( mkdir -pv %s ; cd %s ; [ ! -d .git ] && git init )"%
                (destpath, destpath))
        cmds.append("( cd %s ; git remote add declremote %s ; git fetch )"%
                (destpath, git_url))
        cmds.append("( cd %s ; git checkout -b declrev %s )"%
                (destpath, revision))
        return cmds

    def checkout_all(self, checkout_dir):
        cmds = []
        for layername, layer in self.declaration.layers.iteritems():
            assert(layername == layer['name'])
            remote = self.declaration.layer_remotes.get(layer['remote'])
            repo = layer['repo']
            revision = layer['revision']
            git_url = "/".join([remote, repo])
            cmds.extend(self.checkout(checkout_dir, git_url, revision))
        return cmds

# vim:expandtab:ts=4

@@ -180,16 +180,22 @@
 time, os
+, uuid
 %0A%0Aclass 
@@ -240,16 +240,33 @@
 laration
+, _branch_id=None
 ):%0A     
@@ -419,120 +419,332 @@
     
-def checkout(self, destpath, git_url, revision):%0A        cmds = %5B%5D%0A        cmds.append(%22( mkdir -pv %25s ; cd %25s ;
+    self.branch_id = _branch_id%0A        if not self.branch_id:%0A            self.branch_id = %22%25s-%25s%22%25(time.strftime(%22%25F-%25H%25M%25S%22), uuid.uuid1())%0A%0A    def checkout(self, destpath, git_url, revision):%0A        cmds = %5B%5D%0A        cmds.append(%22%22%22%0A        if %5B ! -d %25s %5D ; then %0A            mkdir -pv %25s%0A            cd %25s%0A           
  %5B !
@@ -765,20 +765,17 @@
 git init
- )%22%25
+%0A
 %0A       
@@ -783,144 +783,214 @@
     
-    (destpath, destpath))%0A        cmds.append(%22( cd %25s ; git remote add declremote %25s ; git fetch )%22%25%0A                (destpath, git_url
+git remote add declremote %25s %0A            git fetch declremote%0A        else%0A            cd %25s%0A            git fetch declremote%0A        fi%22%22%22%25%0A                (destpath, destpath, destpath, git_url, destpath
 ))%0A 
@@ -1042,16 +1042,18 @@
  declrev
+%25s
  %25s )%22%25%0A
@@ -1078,16 +1078,32 @@
 estpath,
+ self.branch_id,
  revisio
@@ -1488,16 +1488,27 @@
 (%5Bremote
+%5B'baseurl'%5D
 , repo%5D)

add a uuid to the repotool class so it can be used to generate branch names