Exemplo n.º 1
0
    def SvcDoRun(self):
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        xo = xp.XMLToObj()
        tag, cr = xo.unmarshal_str(file(self.cfgfile).read())

        ## set up log file
        self.logfile = cr.log
        try:
            oss.cp(self.logfile, self.logfile + ".old")
        except: pass
        self.log = file(self.logfile, "w")

        ## provide info as to what configuration and additional logging we are using
        self.LogInfoEvent("DirSyncServer Rev: '%s'" % REVISION)
        self.LogInfoEvent("Using Log File: '%s'" % self.logfile)
        self.LogInfoEvent("Using Config File: '%s'" % self.cfgfile)

        for item in cr.items:
            self.logmsg("$$ Inserting Rule: '%s'" % item.rule)
            t = ds.DirSyncThread(item.rule, item.src, item.dest, item.excludes, item.filters, item, item.verbose and self.log)
            self.tds.append(t)
            t.setDaemon(True);  t.setName(item.rule);  t.start();  time.sleep(0)
            self.logmsg("$$ Started: '%s' thread. isAlive: %s" % (t.getName(), str(t.isAlive())))

        self.WaitInterval = 30 * 1000
        WinService.SvcDoRun(self)
Exemplo n.º 2
0
Arquivo: repo.py Projeto: chyser/bin
def pull(db, args):
    #-------------------------------------------------------------------------------
    for a in oss.paths(args):

        nm = a.name_ext
        pth = db.get(nm)

        fpath = pth + '/' + nm
        print('pulling "%s" -> "%s' % (a, fpath))

        src = DIR + nm

        if not oss.exists(src):
            print("%s does not exist" % src)
            continue

        if oss.exists(fpath):
            ch = raw_input('overwrite "%s": (Y/n): ' % fpath)
            if ch == 'n':
                continue
            else:
                print('overwritten')

        db.rm(nm)
        oss.cp(src, fpath)
Exemplo n.º 3
0
Arquivo: repo.py Projeto: chyser/pylib
def pull(db, args):
#-------------------------------------------------------------------------------
    for a in oss.paths(args):

        nm = a.name_ext
        pth = db.get(nm)

        fpath = pth + '/' + nm
        print('pulling "%s" -> "%s' % (a, fpath))

        src = DIR + nm

        if not oss.exists(src):
            print("%s does not exist" % src)
            continue

        if oss.exists(fpath):
            ch = raw_input('overwrite "%s": (Y/n): ' % fpath)
            if ch == 'n':
                continue
            else:
                print('overwritten')

        db.rm(nm)
        oss.cp(src, fpath)
Exemplo n.º 4
0
    def __init__(self, args):
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        WinService.__init__(self, args)
        self.logfile = "C:/var/log/dirsync.log"
        try:
            oss.cp(self.logfile, self.logfile + ".old")
        except: pass

        self.cfgfile = "C:/var/cfgs/dirsyncdb.xml"
        self.log = file(self.logfile, "wU")
        self.tds = []
Exemplo n.º 5
0
    def __init__(self, args):
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        WinService.__init__(self, args)
        self.logfile = "C:/var/log/ptes.log"
        try:
            oss.cp(self.logfile, self.logfile + ".old")
        except: pass

        self.tasks = {}
        self.logmsg("Initializing")
        self.cfgobj = cfg.ConfigObject(CfgObj(), "ptes.xml", "C:/var/cfgs")
        self.default = 5 * 60 * 1000
        self.trigger = time.time() + self.default
        self.tds = []
Exemplo n.º 6
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)
Exemplo n.º 7
0
    def __init__(self, args):
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        WinService.__init__(self, args)
        self.logfile = "C:/var/log/ptes.log"
        try:
            oss.cp(self.logfile, self.logfile + ".old")
        except:
            pass

        self.tasks = {}
        self.logmsg("Initializing")
        self.cfgobj = cfg.ConfigObject(CfgObj(), "ptes.xml", "C:/var/cfgs")
        self.default = 5 * 60 * 1000
        self.trigger = time.time() + self.default
        self.tds = []
