Example #1
0
 def setUp(self):
     self.tempdir = tempfile.mkdtemp()
     self.fs = Filesystem(prefix=self.tempdir)
     self.app = Application(self.fs)
     self.tasks_suite = TasksSuite()
     self.tasks = [Task(1, "1"), Task(2, "2"), Task(3, "3")]
     self.tasks_suite.extend(self.tasks)
Example #2
0
 def __init__(self, name, run_func, humanized_template, setup_func=None):
     Task.__init__(self, name)
     self.driver = get_browser()
     if self.driver is None:
         raise NotImplementedError(E_BROWSERTASK_NO_BROWSERS % self.name)
     self.run_func = run_func
     self.humanized_template = humanized_template
     self.setup_func = setup_func
     self.result = None
Example #3
0
 def __init__(self, name, run_func, humanized_template, setup_func = None):
     Task.__init__(self, name)
     self.driver = get_browser()
     if self.driver is None:
         raise NotImplementedError(E_BROWSERTASK_NO_BROWSERS % self.name)
     self.run_func = run_func
     self.humanized_template = humanized_template
     self.setup_func = setup_func
     self.result = None
Example #4
0
def main():

    handler = logging.FileHandler(LOG_FILE_NAME)
    logger.addHandler(handler)
    logger.setLevel("DEBUG")  # WARNING")
    logger.warning('Starting rename with params: [{}]'.format(' '.join(sys.argv[1:])))

    parser = argparse.ArgumentParser()

    parser.add_argument('-E', '--extract-only',
                        dest='extract_only',
                        action='store_true',
                        help=('Extract-only mode. Returns content of PDF'),
                        required=False)
    parser.add_argument('-H', '--hash-only',
                        dest='hash_only',
                        action='store_true',
                        help=('Hash-only mode. Returns MD5 hash of input files'),
                        required=False)
    parser.add_argument('-S', '--simulate',
                        dest='simulate',
                        action='store_true',
                        help=('Simulation mode. Outputs actions that would be taken'),
                        required=False)
    parser.add_argument('-v', '--verbose',
                        dest='verbose',
                        action='store_true',
                        help=('Verbose mode. Outputs detailed information'),
                        required=False)
    parser.add_argument('-q', '--quiet',
                        dest='quiet',
                        action='store_true',
                        help=('Quiet mode. Produces no console output'),
                        required=False)

    parser.add_argument('location',
                        # dest='target',
                        action='store',
                        help='File or folder to process',
                        # required=True,
                        type=str)

    try:
        # TODO: next step: decouple the CLI arguments from the Task class. Possibly with a TaskBuilder?
        task = Task(parser, logger)
        task.execute()
    except Exception as e:
        logger.exception(e)
        raise e
Example #5
0
    def _find_task(self) -> Tuple[Optional[Task], Optional[int]]:
        file = open(self.file_name, 'r')
        str_tasks = file.readlines()
        file.close()
        for index, task_str in enumerate(str_tasks):
            task_dict = json.loads(task_str, object_hook=json_util.object_hook)
            task = Task(**task_dict)
            task.type = TaskType(task.type)

            if task.type != self.task_type:
                continue

            return task, index

        return None, None
Example #6
0
 def test_add_to_not_active_tasks_suite(self):
     task = Task(1, "task")
     self.cli.add(task)
     self.cli.status()
     output = self.stream.getvalue()
     self.assertIn(task.description, output)
     self.assertTrue(self.app.is_tasks_suite_active())
Example #7
0
 def test_add(self):
     self.app.start_tasks_suite(self.tasks_suite)
     task = Task(1, "task")
     self.cli.add(task)
     self.cli.status()
     output = self.stream.getvalue()
     self.assertIn(task.description, output)
Example #8
0
def runMcl(matrixPath, inflation, workingDir, outputPath):
    tempPath = os.path.join(os.path.dirname(outputPath), "temp_{}".format(os.path.basename(outputPath)))
    args = [Configs.mclPath, matrixPath, "--abc", "-o", tempPath]
    if inflation is not None:
        args.extend(["-I", str(inflation)])
    taskArgs = {"command" : subprocess.list2cmdline(args), "fileCopyMap" : {tempPath : outputPath}, "workingDir" : workingDir}
    return Task(taskType = "runCommand", outputFile = outputPath, taskArgs = taskArgs)
