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)
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)
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)
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 = []
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 = []
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)
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 = []
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)
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
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
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)
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)
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)