Example #1
0
 def run(self, exact_progress=True):
     # 精确统计需先dry-run
     total_num = 0
     total_size = 0
     if exact_progress:
         total_num, total_size = self.dryRun()
     self.output('Checking...')
     start_time = time.time()
     finished_size = 0
     try:
         cmd = self.toCmd('--progress')
         proc = subprocess.Popen(cmd, shell=True, **_std_pipe)
         while True:
             retcode = proc.poll()
             if retcode is not None:
                 # rsync未成功执行
                 if retcode != 0:
                     core.getLogger('kits.rsync').error(proc.stderr.read())
                     raise subprocess.CalledProcessError(retcode, cmd)
                 break
             res = proc.stdout.readline().strip()
             # print(output)
             if 'to-check' in res:
                 s = re.findall(r'(\d+) +100%', res)
                 size = int(s[0]) if s else 0
                 finished_size = finished_size + size
                 m = re.findall(r'to-check=(\d+)/(\d+)', res)
                 finished_num = int(m[0][1]) - int(m[0][0])
                 if not exact_progress:
                     total_num = int(m[0][1])
                 self.outputProgressMsg(finished_num, total_num, finished_size, start_time, exact_progress=exact_progress)
     except Exception, e:
         self.saveTerminate(proc)
         raise e
Example #2
0
 def dryRun(self):
     # DRY-RUN 获取文件数及所有文件大小
     self.output('Counting files number...')
     try:
         cmd = self.toCmd('--stats', '--dry-run')
         proc = subprocess.Popen(cmd, shell=True, **_std_pipe)
         ret = proc.wait()
         if ret!=0:
             core.getLogger('kits.rsync').error(proc.stderr.read())
             raise subprocess.CalledProcessError(ret, cmd)
         res = proc.stdout.read()
         total_num = int(re.findall(r'Number of files: (\d+)', res)[0])
         total_size = int(re.findall(r'Total file size: (\d+)', res)[0])
     except Exception, e:
         self.saveTerminate(proc)
         raise e
Example #3
0
 def dryRun(self):
     # DRY-RUN 获取文件数及所有文件大小
     self.output('Counting files number...')
     try:
         cmd = self.toCmd('--stats', '--dry-run')
         proc = subprocess.Popen(cmd, shell=True, **_std_pipe)
         ret = proc.wait()
         if ret != 0:
             core.getLogger('kits.rsync').error(proc.stderr.read())
             raise subprocess.CalledProcessError(ret, cmd)
         res = proc.stdout.read()
         total_num = int(re.findall(r'Number of files: (\d+)', res)[0])
         total_size = int(re.findall(r'Total file size: (\d+)', res)[0])
     except Exception, e:
         self.saveTerminate(proc)
         raise e
Example #4
0
 def run(self, exact_progress=True):
     # 精确统计需先dry-run
     total_num = 0
     total_size = 0
     if exact_progress:
         total_num, total_size = self.dryRun()
     self.output('Checking...')
     start_time = time.time()
     finished_size = 0
     try:
         cmd = self.toCmd('--progress')
         proc = subprocess.Popen(cmd, shell=True, **_std_pipe)
         while True:
             retcode = proc.poll()
             if retcode is not None:
                 # rsync未成功执行
                 if retcode != 0:
                     core.getLogger('kits.rsync').error(proc.stderr.read())
                     raise subprocess.CalledProcessError(retcode, cmd)
                 break
             res = proc.stdout.readline().strip()
             # print(output)
             if 'to-check' in res:
                 s = re.findall(r'(\d+) +100%', res)
                 size = int(s[0]) if s else 0
                 finished_size = finished_size + size
                 m = re.findall(r'to-check=(\d+)/(\d+)', res)
                 finished_num = int(m[0][1]) - int(m[0][0])
                 if not exact_progress:
                     total_num = int(m[0][1])
                 self.outputProgressMsg(finished_num,
                                        total_num,
                                        finished_size,
                                        start_time,
                                        exact_progress=exact_progress)
     except Exception, e:
         self.saveTerminate(proc)
         raise e
Example #5
0
    ln -s ~/ethanol/ethanol_controller/template ~/ethanol/ethanol_controller/pox/pox/template

    2) start the module with ethanol
    cd ~/ethanol/ethanol_controller/pox
    python pox.py ethanol.server template.sampleApp --ap_ip="<your AP's ip address here>"

   SampleApp checks if ethanol is running,
   if ethanol is running, this module can also run
   It print a list of AP's already connected to the controller.
"""

import sys
import os
import core

log = core.getLogger()
"""this is the path of this python file"""
__my_path = os.path.dirname(os.path.realpath(__file__))


def set_app_paths(paths=['']):
    """set python's system path so we can call our functions
       :param list paths contains the relative path for our functions
    """
    for path in paths:
        sys.path.append(os.path.join(__my_path, path))


def is_ethanol_loaded(module_name='pox.ethanol.server'):
    """verifies if ethanol module is loaded