Ejemplo n.º 1
0
def main(argv):
    #-------------------------------------------------------------------------------
    args, opts = oss.gopt(argv[1:], [], [], usage)

    cvsdwn = not CvsRootCheck()

    for f in oss.paths(args):
        ext = oss.splitext(f).lower()
        opts = '-kb' if ext in BinExts else ''

        if cvsdwn:
            otf = file('CVS/offline', 'a')
            print >> otf, 'add ' + opts + ' ' + f
            otf.close()
        else:
            if oss.exists('CVS/offline'):
                inf = file('CVS/offline')
                for cmd in inf:
                    oss.r('cvs.exe ' + cmd)
                inf.close()
                oss.rm('CVS/offline')

            oss.r('cvs.exe add ' + opts + ' ' + f)

    oss.exit(0)
Ejemplo n.º 2
0
def main(argv):
#-------------------------------------------------------------------------------
    args, opts = oss.gopt(argv[1:], [], [], usage)

    cvsdwn = not CvsRootCheck()

    for f in oss.paths(args):
        ext = oss.splitext(f).lower()
        opts = '-kb' if ext in BinExts else ''

        if cvsdwn:
            otf = file('CVS/offline', 'a')
            print >> otf, 'add ' + opts + ' ' + f
            otf.close()
        else:
            if oss.exists('CVS/offline'):
                inf = file('CVS/offline')
                for cmd in inf:
                    oss.r('cvs.exe ' + cmd)
                inf.close()
                oss.rm('CVS/offline')

            oss.r('cvs.exe add ' + opts + ' ' + f)

    oss.exit(0)
Ejemplo n.º 3
0
Archivo: copyit.py Proyecto: chyser/bin
    def xferFile(self, srcFileName, destFileName):
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        if srcFileName in self.bad:
            return

        try:
            fs = oss.filesize(srcFileName)
        except WindowsError:
            return

        ## ensure file is completed
        if srcFileName not in self.rec:
            self.rec[srcFileName] = fs
            return

        if self.rec[srcFileName] == fs:
            try:
                oss.mv(srcFileName, destFileName)
                if not oss.exists(destFileName):
                    raise CopyException("bad copy")

                del self.rec[srcFileName]
                self.xfers.append('%s -> %s' % (srcFileName, destFileName))
                return fs
            except:
                oss.rm(destFileName)
                self.bad.add(srcFileName)
        else:
            print("  @@", srcFileName, self.rec[srcFileName], fs)
            self.rec[srcFileName] = fs

        return
Ejemplo n.º 4
0
def main(argv):
#-------------------------------------------------------------------------------
    args, opts = oss.gopt(argv[1:], [], [], usage)

    for fn in args:
        print fn
        oss.r('crypt <%s >tt.zip' % (fn))
        oss.r('python C:/bin/zippy.py tt.zip')
    oss.rm('tt.zip')
Ejemplo n.º 5
0
def main(argv):
#-------------------------------------------------------------------------------
    args, opts = oss.gopt(argv[1:], [], [], usage)

    for fn in args:
        if not oss.exists(fn):
            usage(1, "%s does not exist" % fn)

        oss.r('python C:/bin/zippy.py -z -c tt.zip %s/*' % fn)
        oss.r('crypt <tt.zip > %s.sec' % (fn))
        oss.rm('tt.zip')
Ejemplo n.º 6
0
Archivo: mycvs.py Proyecto: chyser/bin
    def rm(self, args, opts=None):
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        """ removes the specified files or directories from CVS archive (possible
            offline)

            @type  args: sequence
            @param args: sequence of files or directories to remove
        """
        for fn in args:
            oss.rm(fn)
            self._issueCmd(' rm ' + fn)