Exemplo n.º 8
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)
Exemplo n.º 9
0
Arquivo: config.py Projeto: chyser/bin
    def Save(self):
        #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        xo = xp.ObjToXML()

        try:
            oss.mv(self._filename, self._filename + '.bak')
        except IOError:
            pass

        try:
            otf = file(self._filename, 'w')
            otf.write(xo.marshal('config', self._obj) + '\n')
            otf.close()
        except IOError:
            try:
                oss.cp(self._filename + '.bak', self._filename)
            except:
                pass
Exemplo n.º 10
0
Arquivo: config.py Projeto: chyser/bin
    def Save(self):
    #- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
        xo = xp.ObjToXML()

        try:
            oss.mv(self._filename, self._filename + '.bak')
        except IOError:
            pass

        try:
            otf = file(self._filename, 'w')
            otf.write(xo.marshal('config', self._obj) + '\n')
            otf.close()
        except IOError:
            try:
                oss.cp(self._filename + '.bak', self._filename)
            except:
                pass
Exemplo n.º 11
0
Arquivo: repo.py Projeto: chyser/bin
def push(db, args):
    #-------------------------------------------------------------------------------
    for a in oss.paths(args):
        print('pushing "%s"' % a)

        pth = a.fpath
        nm = a.name_ext

        if not oss.exists(a):
            print('"%s" does not exist' % a)
            continue

        dest = DIR + nm
        if oss.exists(dest):
            print("warning: saved %s exists" % nm)
            ch = raw_input("overwrite: (Y/n): ")
            if ch == 'n':
                continue
            else:
                print('overwritten')

        print(nm, pth)
        db.put(nm, pth)
        oss.cp(a, DIR)
Exemplo n.º 12
0
Arquivo: repo.py Projeto: chyser/pylib
def push(db, args):
#-------------------------------------------------------------------------------
    for a in oss.paths(args):
        print('pushing "%s"' % a)

        pth = a.fpath
        nm = a.name_ext

        if not oss.exists(a):
            print('"%s" does not exist' % a)
            continue

        dest = DIR + nm
        if oss.exists(dest):
            print("warning: saved %s exists" % nm)
            ch = raw_input("overwrite: (Y/n): ")
            if ch == 'n':
                continue
            else:
                print('overwritten')

        print(nm, pth)
        db.put(nm, pth)
        oss.cp(a, DIR)
Exemplo n.º 13
0
Arquivo: crlf.py Projeto: chyser/bin
def main(argv):
    #-------------------------------------------------------------------------------
    """ usage: crlf [options] <file> [<file> ...]

        options:
            -i | --identify  : identify line ending in file (default)
            -w | --win       : convert line endings to windows
            -u | --unix      : convert line ending to unix
            -m | --mac       : convert line endings to mac

        converts line endings in a file to the specifed type
    """
    args, opts = oss.gopt(argv[1:], [('w', 'win'), ('u', 'unix'), ('m', 'mac'),
                                     ('i', 'identify')], [], main.__doc__)

    if not args:
        opts.usage(1, "must specify files")

    src = r"\r|\n|\r\n"

    if opts.identify:
        mode = "id"
    elif opts.mac:
        mode = "mac"
        dest = "\r"
    elif opts.unix:
        mode = "unix"
        src = r"\r?\n"
        dest = "\n"
    elif opts.win:
        mode = "win"
        dest = "\r\n"
    else:
        mode = "id"

    for fName in oss.paths(args):
        if oss.IsDir(fName):
            print(fName, "Directory!")
            continue

        oss.cp(fName, BUFILE)
        with open(fName, "rb") as inf:
            data = inf.read()

            if '\0' in data:
                print(fName, "Binary!")
                continue

            if mode == "id":
                if re.search(r"[^\r]\n", data):
                    res = 'unix'
                elif re.search(r"\r\n", data):
                    res = 'win'
                elif re.search(r"\r[^\n]", data):
                    res = 'mac'
                else:
                    res = 'unkn'

                print('{0} -> {1}'.format(fName, res))

            else:
                newdata = re.sub(src, dest, data)
                if newdata != data:
                    with open(TMPFILE, 'wb') as f:
                        f.write(newdata)
                    oss.cp(TMPFILE, fName)
                    print(fName)

    oss.exit(0)