Esempio n. 1
0
def use_tempdir(temp_dir):
    try:
        utils.mkdirTree(temp_dir)
    except:
        pass

    if not os.path.isdir(temp_dir):
        print "cannot create temp directory=\"%s\"" % (temp_dir)
        sys.exit(1)

    os.chdir(temp_dir)
Esempio n. 2
0
def use_tempdir(temp_dir):
    try:
        utils.mkdirTree(temp_dir)
    except:
        pass

    if not os.path.isdir(temp_dir):
        print "cannot create temp directory=\"%s\"" % (temp_dir)
        sys.exit(1)

    os.chdir(temp_dir)
Esempio n. 3
0
    def checkout(self,
                 tag,
                 module_list,
                 az=None,
                 timestamp=None,
                 nonrecursive=0,
                 checkout_dir=None):
        log.trace(
            'entry',
            [tag, module_list, az, timestamp, nonrecursive, checkout_dir])
        import distributions

        if not checkout_dir:
            checkout_dir = "."

        if az:
            tmpdirbase = os.path.join(checkout_dir, os.path.dirname(az), "cvs")
        else:
            tmpdirbase = os.path.join(checkout_dir, "cvs")

        distributions.setup(tmpdirbase)
        tmpdir = distributions.tmpdir(tmpdirbase)

        if az:
            t = os.path.join(tmpdir, "tmp")
            self.update(tag, module_list, t, timestamp, nonrecursive)
            if os.path.exists(t):
                utils.mkdirTree(os.path.dirname(az))
                outmsg.verbose("Moving %s to %s" % (t, az))
                shell.move(t, az)
        else:
            out_dirs = self.update(tag, module_list, az, timestamp,
                                   nonrecursive, tmpdir)
            #print out_dirs
            for d in out_dirs:
                rl = os.path.join(checkout_dir, d[len(tmpdir) + 1:])
                if os.path.exists(d):
                    outmsg.verbose("Moving %s to %s" % (d, rl))
                    utils.mkdirTree(os.path.dirname(rl))
                    if d[len(tmpdir) + 1:] == ".":
                        for tmp in os.listdir(d):
                            outmsg.verbose(
                                "Moving %s to %s" %
                                (os.path.join(d, tmp), os.path.join(rl, tmp)))
                            shell.move(os.path.join(d, tmp),
                                       os.path.join(rl, tmp))
                    else:
                        shell.move(d, rl)
                else:
                    print "%s does not exists" % d

        distributions.cleanup(tmpdirbase)
        log.trace('exit')
Esempio n. 4
0
    def checkout(self, tag, module_list, az = None, timestamp = None, nonrecursive = 0, checkout_dir = None):
        log.trace( 'entry' , [ tag , module_list , az , timestamp , nonrecursive , checkout_dir ] )
        import distributions
               
        if not checkout_dir:
            checkout_dir="."

        if az:
            tmpdirbase=os.path.join(checkout_dir, os.path.dirname(az), "cvs")
        else:    
            tmpdirbase=os.path.join(checkout_dir, "cvs")
        
        distributions.setup(tmpdirbase)
        tmpdir=distributions.tmpdir(tmpdirbase)

        if az:
            t=os.path.join(tmpdir,"tmp")
            self.update( tag, module_list,t , timestamp, nonrecursive)
            if os.path.exists(t):
                utils.mkdirTree(os.path.dirname(az))
                outmsg.verbose("Moving %s to %s" % (t,az))
                shell.move(t, az)
        else:
            out_dirs=self.update( tag, module_list, az, timestamp, nonrecursive, tmpdir)
            #print out_dirs
            for d in out_dirs:
                rl=os.path.join(checkout_dir, d[len(tmpdir)+1:])
                if os.path.exists(d):
                    outmsg.verbose("Moving %s to %s" % (d, rl))
                    utils.mkdirTree(os.path.dirname(rl))
                    if d[len(tmpdir)+1:] == ".":
                        for tmp in os.listdir(d):
                            outmsg.verbose("Moving %s to %s" % (os.path.join(d,tmp), os.path.join(rl, tmp)))
                            shell.move(os.path.join(d,tmp), os.path.join(rl, tmp))
                    else:
                        shell.move(d, rl)
                else:
                    print "%s does not exists" % d

        distributions.cleanup(tmpdirbase)
        log.trace( 'exit' )