Ejemplo n.º 7
0
Archivo: mycvs.py Proyecto: chyser/bin
 def updateOffline(self):
 #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     """ if some offline operations were queued, execute them if online
     """
     if self.cvsup and oss.exists('CVS/offline'):
         inf = file('CVS/offline')
         for cmd in inf:
             oss.r(self.exe + cmd)
         inf.close()
         oss.rm('CVS/offline')
         return True
Ejemplo n.º 8
0
Archivo: pmake.py Proyecto: chyser/bin
def doFile(ddir, mfile, make, jobs, opts, args):
#-------------------------------------------------------------------------------
    if mfile is not None:
        makefile = mfile
        make = "nmake"

        if not oss.exists(makefile):
            print "%s doesn't exist" % makefile
            return 0

    else:
        if oss.exists('make.pmk'):
            makefile = 'make.pmk'
            makeCmd = 'make --win32' + jobs
        elif oss.exists('nmake.pmk'):
            makefile = 'nmake.pmk'
            makeCmd  = 'nmake'
        elif oss.exists('makefile'):
            makefile = 'makefile'
            makeCmd  = 'make --win32' + jobs
        else:
            return 0

    print '\nmaking:', ddir
    if make:
        makeCmd = make

    outfile = '/tmp/' + makefile + ".mak"

    tgtfile = makefile + ".mak"

    ret = 0
    try:
        GenMakefile(makefile, tgtfile, makeCmd)

        ret = 0
        cmd = ["%s -f %s" % (makeCmd, tgtfile)]

        if opts.define is not None:
            cmd.extend(['-D' + opts.define] if isinstance(opts.define, str) else ['-D %s' % d for d in opts.define])

        cmd.extend(args)
        cmd = ' '.join(cmd)

        print cmd
        print '-----------------------------------'
        ret = os.system(cmd)

    except Exception:
        traceback.print_exc()
        oss.rm(outfile)
        return 11

    return ret
Ejemplo n.º 9
0
def pretest(moduleName):
#-------------------------------------------------------------------------------
    print("Running Pretest:", moduleName, file=oss.stderr)
    module = __import__(moduleName)

    print(module.__file__)
    if module.__file__.endswith('.py'):

        if test_it(moduleName):
            pass
        else:
            fn = module.__file__
            oss.rm(fn + 'c')
            oss.rm(fn + 'o')
Ejemplo n.º 10
0
    def SyncDirs(self, dst=None, pretend=False):
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        src = self.GetFileInfo(self.srcPath)

        if not dst:
            dst = self.GetFileInfo(self.destPath)

        d, a = util.DiffLists(src.keys(), dst.keys())

        #print src.keys()
        #print dst.keys()

        self.log("\nremoving: " + str(d), nl='\n')

        for f in d:
            if not pretend:
                oss.rm('-rf', self.destPath + '/' + f)

        self.log("\nadding: " +  str(a))

        for f in a:
            df = oss.normpath(self.destPath + '/' + f)
            sf = oss.normpath(self.srcPath + '/' + f)
            if oss.IsDir(sf):
                if not pretend:
                    util.CallNoException(oss.mkdirs, (df))
            else:
                pth, nm, ext = oss.splitFilename(df)
                if not pretend:
                    oss.mkdirs(pth)
                    oss.cp(sf, df)

        chgd = []
        dm, chk = util.DiffLists(src.keys(), a)

        for f in chk:
            if src[f] != dst[f]:
                df = oss.normpath(self.destPath + '/' + f)
                sf = oss.normpath(self.srcPath + '/' + f)
                chgd.append(f)

                pth, nm, ext = oss.splitFilename(df)
                if not pretend:
                    oss.mkdirs(pth)
                    util.CallNoException(oss.cp, (sf, df))


        self.log("\nchanged: " +  str(chgd), bl='@')
        return self.GetFileInfo(self.destPath)
Ejemplo n.º 11
0
    def SyncDirs(self, dst=None, pretend=False):
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        src = self.GetFileInfo(self.srcPath)

        if not dst:
            dst = self.GetFileInfo(self.destPath)

        d, a = util.DiffLists(src.keys(), dst.keys())

        #print src.keys()
        #print dst.keys()

        self.log("\nremoving: " + str(d), nl='\n')

        for f in d:
            if not pretend:
                oss.rm('-rf', self.destPath + '/' + f)

        self.log("\nadding: " + str(a))

        for f in a:
            df = oss.normpath(self.destPath + '/' + f)
            sf = oss.normpath(self.srcPath + '/' + f)
            if oss.IsDir(sf):
                if not pretend:
                    util.CallNoException(oss.mkdirs, (df))
            else:
                pth, nm, ext = oss.splitFilename(df)
                if not pretend:
                    oss.mkdirs(pth)
                    oss.cp(sf, df)

        chgd = []
        dm, chk = util.DiffLists(src.keys(), a)

        for f in chk:
            if src[f] != dst[f]:
                df = oss.normpath(self.destPath + '/' + f)
                sf = oss.normpath(self.srcPath + '/' + f)
                chgd.append(f)

                pth, nm, ext = oss.splitFilename(df)
                if not pretend:
                    oss.mkdirs(pth)
                    util.CallNoException(oss.cp, (sf, df))

        self.log("\nchanged: " + str(chgd), bl='@')
        return self.GetFileInfo(self.destPath)
Ejemplo n.º 12
0
def process(fn, tabsize):
    #-------------------------------------------------------------------------------
    try:
        with open(fn, 'rU') as inf:
            text = inf.read()
    except IOError as msg:
        print("%s: I/O error: %s" % (fn, str(msg)), file=oss.stderr)
        return

    newtext = string.expandtabs(text, tabsize)
    if newtext == text:
        return

    backup = fn + "~"

    oss.rm(backup)
    oss.mv(fn, backup)

    with open(fn, 'w') as otf:
        otf.write(newtext)

    print(fn)
Ejemplo n.º 13
0
def process(fn, tabsize):
#-------------------------------------------------------------------------------
    try:
        with open(fn, 'rU') as inf:
            text = inf.read()
    except IOError as msg:
        print("%s: I/O error: %s" % (fn, str(msg)), file=oss.stderr)
        return

    newtext = string.expandtabs(text, tabsize)
    if newtext == text:
        return

    backup = fn + "~"

    oss.rm(backup)
    oss.mv(fn, backup)

    with open(fn, 'w') as otf:
        otf.write(newtext)

    print(fn)
Ejemplo n.º 14
0
Archivo: runit.py Proyecto: chyser/bin
def main(argv):
    #-------------------------------------------------------------------------------
    """
    runit.py [-p] [-b] [-m] [-k] [-x] [-d <PathDir>] <script>
        -p | --pause    : pause after completion
        -b | --build    : generate build style output
        -m | --nomain   : disable calling main
        -k | --nomake   : disable running make
        -x | --nodebug  : disable debug flag
        -a | --absdir   : absolute path given, don't use for wkdir
        -d | --wkdir <PathDir> : directory where program is
        <script>: script to run or 'build'

    runit supports execution of python scripts from within Slickedit.  Since a
    window is created on execution (and is destroyed upon completion), console
    programs need to block on user input to allow execution results to be
    seen.  -p does this.  Also, exceptions often cause the blocking code to be
    bypassed, such that errors cannot be seen at all.  Even when visible, the
    default dump format is not easily parsed by editors.  -b does this.  Many
    forms of errors can be detected by 'importing' the program without running
    the main code.  -m does this.

    -d or providing the full path in the script names allows local directory
    modules to be found as if the script was run directly from the local
    directory.

    Version 1.0
    """
    args, opt = oss.gopt(argv[1:], [('p', 'pause'), ('b', 'build'),
                                    ('m', 'nomain'), ('k', 'nomake'),
                                    ('x', 'nodebug'), ('a', 'absdir')],
                         [('d', 'wkdir')], main.__doc__)

    oss.echo("die", "/tmp/runit_die")
    time.sleep(2)
    oss.rm("/tmp/runit_die")

    if not args:
        opt.usage(1, "Must supply a program to run")

    prgmName = oss.path(args[0])

    if opt.wkdir is None:
        pdir = prgmName.drive_path
        opt.wkdir = pdir if pdir and opt.absdir else '.'

    if 0:
        thread.start_new_thread(look_out, (1, ))

    global moduleName, fileName, globd

    moduleName = prgmName.name
    fileName = prgmName.drive_path_name + '.py'

    globd = {}
    exec('import sys', globd)

    ## enable local modules to be found
    wd = oss.abspath(opt.wkdir)
    globd['sys'].path.insert(0, wd)

    ## if calling main is disabled, use build semantics
    if opt.nomain:
        opt.build = True

    try:
        ## recreate argv
        globd['sys'].argv = [fileName] + args[1:]

        ## if calling main is disabled, change name
        globd["__name__"] = "__main__" if opt.nomain is None else moduleName

        if opt.nodebug is not None:
            globd["__debug__"] = True

        if opt.build is None:
            print("CmdLine: '%s'" % " ".join(globd['sys'].argv))

        ## run a makefile if it exists
        if opt.nomake is None:
            if oss.exists("make.pmk") or oss.exists("nmake.pmk"):
                oss.r('python C:\\bin\\pmake.py')
            elif oss.exists("makefile"):
                oss.r('make')

        sys.path = globd['sys'].path
        sys.argv = globd['sys'].argv
        reload(oss)

        sys.modules['runit'] = sys.modules['__main__']
        try:
            sys.modules['__main__'] = __import__(moduleName)
        except ImportError:
            print(sys.path, file=oss.stderr)

        try:
            execfile(sys.modules['runit'].fileName, sys.modules['runit'].globd)
        except SystemExit:
            pass

        if opt.pause and not opt.build:
            print("-- continue --")
            sys.stdin.readline()

    except Exception:
        if opt.build:
            ## print error message(s) in form many editors can parse
            t, v, tb = sys.exc_info()

            traceback.print_exc()

            print(traceback.extract_tb(tb))

            tbl = traceback.extract_tb(tb)[-1]
            s = traceback.format_exception_only(t, v)

            err = "".join(s)

            if s[0].find('File') != -1:
                l = s[0].split()
                print("%s(%s):\n" % (l[1].split('"')[1], l[3]), err)
            else:
                print("%s(%d):\n" % (tbl[0], tbl[1]), err)
        else:
            ## standard dump semantics
            traceback.print_exc()
            print("-- continue --")
            sys.stdin.readline()
Ejemplo n.º 15
0
Archivo: runit.py Proyecto: chyser/bin
def main(argv):
#-------------------------------------------------------------------------------
    """
    runit.py [-p] [-b] [-m] [-k] [-x] [-d <PathDir>] <script>
        -p | --pause    : pause after completion
        -b | --build    : generate build style output
        -m | --nomain   : disable calling main
        -k | --nomake   : disable running make
        -x | --nodebug  : disable debug flag
        -a | --absdir   : absolute path given, don't use for wkdir
        -d | --wkdir <PathDir> : directory where program is
        <script>: script to run or 'build'

    runit supports execution of python scripts from within Slickedit.  Since a
    window is created on execution (and is destroyed upon completion), console
    programs need to block on user input to allow execution results to be
    seen.  -p does this.  Also, exceptions often cause the blocking code to be
    bypassed, such that errors cannot be seen at all.  Even when visible, the
    default dump format is not easily parsed by editors.  -b does this.  Many
    forms of errors can be detected by 'importing' the program without running
    the main code.  -m does this.

    -d or providing the full path in the script names allows local directory
    modules to be found as if the script was run directly from the local
    directory.

    Version 1.0
    """
    args, opt = oss.gopt(argv[1:], [('p', 'pause'), ('b', 'build'), ('m', 'nomain'),
                   ('k', 'nomake'), ('x', 'nodebug'), ('a', 'absdir')], [('d', 'wkdir')], main.__doc__)

    oss.echo("die", "/tmp/runit_die")
    time.sleep(2)
    oss.rm("/tmp/runit_die")

    if not args:
        opt.usage(1, "Must supply a program to run")

    prgmName = oss.path(args[0])

    if opt.wkdir is None:
        pdir = prgmName.drive_path
        opt.wkdir = pdir if pdir and opt.absdir else '.'

    if 0:
        thread.start_new_thread(look_out, (1,))

    global moduleName, fileName, globd

    moduleName = prgmName.name
    fileName = prgmName.drive_path_name + '.py'

    globd = {}
    exec('import sys', globd)

    ## enable local modules to be found
    wd = oss.abspath(opt.wkdir)
    globd['sys'].path.insert(0, wd)

    ## if calling main is disabled, use build semantics
    if opt.nomain:
        opt.build = True

    try:
        ## recreate argv
        globd['sys'].argv = [fileName] + args[1:]

        ## if calling main is disabled, change name
        globd["__name__"] = "__main__" if opt.nomain is None else moduleName

        if opt.nodebug is not None:
            globd["__debug__"] =  True

        if opt.build is None:
            print("CmdLine: '%s'" % " ".join(globd['sys'].argv))

        ## run a makefile if it exists
        if opt.nomake is None:
            if oss.exists("make.pmk") or oss.exists("nmake.pmk"):
                oss.r('python C:\\bin\\pmake.py')
            elif oss.exists("makefile"):
                oss.r('make')

        sys.path = globd['sys'].path
        sys.argv = globd['sys'].argv
        reload(oss)

        sys.modules['runit'] = sys.modules['__main__']
        try:
            sys.modules['__main__'] = __import__(moduleName)
        except ImportError:
            print(sys.path, file=oss.stderr)

        try:
            execfile(sys.modules['runit'].fileName, sys.modules['runit'].globd)
        except SystemExit:
            pass

        if opt.pause and not opt.build:
            print("-- continue --")
            sys.stdin.readline()

    except Exception:
        if opt.build:
            ## print error message(s) in form many editors can parse
            t, v, tb = sys.exc_info()

            traceback.print_exc()

            print(traceback.extract_tb(tb))

            tbl = traceback.extract_tb(tb)[-1]
            s = traceback.format_exception_only(t,v)

            err = "".join(s)

            if s[0].find('File') != -1:
                l = s[0].split()
                print("%s(%s):\n" % (l[1].split('"')[1], l[3]), err)
            else:
                print("%s(%d):\n" % (tbl[0], tbl[1]), err)
        else:
            ## standard dump semantics
            traceback.print_exc()
            print("-- continue --")
            sys.stdin.readline()
Ejemplo n.º 16
0
    def real_execute(self, tgt, cmds):
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        script = []
        args = prgm = eof = strip = None

        state = 0

        env = dict(self.parent.mobj.env)
        oss.cd(self.parent.curDir)

        for line in cmds:
            if state == 0:
                if '<<<' in line:
                    state = 1
                    strip, line = util.leadingSpaces(line)
                    a, eof = relib.split('<<<', line)
                    prgm = a[0]
                    try:
                        args = a[1:]
                    except IndexError:
                        args = []
                else:
                    line = line.strip()
                    if line:
                        s = line.split(' ', 1)

                        if s[0] in BUILTINS:
                            BUILTINS[s[0]](s[1])

                        elif s[0] == 'set':
                            try:
                                var, _, val = s[1].partition('=')
                                var = var.strip().encode('ascii', 'ignore')
                                if _ == '=':
                                    val = val.strip().encode('ascii', 'ignore')
                                    env[var] = val
                                else:
                                    print(var, '=', env[var])
                            except IndexError:
                                pprint.pprint(env)

                        elif s[0] == 'call':
                            cmd = self.parent.evalPython(s[1])
                            if cmd is not None:
                                self.runCmd(tgt, cmd, env)

                        else:
                            self.runCmd(tgt, line, env)

            elif state == 1:
                if line.strip() == eof[0]:
                    otf = tempfile.NamedTemporaryFile(delete=False)
                    name = otf.name
                    otf.writelines(script)
                    otf.close()

                    try:
                        self.runCmd(tgt, prgm + ' ' + name + ' ' + ' '.join(args), env, True)
                    finally:
                        oss.rm(name)

                    script = []
                    args = prgm = eof = strip = None
                    state = 0
                else:
                    ln = line[strip:]
                    if len(ln) == 0:
                        ln = '\n'
                    script.append(ln)

        self.complete.set()
Ejemplo n.º 17
0
 def Remove(self):
 #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     oss.rm(self.FileName)