Example #9
0
def runClustalOmegaGuideTree(fastaPath, workingDir, outputPath, threads = 1):
    tempPath = os.path.join(os.path.dirname(outputPath), "temp_{}".format(os.path.basename(outputPath)))
    args = [Configs.clustalPath]
    args.extend(["-i", fastaPath, "--max-hmm-iterations=-1", "--guidetree-out={}".format(tempPath)])
    args.extend(["--threads={}".format(threads)])
    taskArgs = {"command" : subprocess.list2cmdline(args), "fileCopyMap" : {tempPath : outputPath}, "workingDir" : workingDir}
    return Task(taskType = "runCommand", outputFile = outputPath, taskArgs = taskArgs)
Example #10
0
    def start_onmyoji(self):
        section = self.ui.tabWidget.currentIndex()

        # 读取配置
        self.get_conf(section)

        if section == 0:
            # 御魂
            if self.ui.mitama_single.isChecked():
                # 单刷
                self.fight = SingleFight()

            elif self.ui.mitama_driver.isChecked():
                # 司机
                self.fight = DriverFighter()

            elif self.ui.mitama_passenger.isChecked():
                # 乘客
                self.fight = FighterPassenger()

            elif self.ui.mitama_dual.isChecked():
                # 双开
                self.fight = DualFighter()

        elif section == 1:
            # 探索
            self.fight = ExploreFight()

        elif section == 2:
            # 百鬼夜行
            self.fight = Ghost()

        elif section == 3:
            # 结界突破
            if self.ui.individual.isChecked():
                # 个人突破
                self.fight = Breakthrough()

            elif self.ui.shack.isChecked():
                # 个人突破
                self.fight = ShackBreakthrough()

        elif section == 4:
            self.fight = Task()

        task = threading.Thread(target=self.fight.start)
        task.start()
Example #11
0
 def setUp(self):
     self.tempdir = tempfile.mkdtemp()
     self.fs = Filesystem(prefix=self.tempdir)
     self.app = Application(self.fs)
     self.stream = StringIO()
     self.cli = CLI(self.app, self.stream)
     self.task = Task(30, "desc")
     self.tasks_suite = TasksSuite()
     self.tasks_suite.append(self.task)
Example #12
0
def runMafftGuideTree(fastaPath, workingDir, outputPath, threads = 1):
    tempPath = os.path.join(os.path.dirname(outputPath), "temp_{}".format(os.path.basename(outputPath)))
    treeFile = os.path.join(os.path.dirname(fastaPath),  "{}.tree".format(os.path.basename(fastaPath)))
    args = [Configs.mafftPath, "--retree", "0", "--treeout", "--parttree",
            "--quiet", "--thread", str(threads), "--anysymbol"]
    args.extend(["--partsize", "1000"])
    args.extend([fastaPath, ">", tempPath])
    taskArgs = {"command" : subprocess.list2cmdline(args), "fileCopyMap" : {treeFile : outputPath}, "workingDir" : workingDir}
    return Task(taskType = "runCommand", outputFile = outputPath, taskArgs = taskArgs)
Example #13
0
def runMafft(fastaPath, subtablePath, workingDir, outputPath, threads = 1):
    tempPath = os.path.join(os.path.dirname(outputPath), "temp_{}".format(os.path.basename(outputPath)))
    args = [Configs.mafftPath, "--localpair", "--maxiterate", "1000", "--ep", "0.123", 
            "--quiet", "--thread", str(threads), "--anysymbol"]
    if subtablePath is not None:
        args.extend(["--merge", subtablePath])
    args.extend([fastaPath, ">", tempPath])
    taskArgs = {"command" : subprocess.list2cmdline(args), "fileCopyMap" : {tempPath : outputPath}, "workingDir" : workingDir}
    return Task(taskType = "runCommand", outputFile = outputPath, taskArgs = taskArgs)
Example #14
0
 def test_execute_add(self):
     minutes = 1
     description = "task"
     task = Task(minutes, description)
     args = ["", "add", str(minutes), description]
     self.cli.execute(args)
     self.cli.status()
     output = self.stream.getvalue()
     self.assertIn(task.description, output)