Esempio n. 5
0
    def update(self,
               tag,
               module_list,
               az=None,
               timestamp=None,
               nonrecursive=0,
               checkout_dir=None):
        # print "TAG = %s" % tag
        # print "TIMESTAMP = %s" % timestamp

        if checkout_dir == None:
            checkout_dir = os.curdir

        cmd = "cvs"

        if self.root:
            if self.shadow:
                cmd = "%s -d %s" % (cmd, self.shadow)
            else:
                cmd = "%s -d %s" % (cmd, self.root)

        cmd = "%s checkout" % cmd

        if nonrecursive:
            cmd = cmd + " -l"

        if len(tag):
            if tag == "HEAD":
                cmd = "%s -A" % cmd
            else:
                cmd = '%s -r "%s"' % (cmd, tag)

        if timestamp:
            cmd = '%s -D "%s"' % (cmd, timestamp)

        out_dirs = []
        for x in module_list:
            #print "%s" % repr( [checkout_dir] + string.split(x,"/"))
            out_dirs.append(
                apply(os.path.join, [checkout_dir] + string.split(x, "/")))

        as_arg = ""
        if az:
            dir, base = os.path.split(az)
            if dir:
                utils.mkdirTree(dir)
                checkout_dir = dir
            cmd = "%s -d %s" % (cmd, base)
            out_dirs = [az]

        cmd = "%s %s" % (cmd, string.join(module_list))
        outmsg.verbose(
            "running %s in %s + %s (as = %s)" %
            (repr(cmd), repr(os.getcwd()), repr(checkout_dir), repr(az)))

        def line_cb(line):
            outmsg.verbose(string.strip(line))

        # Tenacious cvs checkout loop, tries <num_cvs_retries> times before
        # failing.
        for N in range(0, num_cvs_retries):
            retcode, output = shell.run(cmd, line_cb, dir=checkout_dir)
            if retcode:
                # If we have a fatal error as determined by error output
                # matching any of the following strings, then we will abort out
                # of the retry loop.
                if string.find(output, "cannot find module") != -1:
                    break
                if string.find(output, "cannot expand modules") != -1:
                    break
                if string.find(output,
                               "cannot open CVS/Entries for reading") != -1:
                    break
                if string.find(output, "Cannot access ") != -1:
                    break
                if string.find(output, "Can't parse date/time") != -1:
                    break
                if string.find(
                        output,
                        "is modified but no longer in the repository") != -1:
                    break
                if string.find(output, "\nC ") != -1:
                    break
                # We didn't abort, so we'll assume non-fatal error, log the
                # error, and try again.
                log.info(
                    "CVS command failed with error code %d, trying again in a few seconds."
                    % retcode)
                time.sleep(1 + N * 5)
            else:
                break

        dirs = out_dirs[:]
        for dir in dirs:
            if os.path.isdir(dir):

                ## Create a timestamp file
                timestamp = os.path.join(dir, "CVS", "timestamp")
                shell.rm(timestamp)
                try:
                    open(timestamp, "w").write(str(int(time.time())))
                except IOError:
                    continue

                if self.shadow:
                    for subdir in os.listdir(dir):
                        if string.lower(subdir) != "cvs":
                            subdir = os.path.join(dir, subdir)
                            if os.path.isdir(subdir):
                                dirs.append(subdir)

                    rootfile = os.path.join(dir, "CVS", "Root")
                    open(rootfile, "w").write("%s\n" % self.root)

        #print "ODIRS: %s" % repr(out_dirs)
        return out_dirs
