Exemple #1
0
def retrieveFile(samba, share, path, id_str):
    file_path = 'temp/' + share + path + '.' + id_str
    try:
        mkdir(file_path)
        with open(file_path, 'wb') as f:
            samba.retrieveFile(share, path, f)
            LOGS.info('获取文件:' + path)
    except Exception as e:
        LOGS.error('SMB获取文件错误:' + str(e))
    return file_path
Exemple #2
0
def getFile(task):
    '''
    复制指定文件
    :param task: item.dir要求必须为绝对路径
    :return: 已复制文件的相对路径
    '''
    files = []
    if isFolder(task.dir):
        copy_tree(task.dir, 'temp/') # 目录的复制
        orgFiles = getFileNames(task.dir)
        rootLen = len(task.dir)
        files = list(map(lambda x:'temp/'+x[rootLen:],orgFiles))
        file_sender.rename(files, task.finger)

    else:
        shutil.copy(task.dir, 'temp')  # 文件拷贝,src必须是一个文件,dst可以是一个文件或者目录
        files.append('temp/' + os.path.basename(task.dir))
        file_sender.rename(files, task.finger)
    LOGS.info("文件复制完成:" + task.dir)
    return files
Exemple #3
0
def changeNetwork(device, ip, netmask, gateway):
    """
    @attention: change the network of the system
    """
    #print(get_ip_address('eth5'))

    path = "/etc/sysconfig/network-scripts/ifcfg-" + str(device)
    file_handler = open(path, "r")
    network_content = file_handler.read()
    file_handler.close()
    conte = "IPADDR=%s\nNETMASK=%s\nGATEWAY=%s\n" % (ip, netmask, gateway)
    num = network_content.find("IPADDR")
    if num != -1:
        network_content = network_content[:num] + conte
        file_handler = open(path, "w")
        file_handler.write(network_content)
        file_handler.close()
    LOGS.info('ip修改成功:%s:%s:%s:%s' % (device, ip, gateway, netmask))
    try:
        result = subprocess.call("sudo ifdown %s && sudo ifup %s" %
                                 (device, device),
                                 shell=True)
        if result == 0:
            LOGS.info('网卡重启成功:%s:%s:%s:%s' % (device, ip, gateway, netmask))
            return True
        else:
            LOGS.info('网卡重启失败:%s:%s:%s:%s' % (device, ip, gateway, netmask))
            return False
    except Exception as e:
        LOGS.error(str(e))
        return False
Exemple #4
0
def run(id):
    if not allow():
        LOGS.error('系统激活失败,请联系厂家获取支持')
        return
    #解析任务
    db.connect()
    task = Task.get(Task.finger == id)
    if task is None:
        LOGS.error('找不到对应任务:'+str(id))
        exit(-1)
    # 增加运行次数
    task.count = task.count + 1
    task.save()
    db.close()
    LOGS.info('开始任务:' + str(id)+":"+task.name)

    #执行任务
    files =getDataFile(task)
    if len(files) == 0:
        LOGS.info('未获取到任何数据:' + str(id) + ':' + task.name)
        return 0

    #发送文件
    r = redis.Redis()
    for f in files:
        #subprocess.call('./transfer_file -s '+f, shell=True)
        #改为发送文件列表到redis
        print(f)
        r.lpush('file',f)
        #记录日志
    LOGS.info('数据加入发送队列,等待发送:'+str(id)+':'+task.name)