Example #15
0
    def create_task(self, task_type: TaskType, content: Any):
        content_str = self.dump_content(content)

        task = asdict(Task(type=task_type,
                           content=content_str,
                           source_ip=self._get_ip_address(),
                           creation_time=datetime.utcnow()))

        file = open(self.file_name, 'a')
        self._log_task(task)
        file.write(f'{json.dumps(task, default=json_util.default)}\n')
        file.close()
Example #16
0
def runRaxmlNg(fastaFilePath, workingDir, outputPath, threads = 8):
    # raxml-ng --msa prim.phy --model GTR+G --prefix T4 --threads 2 --seed 2 --tree pars{25},rand{25}
    baseName = os.path.basename(outputPath).replace(".","")
    raxmlFile = os.path.join(workingDir, "{}.raxml.bestTree".format(baseName))
    seed = random.randint(1, 1000000)
    args = [Configs.raxmlPath,
            "--msa", fastaFilePath,
            "--prefix", baseName,
            "--threads", str(threads),
            "--seed", str(seed)]
    
    if Configs.inferDataType(fastaFilePath) == "protein":
        args.extend(["--model", "LG+G"])
    else:
        args.extend(["--model", "GTR+G"])
        
    args.extend(["--tree", "pars{{{}}}".format(1)])
    taskArgs = {"command" : subprocess.list2cmdline(args), "fileCopyMap" : {raxmlFile : outputPath}, "workingDir" : workingDir}
    return Task(taskType = "runCommand", outputFile = outputPath, taskArgs = taskArgs)
Example #17
0
def runFastTree(fastaFilePath, workingDir, outputPath, mode = "normal", intree = None):
    tempPath = os.path.join(os.path.dirname(outputPath), "temp_{}".format(os.path.basename(outputPath)))
    
    args = [Configs.fasttreePath]
    if Configs.inferDataType(fastaFilePath) == "protein":
        args.extend(["-lg"])
    else:
        args.extend(["-nt", "-gtr"])
    
    if intree is not None:
        args.extend(["-intree", intree])
    
    if mode == "fast":
        args.extend(["-fastest", "-nosupport"]) 
    elif mode == "faster":
        args.extend(["-fastest", "-nosupport", "-mlnni", "4" ]) 
    elif mode == "noml":
        args.extend(["-fastest", "-nosupport", "-noml"])
    
    args.extend([fastaFilePath, ">", tempPath])
    taskArgs = {"command" : subprocess.list2cmdline(args), "fileCopyMap" : {tempPath : outputPath}, "workingDir" : workingDir}
    return Task(taskType = "runCommand", outputFile = outputPath, taskArgs = taskArgs)
def getRemoteTask():
    from tasks.task import Task
    config = getConfig()

    r = requests.get(config["centerBaseURL"] + "/nodes/" + config["id"] +
                     "/tasks")
    data = json.loads(r.content)
    tasks = data["tasks"]
    nexttask = None
    for task in tasks:
        if task["status"] < 2:
            nexttask = task

    task = nexttask

    if not task:
        return None

    id = task["id"]
    range = long2ip(task["startIP"]) + "-" + long2ip(task["endIP"])
    if task["startIP"] == task["endIP"]:
        range = long2ip(task["startIP"])
    startPort = task["startPort"]
    endPort = task["endPort"]
    plugins = task["plugins"]

    for plugin in plugins:
        r = requests.get(config["centerBaseURL"] + "/plugins/" + plugin)
        plugindata = r.content
        f = open(path.join(pluginsdir, plugin + ".py"), "w", encoding="utf-8")
        f.write(plugindata.decode())
        f.close()

    task = Task(id, range, startPort, endPort, plugins)

    return task
Example #19
0
    def __init__(self, init_pose=None, init_velocities=None, init_angle_velocities=None, runtime=5., target_pos=None):
        Task.__init__(self, init_pose=init_pose, init_velocities=init_velocities,
                      init_angle_velocities=init_angle_velocities, runtime=runtime, target_pos=target_pos)

        position = self.sim.pose[0:3]
        self.init_distance =  self._get_distance(position)
Example #20
0
 def __init__(self, fs, inputs):
     Task.__init__(self, fs)
     self.inputs = inputs
     self._parents = self.create_parents()
     self.path = os.path.join(self.fs, self.name())