Esempio n. 6
0
def run():
    global include_list
    global gnumake

    ## Que?
    sys.setcheckinterval(50)

    magic = "# Dependency magic by $Id: mkdepend_exe.py,v 1.2 2006/07/06 19:28:05 jfinnecy Exp $\n"
    obj_path, makefile, source_list = parse_args(sys.argv[1:])

    if makefile:
        if not os.path.isfile(makefile):
            print "Makefile=\"%s\" not found." % (makefile)
            sys.exit(1)
    else:
        if not gnumake:
            print "No Makefile specified."
            sys.exit(1)

    init_platform()
    
    if makefile:
        makefile_data = open(makefile, "r").read()
        if gnumake and string.find(makefile_data,magic)!=-1:
            print "Dependencies have already been updated automagically."
            sys.exit(0)
        
    # Get system include path (Windows way)
    #incpath=os.environ.get("include")
    #if incpath:
    #    include_list = include_list + string.split(incpath,';')

    #incpath=os.environ.get("C_INCLUDE_PATH")
    # Get system include path (UNIX way)
    #if incpath:
    #    include_list = include_list + string.split(incpath,':')

    mrlist = [
        "# DO NOT DELETE -- mkdepend depends on this line\n"
        ]
    extentions={".c":1, ".cc":1, ".cxx":1 }
    all_files={}
    for source in source_list:
        (base, ext) = os.path.splitext(source)
        extentions[ext]=1

        base = os.path.normpath(base)
        if os.path.isabs(base):
            base = string.replace(base,"\\","_")
            base = string.replace(base,":","_")
            base = string.replace(base,"/","_")
        else:
            ## Trim off any ../ from the beginning of the path
            base = string.replace(base,"\\","/")
            tmp = string.split(base, "/")
            x = 0
            while len(tmp) > x + 1:
                if tmp[x] in [ os.curdir, os.pardir ]:
                    x = x + 1
                else:
                    break
            if x:
                tmp = [ "par%d" % x ] + tmp[x:]
            base = string.join(tmp,os.sep)

        path = os.path.join(obj_path, base)

        if string.lower(ext) == ".rc":
            obj = "%s.%s" % (path, "res")
        else:
            obj = "%s.%s" % (path, object_ext)

        dep = "%s.%s" % (path, "dep")

        deptime = mtime(dep)

        if deptime:
            tmp_rules=open(dep,"r").readlines()

            mt=mtime(dep+"-flist")
            if mt and mt <= deptime:
                hlist=string.split(open(dep+"-flist","r").read(),"\n")
            else:
                hlist = []
                for l in tmp_rules:
                    l = string.split(l,":")

                    ## Patchlet for stupid windows path names
                    if len(l)>1 and len(l[0]) == 1:
                        l = [ l[0] +":"+l[1] ] + l[2:]

                    if len(l):
                        file = string.strip(string.join(l[1:],":"))
                        file = unquote_dep(file)
                        hlist.append(file)

            for file in hlist:
                #print "Checking times for %s (%s >? %s)" % (repr(file), repr(mtime(file)), repr(deptime))
                mt = mtime(file)
                if mt > deptime or mt == 0:
                    deptime = 0
                    break


        if not deptime:
            hlist = ReadSourceFile(source)
            tmp_rules=None

        global prefix_includes
        for pi in prefix_includes:
            if pi not in hlist:
                hlist.extend( ReadSourceFile(pi) )
                tmp_rules=None
    
        if gnumake:
            obj = "%s %s.dep" % (obj, obj_path)

        if tmp_rules:
            tmp=tmp_rules
        else:
            tmp = MakefileRuleList(obj, hlist)

        if not deptime:
            utils.mkdirTree(path)
            open(dep+"-flist", "w").write(string.join(hlist, "\n"))
            open(dep, "w").write(string.join(tmp, ""))

        if not gnumake:
            mrlist.extend(tmp)

        for file in hlist:
            all_files[file]=1

    if not makefile:
        sys.exit(0)
        
    if gnumake:
        tmplist=[]
        p = obj_path
        while p not in [ "", ".", "..", ":" ]:
            tmplist.append('\t@test -d %s || mkdir %s\n' % (p,p))
            p = os.path.dirname(p)

        tmplist.reverse()
        tmplist.append('\t%s %s --gnumake -t%s $?\n' % (sys.executable, sys.argv[0], obj_path))

        mrlist.append(magic)
        mrlist.append('ifneq ($MAKECMDGOALS),clean)\n')
        mrlist.append('-include $(COMPILED_OBJS:.%s=.dep)\n' % object_ext)
        mrlist.append('endif\n')
        for ext in extentions.keys():
            mrlist.append('\n')
            mrlist.append('%s/%%.dep: %%%s\n' % (obj_path, ext))
            mrlist.extend(tmplist)
        mrlist.append('\n')

    mrlist.append('\n')

    fil = open(makefile, "w")
    fil.write(makefile_data[:string.find(makefile_data,"# DO NOT DELETE")])
    fil.write(string.join(mrlist,""))
    fil.close()

    fil = open(makefile+"-mkdep.o","w")
    fil.write(string.join(all_files.keys(),"\n"))
    fil.close()

    sys.setcheckinterval(10)
    sys.exit(0)
