Пример #1
0
def checkUpdateDir(fileset):
  for f in fileset:
    remoteInfo = f.get('remote')
    if remoteInfo is None: continue
    remoteDir = remoteInfo.get('dir')
    if remoteDir is None: continue
    ftpDir = os.path.join(getDatarootDir(),'data','ftp','data','user',remoteDir)
    if os.path.exists(ftpDir):
      return True
  return False
Пример #2
0
 def __init__(self,yamlFile):
   self.yamlFile = yamlFile
   self.name = _getFname(yamlFile)
   self.groupDir = dirName = os.path.join(getDatarootDir(),'data','ps',self.name)
   if not os.path.exists( dirName):
     os.makedirs(dirName)
   self.procsMap = None #yaml map
   self.locals = {}#key is procName,value[0] is LocalProcess,value[1] is LPConfig
   self.reload()
   self.tailMap = {} #key is procName log/console,value is lastSize
Пример #3
0
def init():
  global db
  dataDir = os.path.join(getDatarootDir(),DATA_DIR) 
  checkDir(dataDir)
  db = adbapi.ConnectionPool("sqlite3", database=os.path.join(dataDir,"stdpm.db"),check_same_thread=False)
  def check(txn):
    res = txn.execute("SELECT * FROM sqlite_master WHERE type='table' AND name=?",['Process']).fetchone()
    if res is None:
      txn.execute('CREATE TABLE Process(clientIp VARCHAR(64),procGroup VARCHAR(255),procName VARCHAR(255),procInfo TEXT,PRIMARY KEY(clientIp,procGroup,procName))')
    else:
      def initDb(result):
        for res in result:
          ip = res[0]
          _checkIpDict(ip)
          _checkResourceDictName(uniqueProcName(ip,res[1],res[2]),)
      db.runQuery('SELECT clientIp,procGroup,procName  FROM Process').addCallback(initDb)
  db.runInteraction(check).addCallback(lambda x:x)
Пример #4
0
def initFtpFactory():
  ftpRoot = os.path.join(getDatarootDir(),'data','ftp','')
  ftpData = os.path.join(ftpRoot,'data')
  checkDir(ftpData)
  passFile = os.path.join(ftpRoot,"userpass.dat")
  if not os.path.exists(passFile) :
    with open(passFile,"w+") as f:
      f.write("user:trunksoft\n")
  with open(passFile) as f:
    for line in f:
      splits = line.split(":")
      if len(splits)>1:
        checkDir(os.path.join(ftpData,splits[0]))
  FTPFactory.allowAnonymous = False
  p = Portal(FTPRealm(ftpData,ftpData),[FilePasswordDB(passFile)])
  f = FTPFactory(p)
  return f
Пример #5
0
  if pg:
    pg.restartProc(psName,secs,memo)
  else:
    print 'can not found process group:'+psGroup

def getLPConfig(psGroup,psName):
  pg = procGroupDict.get(psGroup)
  if pg:
    procInfo = pg.procsMap.get(psName)
    if procInfo:
      return LPConfig(procInfo)
  return None

def _updateLog(logFd,fname):
  logFd.write("%s%s%s%s"%(fname,SEP,datetime.now().strftime(TIME_FORMAT),CR))
_clientUpdateLogFile = os.path.join(getDatarootDir(),'data','clientUpdateLog.ulog')
def clientUpdateLog(fname):
  with open(_clientUpdateLogFile,'w+') as f:
    _updateLog(f,fname)
def updateLog(psGroup,psName,fname):
  if psGroup is None: return
  pg = procGroupDict.get(psGroup)
  if pg:
    localValue = pg.locals.get(psName)
    if localValue:
      localValue[0].logUpdate(fname)
def _lastUpdateTime(logFd):
  fsize = os.path.getsize(logFd.name)
  if fsize>100:
    logFd.seek(-100,os.SEEK_END)
  lines = logFd.readlines()
Пример #6
0
from twisted.internet import reactor
from twisted.protocols.ftp import FTPClient,FTPFileListProtocol

import os,shutil,fnmatch
import zlib,json
import tarfile,zipfile
from datetime import datetime
try:
    from cStringIO import StringIO
except ImportError:
    from StringIO import StringIO

from dp.common import getDatarootDir,checkDir,TIME_FORMAT
from dp.client.process import restartProc,getLPConfig,updateLog,clientUpdateLog

cacheDir = os.path.join(getDatarootDir(),'data','filecache','')
checkDir(cacheDir)

class BufferFileTransferProtocol(Protocol):
  def __init__(self,fname,localInfo,psGroup,psName,changeFlagList):
    self.fname=fname
    self.psGroup = psGroup
    self.psName = psName
    self.localInfo = localInfo
    self.tmpName=os.path.join(cacheDir,fname+'.tmp')
    self.fileInst=open(self.tmpName,'wb+')
    self.changeFlagList = changeFlagList
  def dataReceived(self,data):
    self.fileInst.write(data)
  def _processFiles(self,cacheFile,localDir,localInfo):
    extname = os.path.splitext(self.fname)[-1].lower()