Example #21
0
 def __init__(self, name, run_func, humanized_template, setup_func=None):
     Task.__init__(self, name)
     self.run_func = run_func
     self.humanized_template = humanized_template
     self.setup_func = setup_func
     self.result = None
Example #22
0
def runHmmSearch(hmmModelPath, fragPath, workingDir, outputPath):
    tempPath = os.path.join(os.path.dirname(outputPath), "temp_{}".format(os.path.basename(outputPath)))
    args = [Configs.hmmsearchPath,"--noali", "--cpu", "1", "-o", tempPath, "-E", "99999999", "--max"]
    args.extend([hmmModelPath, fragPath])
    taskArgs = {"command" : subprocess.list2cmdline(args), "fileCopyMap" : {tempPath : outputPath}, "workingDir" : workingDir}
    return Task(taskType = "runCommand", outputFile = outputPath, taskArgs = taskArgs)
Example #23
0
class MyMainWindow(QMainWindow):
    def __init__(self, parent=None):
        super(MyMainWindow, self).__init__(parent)
        self.ui = Ui_MainWindow()
        self.ui.setupUi(self)

        self.ui.textEdit.ensureCursorVisible()

        h = GuiLogger()
        h.edit = self.ui.textEdit
        logger = logging.getLogger()
        logger.setLevel(logging.INFO)
        logger.addHandler(h)

    def set_conf(self, conf, section):
        '''
        设置参数至配置文件
        '''
        # 一般参数
        conf.set('watchdog', 'watchdog_enable',
                 str(self.ui.checkBox.isChecked()))
        conf.set('watchdog', 'max_win_time', str(self.ui.lineEdit.text()))
        conf.set('watchdog', 'max_op_time', str(self.ui.lineEdit_2.text()))

        # 御魂参数
        if section == 0 or section == 4:
            # 御魂
            conf.set('mitama', 'mitama_click_partner_left',
                     str(self.ui.mitama_click_partner_left.isChecked()))
            conf.set('mitama', 'mitama_click_partner_right',
                     str(self.ui.mitama_click_partner_right.isChecked()))

        # 探索参数
        if section == 1 or section == 4:
            # 探索
            conf.set('explore', 'fight_boss_enable',
                     str(self.ui.checkBox_2.isChecked()))
            conf.set('explore', 'tupo_enable',
                     str(self.ui.checkBox_4.isChecked()))
            conf.set('explore', 'slide_shikigami',
                     str(self.ui.checkBox_3.isChecked()))
            conf.set('explore', 'slide_shikigami_progress',
                     str(self.ui.horizontalSlider.value()))
            conf.set('explore', 'zhunbei_delay',
                     str(self.ui.lineEdit_3.text()))

        # 百鬼夜行参数
        if section == 2 or section == 4:
            pass

        # 结界突破参数
        if section == 3 or section == 4:
            pass

        # 专项任务参数
        if section == 4:
            conf.set('task', 'tansuo', str(self.ui.lineEdit_4.text()))
            conf.set('task', 'yuhun', str(self.ui.lineEdit_5.text()))
            conf.set('task', 'juexing', str(self.ui.lineEdit_6.text()))
            conf.set('task', 'tupo', str(self.ui.lineEdit_7.text()))

            # 御魂
            conf.set('mitama', 'mitama_click_partner_left', 'True')
            conf.set('mitama', 'mitama_click_partner_right', 'False')

            # 探索
            conf.set('explore', 'fight_boss_enable', 'True')
            conf.set('explore', 'tupo_enable', 'False')

    def get_conf(self, section):
        conf = configparser.ConfigParser()
        # 读取配置文件
        conf.read('conf.ini', encoding="utf-8")

        # 修改配置
        try:
            self.set_conf(conf, section)
        except:
            conf.add_section('watchdog')
            conf.add_section('explore')
            conf.add_section('mitama')
            conf.add_section('task')
            self.set_conf(conf, section)

        # 保存配置文件
        with open('conf.ini', 'w') as configfile:
            conf.write(configfile)

    def start_onmyoji(self):
        section = self.ui.tabWidget.currentIndex()

        # 读取配置
        self.get_conf(section)

        if section == 0:
            # 御魂
            if self.ui.mitama_single.isChecked():
                # 单刷
                self.fight = SingleFight()

            elif self.ui.mitama_driver.isChecked():
                # 司机
                self.fight = DriverFighter()

            elif self.ui.mitama_passenger.isChecked():
                # 乘客
                self.fight = FighterPassenger()

            elif self.ui.mitama_dual.isChecked():
                # 双开
                self.fight = DualFighter()

        elif section == 1:
            # 探索
            self.fight = ExploreFight()

        elif section == 2:
            # 百鬼夜行
            self.fight = Ghost()

        elif section == 3:
            # 结界突破
            if self.ui.individual.isChecked():
                # 个人突破
                self.fight = Breakthrough()

            elif self.ui.shack.isChecked():
                # 个人突破
                self.fight = ShackBreakthrough()

        elif section == 4:
            self.fight = Task()

        task = threading.Thread(target=self.fight.start)
        task.start()

    def stop_onmyoji(self):
        try:
            self.fight.deactivate()
        except:
            pass