Esempio n. 7
0
    def update(self, tag, module_list, az = None, timestamp = None, nonrecursive = 0, checkout_dir = None):
        # print "TAG = %s" % tag
        # print "TIMESTAMP = %s" % timestamp

        if checkout_dir == None:
            checkout_dir = os.curdir
            
        cmd = "cvs"
        
        if self.root:
            if self.shadow:
                cmd = "%s -d %s" % (cmd, self.shadow)
            else:
                cmd = "%s -d %s" % (cmd, self.root)

        cmd = "%s checkout" % cmd

        if nonrecursive:
            cmd = cmd + " -l"

        if len(tag):
            if tag == "HEAD":
                cmd = "%s -A" % cmd
            else:
                cmd = '%s -r "%s"' % (cmd, tag)

        if timestamp:
            cmd = '%s -D "%s"' % (cmd, timestamp)

        out_dirs = []
        for x in module_list:
            #print "%s" % repr( [checkout_dir] + string.split(x,"/"))
            out_dirs.append(apply(os.path.join, [checkout_dir] +
                                  string.split(x,"/")))

        as_arg = ""
        if az:
            dir, base = os.path.split(az)
            if dir:
                utils.mkdirTree(dir)
                checkout_dir = dir
            cmd = "%s -d %s" % (cmd , base)
            out_dirs = [az]

        cmd = "%s %s" % (cmd, string.join(module_list))
        outmsg.verbose("running %s in %s + %s (as = %s)" % (repr(cmd), repr(os.getcwd()), repr(checkout_dir), repr(az)))
        def line_cb(line):
            outmsg.verbose(string.strip(line))

        # Tenacious cvs checkout loop, tries <num_cvs_retries> times before
        # failing.
        for N in range(0, num_cvs_retries):
            retcode, output = shell.run(cmd, line_cb, dir = checkout_dir)
            if retcode:
                # If we have a fatal error as determined by error output 
                # matching any of the following strings, then we will abort out 
                # of the retry loop.
                if string.find(output,"cannot find module") != -1:
                    break
                if string.find(output,"cannot expand modules")!=-1:
                    break
                if string.find(output,"cannot open CVS/Entries for reading")!=-1:
                    break
                if string.find(output,"Cannot access ")!=-1:
                    break
                if string.find(output,"Can't parse date/time")!=-1:
                    break
                if string.find(output,"is modified but no longer in the repository")!=-1:
                    break
                if string.find(output,"\nC ")!=-1:
                    break
                # We didn't abort, so we'll assume non-fatal error, log the
                # error, and try again.
                log.info( "CVS command failed with error code %d, trying again in a few seconds." % retcode )
                time.sleep(1 + N*5)
            else:
                break

        dirs = out_dirs[:]
        for dir in dirs:
            if os.path.isdir(dir):

                ## Create a timestamp file
                timestamp=os.path.join(dir, "CVS", "timestamp")
                shell.rm(timestamp)
                try:
                    open(timestamp,"w").write(str(int(time.time())))
                except IOError:
                    continue

                if self.shadow:
                    for subdir in os.listdir(dir):
                        if string.lower(subdir) != "cvs":
                            subdir=os.path.join(dir, subdir)
                            if os.path.isdir(subdir):
                                dirs.append(subdir)

                    rootfile = os.path.join(dir, "CVS", "Root")
                    open(rootfile,"w").write("%s\n" % self.root)

        #print "ODIRS: %s" % repr(out_dirs)
        return out_dirs
Esempio n. 8
0
def run():
    global include_list
    global gnumake

    ## Que?
    sys.setcheckinterval(50)

    magic = "# Dependency magic by $Id: mkdepend_exe.py,v 1.2 2006/07/06 19:28:05 jfinnecy Exp $\n"
    obj_path, makefile, source_list = parse_args(sys.argv[1:])

    if makefile:
        if not os.path.isfile(makefile):
            print "Makefile=\"%s\" not found." % (makefile)
            sys.exit(1)
    else:
        if not gnumake:
            print "No Makefile specified."
            sys.exit(1)

    init_platform()

    if makefile:
        makefile_data = open(makefile, "r").read()
        if gnumake and string.find(makefile_data, magic) != -1:
            print "Dependencies have already been updated automagically."
            sys.exit(0)

    # Get system include path (Windows way)
    #incpath=os.environ.get("include")
    #if incpath:
    #    include_list = include_list + string.split(incpath,';')

    #incpath=os.environ.get("C_INCLUDE_PATH")
    # Get system include path (UNIX way)
    #if incpath:
    #    include_list = include_list + string.split(incpath,':')

    mrlist = ["# DO NOT DELETE -- mkdepend depends on this line\n"]
    extentions = {".c": 1, ".cc": 1, ".cxx": 1}
    all_files = {}
    for source in source_list:
        (base, ext) = os.path.splitext(source)
        extentions[ext] = 1

        base = os.path.normpath(base)
        if os.path.isabs(base):
            base = string.replace(base, "\\", "_")
            base = string.replace(base, ":", "_")
            base = string.replace(base, "/", "_")
        else:
            ## Trim off any ../ from the beginning of the path
            base = string.replace(base, "\\", "/")
            tmp = string.split(base, "/")
            x = 0
            while len(tmp) > x + 1:
                if tmp[x] in [os.curdir, os.pardir]:
                    x = x + 1
                else:
                    break
            if x:
                tmp = ["par%d" % x] + tmp[x:]
            base = string.join(tmp, os.sep)

        path = os.path.join(obj_path, base)

        if string.lower(ext) == ".rc":
            obj = "%s.%s" % (path, "res")
        else:
            obj = "%s.%s" % (path, object_ext)

        dep = "%s.%s" % (path, "dep")

        deptime = mtime(dep)

        if deptime:
            tmp_rules = open(dep, "r").readlines()

            mt = mtime(dep + "-flist")
            if mt and mt <= deptime:
                hlist = string.split(open(dep + "-flist", "r").read(), "\n")
            else:
                hlist = []
                for l in tmp_rules:
                    l = string.split(l, ":")

                    ## Patchlet for stupid windows path names
                    if len(l) > 1 and len(l[0]) == 1:
                        l = [l[0] + ":" + l[1]] + l[2:]

                    if len(l):
                        file = string.strip(string.join(l[1:], ":"))
                        file = unquote_dep(file)
                        hlist.append(file)

            for file in hlist:
                #print "Checking times for %s (%s >? %s)" % (repr(file), repr(mtime(file)), repr(deptime))
                mt = mtime(file)
                if mt > deptime or mt == 0:
                    deptime = 0
                    break

        if not deptime:
            hlist = ReadSourceFile(source)
            tmp_rules = None

        global prefix_includes
        for pi in prefix_includes:
            if pi not in hlist:
                hlist.extend(ReadSourceFile(pi))
                tmp_rules = None

        if gnumake:
            obj = "%s %s.dep" % (obj, obj_path)

        if tmp_rules:
            tmp = tmp_rules
        else:
            tmp = MakefileRuleList(obj, hlist)

        if not deptime:
            utils.mkdirTree(path)
            open(dep + "-flist", "w").write(string.join(hlist, "\n"))
            open(dep, "w").write(string.join(tmp, ""))

        if not gnumake:
            mrlist.extend(tmp)

        for file in hlist:
            all_files[file] = 1

    if not makefile:
        sys.exit(0)

    if gnumake:
        tmplist = []
        p = obj_path
        while p not in ["", ".", "..", ":"]:
            tmplist.append('\t@test -d %s || mkdir %s\n' % (p, p))
            p = os.path.dirname(p)

        tmplist.reverse()
        tmplist.append('\t%s %s --gnumake -t%s $?\n' %
                       (sys.executable, sys.argv[0], obj_path))

        mrlist.append(magic)
        mrlist.append('ifneq ($MAKECMDGOALS),clean)\n')
        mrlist.append('-include $(COMPILED_OBJS:.%s=.dep)\n' % object_ext)
        mrlist.append('endif\n')
        for ext in extentions.keys():
            mrlist.append('\n')
            mrlist.append('%s/%%.dep: %%%s\n' % (obj_path, ext))
            mrlist.extend(tmplist)
        mrlist.append('\n')

    mrlist.append('\n')

    fil = open(makefile, "w")
    fil.write(makefile_data[:string.find(makefile_data, "# DO NOT DELETE")])
    fil.write(string.join(mrlist, ""))
    fil.close()

    fil = open(makefile + "-mkdep.o", "w")
    fil.write(string.join(all_files.keys(), "\n"))
    fil.close()

    sys.setcheckinterval(10)
    sys.exit(0)