Example #24
0
def runHmmBuild(alignmentPath, workingDir, outputPath):
    tempPath = os.path.join(os.path.dirname(outputPath), "temp_{}".format(os.path.basename(outputPath)))
    args = [Configs.hmmbuildPath,'--ere', '0.59', "--cpu", "1"]
    args.extend(["--symfrac", "0.0", "--informat", "afa", tempPath, alignmentPath])
    taskArgs = {"command" : subprocess.list2cmdline(args), "fileCopyMap" : {tempPath : outputPath}, "workingDir" : workingDir}
    return Task(taskType = "runCommand", outputFile = outputPath, taskArgs = taskArgs)
Example #25
0
 def __init__(self, fs, inputs, density=512):
     Task.__init__(self, fs)
     self.inputs = inputs
     self.inputs = (*inputs, density)
     self._parents = self.create_parents()
     self.path = os.path.join(self.fs, self.name() + ".npy")
Example #26
0
def main():
    in_args = get_input_args()

    exportPath = './data/'
    if not os.path.exists(exportPath):
        os.makedirs(exportPath)

    # z axis is up
    init_pose = np.array([0.0, 0.0, 1.0, 0.0, 0.0, 0.0])
    target_pos = np.array([0.0, 0.0, 10.0])
    task = Task(init_pose=init_pose, target_pos=target_pos, runtime=15.0)
    #agent = PolicySearch_Agent(task)
    #agent = Basic_Agent(task)
    agent = DDPG_Agent(task)

    # before training
    resultsAll = []
    high_score = -1000000.0
    low_score = 1000000.0

    # do this in each episode

    for i_episode in range(1, in_args.num_episodes + 1):
        # start a new episode
        state = agent.reset_episode()
        score = 0

        episode_results = {
            'time': [],
            'x': [],
            'y': [],
            'z': [],
            'phi': [],
            'theta': [],
            'psi': [],
            'vx': [],
            'vy': [],
            'vz': [],
            'reward': [],
        }

        while True:
            action = agent.act(state)
            next_state, reward, done = task.step(action)

            agent.step(action, reward, next_state, done)
            state = next_state
            score += reward
            high_score = max(high_score, score)
            low_score = min(low_score, score)

            # track the results for offline analysis
            episode_results['time'].append(task.sim.time)
            episode_results['x'].append(state[0])
            episode_results['y'].append(state[1])
            episode_results['z'].append(state[2])
            episode_results['phi'].append(state[3])
            episode_results['theta'].append(state[4])
            episode_results['psi'].append(state[5])
            episode_results['vx'].append(state[6])
            episode_results['vy'].append(state[7])
            episode_results['vz'].append(state[8])
            episode_results['reward'].append(reward)

            if done:
                print(
                    "\rEpisode = {:4d}, score = {:7.3f}, low score = {:7.3f}, high score = {:7.3f}"
                    .format(i_episode, score, low_score, high_score),
                    end="")
                break

        resultsAll.append(episode_results)

        sys.stdout.flush()

    # save results for later analysis
    with open("{}results0.bin".format(exportPath), 'wb') as pickleFile:
        pickle.dump(resultsAll, pickleFile)

    print("\n")