Ejemplo n.º 1
0
    def _start_application(self):
        """ Creates and initializes objects"""

        log.set_vs_log(SETTINGS.loglevel, SETTINGS.logrotate, start_string)

        save_pid()
        save_version()

        try:
            import stitcher
            import camera
            import display
            from output.output_manager import OutputManager
            from project_manager import ProjectManager
            from preset_manager import PresetManager
        except ImportError:
            logger.error("cannot import dependencies. Aborting\n")
            raise

        self.preset_manager = PresetManager()
        self.camera = camera.Camera(self)
        if SETTINGS.ptv is not None:
            self.project_manager = ProjectManager(SETTINGS.ptv)
        else:
            self.project_manager = ProjectManager(
                defaults.USER_DEFAULT_PTV_PATH)

        self.display = display.Display(self)
        self.stitcher = stitcher.Stitcher(
            self, stitcher_api.StitcherAPI.stitcher_executor, self.display)
        self.output_manager = OutputManager(self.stitcher)

        app = make_application_API(self, self.stitcher, self.output_manager,
                                   self.preset_manager, self.project_manager,
                                   self.camera, SETTINGS.verbose)
        self.http_server = httpserver.HTTPServer(app)

        self.camera.t_init()

        if Debugging is not None:
            self.debugging = Debugging(self.output_manager,
                                       self.preset_manager)
            blinker.signal("start_debug_failed").connect(
                self.stitcher.terminate)

        CLIENT_MESSENGER.send_event("server_started", {
            "date": str(datetime.datetime.now()),
            "session": defaults.SESSION_UUID
        })

        try:
            refs.load()
            self.http_server.listen(SETTINGS.port)
            self.t_run()
        except socket.error, msg:
            global EXIT_MESSAGE
            global EXIT_CODE
            EXIT_MESSAGE = "Socket error: " + str(msg)
            EXIT_CODE = -1
            self.stop()
Ejemplo n.º 2
0
 def process_machine_settings(self, mset):
     if 'machine_info' in mset:
         machine_info = mset.machine_info
         if isinstance(machine_info, dict) or isinstance(machine_info, obj):
             for machine_name, minfo in machine_info.iteritems():
                 mname = machine_name.lower()
                 if Machine.exists(mname):
                     machine = Machine.get(mname)
                     machine.incorporate_user_info(minfo)
                 else:
                     self.error(
                         'machine {0} is unknown\n  cannot set machine_info'
                         .format(machine_name))
                 #end if
             #end for
         else:
             self.error(
                 'machine_info must be a dict or obj\n  you provided type '
                 + machine_info.__class__.__name__)
         #end if
     #end if
     if 'machine' in mset:
         machine_name = mset.machine
         if not Machine.exists(machine_name):
             self.error('machine {0} is unknown'.format(machine_name))
         #end if
         Job.machine = machine_name
         ProjectManager.machine = Machine.get(machine_name)
         if 'account' in mset:
             account = mset.account
             if not isinstance(account, str):
                 self.error(
                     'account for {0} must be a string\n  you provided: {1}'
                     .format(machine_name, account))
             #end if
             ProjectManager.machine.account = account
         #end if
         if 'machine_mode' in mset:
             machine_mode = mset.machine_mode
             if machine_mode in Machine.modes:
                 machine_mode = Machine.modes[machine_mode]
             #end if
             if machine_mode == Machine.modes.interactive:
                 if ProjectManager.machine == None:
                     ProjectManager.class_error(
                         'no machine specified for interactive mode')
                 #end if
                 if not isinstance(ProjectManager.machine, Supercomputer):
                     self.error(
                         'interactive mode is not supported for machine type '
                         + ProjectManager.machine.__class__.__name__)
                 #end if
                 if not 'interactive_cores' in mset:
                     self.error(
                         'interactive mode requested, but interactive_cores not set'
                     )
                 #end if
                 ProjectManager.machine = ProjectManager.machine.interactive_representation(
                     mset.interactive_cores)
                 Job.machine = ProjectManager.machine.name
Ejemplo n.º 3
0
 def setUp(self):
     SETTINGS.current_audio_source = ProjectManager.AUDIO_NOAUDIO
     self.project_manager = ProjectManager(TEST_PTV_FILEPATH)
     self.stitcher_controller = self.project_manager.create_controller()
     self.manager = AlgorithmManager(self.stitcher_controller)
     with open(TEST_RIG_PARAMETERS_FILEPATH, "r") as rig_params_file:
         self.rig_parameters = rig_params_file.read()
Ejemplo n.º 4
0
def main(project, description):
    pm = ProjectManager()

    pm.project_note(
        project,
        description,
    )
Ejemplo n.º 5
0
def test_screen_fake_sims():
    from generic import NexusError
    from simulation import Simulation
    from project_manager import ProjectManager

    from test_simulation_module import get_test_workflow, n_test_workflows

    sims = []
    for n in range(n_test_workflows):
        sims.extend(get_test_workflow(n).list())
    #end for

    pm = ProjectManager()
    pm.add_simulations(sims)

    pm.screen_fake_sims()

    s = sims[len(sims) // 2]
    s.fake_sim = True

    try:
        pm.screen_fake_sims()
        raise FailedTest
    except NexusError:
        None
    except FailedTest:
        failed()
    except Exception as e:
        failed(str(e))
    #end try

    Simulation.clear_all_sims()
Ejemplo n.º 6
0
 def add_project(self):
     dialog = Dialog()
     staff_data_list = StaffManager.search_idle_staff()
     for staff in staff_data_list:
         dialog.listWidgetA.addItem(QtGui.QListWidgetItem(staff[1]))
     if dialog.exec_():
         dic = dialog.get_add_datas()
         attendee_ids = copy.deepcopy(dic['attendee_ids'])
         del dic['attendee_ids']
         project = Project(**dic)
         project = ProjectManager.add_project(project)
         StaffManager.add_staff_project(project.id, attendee_ids)
         search_datas = ProjectManager.get_all_project_and_format()
         self.refresh_project(search_datas)
         dialog.destroy()
Ejemplo n.º 7
0
 def search_project_by_name(self):
     project_name = unicode(self.name_edit.text())
     if project_name not in (None, ''):
         search_datas = ProjectManager.search_project_by_name(project_name)
         self.my_table.refresh_project(search_datas)
     else:
         ToolsManager.information_box(u'注意', u'请填写项目名再搜索!')
Ejemplo n.º 8
0
def main(trackname):
    # 1. Make sure that this actually exists in my track targets, if not throw an exception
    pm = ProjectManager()
    track_path = pm.personal_dir
    track_targets_path = '{}/track_targets'.format(track_path)
    all_track_targets = sorted(os.listdir(track_targets_path))
    if trackname + '.track' not in all_track_targets:
        raise ValueError(
            "Error, the trackname provided is not a current track target")
    elif trackname in [
            'weekly_goals', 'monthly_goals', 'quarterly_goals', 'yearly_goals'
    ]:
        raise ValueError("Error, cannot ignore {}".format(trackname))
    else:
        ignore = Ignore()
        ignored_tracks = ignore.get_ignored_tracks()
        ignored_tracks.add(trackname)

        # and finally save it
        with open(ignore.ignore_path, 'wb') as f:
            pk.dump(ignored_tracks, f)

        print(
            bcolors.BOLD + bcolors.OKBLUE + "\n\t" + trackname +
            " has officially been ignored. \n\tPlease execute unignore_track.py to unignore this track name.\n"
            + bcolors.ENDC)
Ejemplo n.º 9
0
 def process_machine_settings(self,mset):
     if 'machine_info' in mset:
         machine_info = mset.machine_info
         if isinstance(machine_info,dict) or isinstance(machine_info,obj):
             for machine_name,minfo in machine_info.iteritems():
                 mname = machine_name.lower()
                 if Machine.exists(mname):
                     machine = Machine.get(mname)
                     machine.incorporate_user_info(minfo)
                 else:
                     self.error('machine {0} is unknown\n  cannot set machine_info'.format(machine_name))
                 #end if
             #end for
         else:
             self.error('machine_info must be a dict or obj\n  you provided type '+machine_info.__class__.__name__)
         #end if
     #end if
     if 'machine' in mset:
         machine_name = mset.machine
         if not Machine.exists(machine_name):
             self.error('machine {0} is unknown'.format(machine_name))
         #end if
         Job.machine = machine_name
         ProjectManager.machine = Machine.get(machine_name)
         if 'account' in mset:
             account = mset.account
             if not isinstance(account,str):
                 self.error('account for {0} must be a string\n  you provided: {1}'.format(machine_name,account))
             #end if
             ProjectManager.machine.account = account
         #end if
         if 'machine_mode' in mset:
             machine_mode = mset.machine_mode
             if machine_mode in Machine.modes:
                 machine_mode = Machine.modes[machine_mode]
             #end if
             if machine_mode==Machine.modes.interactive:
                 if ProjectManager.machine==None:
                     ProjectManager.class_error('no machine specified for interactive mode')
                 #end if
                 if not isinstance(ProjectManager.machine,Supercomputer):
                     self.error('interactive mode is not supported for machine type '+ProjectManager.machine.__class__.__name__)
                 #end if
                 if not 'interactive_cores' in mset:
                     self.error('interactive mode requested, but interactive_cores not set')
                 #end if
                 ProjectManager.machine = ProjectManager.machine.interactive_representation(mset.interactive_cores)
Ejemplo n.º 10
0
 def delete_project(self):
     indexes = self.selectionModel().selectedRows()
     if len(indexes) == 0:
         ToolsManager.information_box(u"注意", u"请选择一行或多行进行删除!")
     else:
         button = ToolsManager.question_box(u"提醒", u"是否删除选中行?")
         if button == QtGui.QMessageBox.Ok:
             ids_list = []
             for index in sorted(indexes):
                 id_text = self.item(index.row(), 0).text()
                 ids_list.append(int(id_text))
             ProjectManager.delete_project(ids_list)
             StaffManager.delete_staff_project_by_project_ids(ids_list)
             search_datas = ProjectManager.get_all_project_and_format()
             self.refresh_project(search_datas)
         else:
             pass
Ejemplo n.º 11
0
    def __init__(self,parent=None):
        super(MyTable,self).__init__(parent)

        head_labels = constant.PROJECT_COLUMN
        self.setColumnCount(len(head_labels))
        self.setRowCount(0)
        self.setHorizontalHeaderLabels(head_labels)
        search_datas = ProjectManager.get_all_project_and_format()
        self.refresh_project(search_datas)
Ejemplo n.º 12
0
 def search_project_by_date(self):
     para = {
         'start_time': self.start_time_edit.date().toPyDate(),
         'end_time': self.end_time_edit.date().toPyDate()
     }
     if para['end_time'] < para['start_time']:
         ToolsManager.information_box(u'注意', u'起始日期应该小于终止日期!')
     else:
         search_datas = ProjectManager.search_project_by_date(**para)
         self.my_table.refresh_project(search_datas)
Ejemplo n.º 13
0
def main():
    """
    Main Method, used to test program
    """

    # 1. create project
    # projectName = 'kilimanjaro'
    project_name = 'sanfrancisco'
    project = ProjectManager(project_name)

    # show_grid_results(project)
    # 3. create images
    answ = input('Do you want to create the images (y/n)?: ')
    if answ == 'y':
        answ = input('Batch create(y/n)?: ')
        if answ == 'y':
            project.batch_create_imagery()
        else:
            image_creator.create_images(project)

    # 4. display the image
    answ = input('Do you want to display the images (y/n)?: ')
    if answ == 'y':
        show_image(project, 'rgb', cropped=False)

    # clustering
    clusters = 7
    cropped = True
    image_type = 'rgb'
    # 5. classify the image
    answ = input('Do you want to classify the images (y/n)?: ')
    # answ = 'y'
    if answ == 'y':
        kmeans_cluster(project, clusters, image_type, cropped)
        # gmm_cluster(project, clusters, image_type, cropped)
        # dbscan_cluster(project, 5, 100, image_type, cropped)
        # plot_cost_function(project, image_type)

    # 6. show classified image
    answ = input('Do you want to show the classified images (y/n)?: ')
    if answ == 'y':
        # convert_to_png(project, 'ndvi', False, True, clusters)
        show_clustering(project, cropped)
Ejemplo n.º 14
0
class TestProjectManager(unittest.TestCase):
    def setUp(self):
        SETTINGS.current_audio_source = ProjectManager.AUDIO_NOAUDIO
        self.project_manager = ProjectManager(TEST_PTV_FILEPATH)

    def test_save(self):
        exposure = self.project_manager.project_config.has("exposure")
        exposure = exposure.clone()

        exposure.push("updated", vs.Value.boolObject(True))

        self.project_manager.update("exposure", exposure, auto_save=False)
        self.project_manager.save(TEST_PTV_SAVEPATH)

        updated_project = ProjectManager(TEST_PTV_SAVEPATH)

        self.assertEqual(
            exposure.has("updated").getBool(),
            updated_project.project_config.has("exposure").has(
                "updated").getBool())
Ejemplo n.º 15
0
    def update_project(self):
        indexes = self.selectionModel().selectedRows()
        if(len(indexes)) == 1:
            dialog = Dialog()
            id_text = self.item(indexes[0].row(), 0).text()
            project_item = ProjectManager.get_one_item_by_project_id(int(id_text))

            dialog.name_edit.setText(project_item.name)
            dialog.search_id_edit.setText(project_item.search_id)
            dialog.source_place_edit.setCurrentIndex(dialog.source_place_edit.findText(project_item.source_place))
            dialog.main_designer_edit.setText(project_item.main_designer)
            dialog.design_all_edit.setText(project_item.design_all)
            dialog.responsible_man_edit.setText(project_item.responsible_man)
            dialog.start_time_edit.setDate(project_item.start_time)
            dialog.end_time_edit.setDate(project_item.end_time)
            dialog.description_edit.setText(project_item.description)
            dialog.name_edit.setReadOnly(True)
            staff_str = StaffManager.search_staff_by_project_id(project_item.id)
            if staff_str == '':         # 项目里没人
                staff_data_list = StaffManager.search_idle_staff()
                for staff in staff_data_list:
                    dialog.listWidgetA.addItem(staff[1])            # "1"是列表的的名字字段
            else:
                staff_name_list = staff_str.split(',')
                for staff_name in staff_name_list:
                    dialog.listWidgetB.addItem(staff_name)
                staff_data_list = StaffManager.search_idle_staff()
                for staff in staff_data_list:
                    if staff[1] not in staff_name_list:
                        dialog.listWidgetA.addItem(staff[1])

            if dialog.exec_():
                dic = dialog.get_add_datas()
                dic['id'] = int(id_text)
                ProjectManager.updata_project(dic)
                search_datas = ProjectManager.get_all_project_and_format()
                self.refresh_project(search_datas)
                dialog.destroy()
        else:
            # 弹出警告
            ToolsManager.information_box(u"注意", u"请选择一行进行更新!")
Ejemplo n.º 16
0
def test_init():
    from generic import obj
    from nexus_base import nexus_core
    from project_manager import ProjectManager

    pm = ProjectManager()

    modes = nexus_core.modes
    assert (pm.persistent_modes == set([modes.submit, modes.all]))
    assert (pm.simulations == obj())
    assert (pm.cascades == obj())
    assert (pm.progressing_cascades == obj())
Ejemplo n.º 17
0
def test_load_cascades():
    from simulation import Simulation
    from project_manager import ProjectManager

    from test_simulation_module import get_test_workflow

    sims = get_test_workflow(1)

    pm = ProjectManager()
    pm.add_simulations(sims.list())

    idc = id(pm.cascades)
    idp = id(pm.progressing_cascades)

    pm.load_cascades()

    assert (list(pm.cascades.keys()) == [sims.s1.simid])
    assert (list(pm.progressing_cascades.keys()) == [sims.s1.simid])
    assert (id(pm.cascades[sims.s1.simid]) == id(sims.s1))
    assert (id(pm.progressing_cascades[sims.s1.simid]) == id(sims.s1))

    assert (id(pm.cascades) != idc)
    assert (id(pm.progressing_cascades) != idp)

    Simulation.clear_all_sims()
Ejemplo n.º 18
0
def run_project(*args,**kwargs):
    if nexus_core.graph_sims:
        graph_sims()
    #end if
    pm = ProjectManager()
    pm.add_simulations(*args,**kwargs)
    pm.run_project()
    return pm
Ejemplo n.º 19
0
def main(track_date, track_target, track_value, is_all):
    pm = ProjectManager()
    track_path = pm.personal_dir
    track_targets_path = '{}/track_targets'.format(track_path)
    all_track_targets = sorted([x for x in os.listdir(track_targets_path) if x.endswith('.track')])

    to_show = False

     # today
    if not track_target and not track_date and not track_value: # user just called track.py with no arguments --> show targets for today
        print("\nCurrent track targets for today :")
        track_date, dt = get_date_from_string('t')
        to_show = True

    elif track_date and not track_target and not track_value: # user provided a date but nothing else
        track_date, dt = get_date_from_string(track_date)
        print("\nCurrent track targets for {}".format(track_date))
        to_show = True

    elif not track_target or not track_date or not track_value: # user forgot 1 argument
        raise_fail_error("Error. please execute \n\tpython track.py [YYYY-MM-DD] [target] [value]")

    if not to_show:
        track_date, dt = get_date_from_string(track_date) 

    # adapt all_track_targets for weekly_goals, monthly_goals, quarterly_goals, yearly_goals
    iso_info = get_iso_info(dt)
    for key in ['week', 'month', 'quarter', 'year']:
        key1 = key + 'ly_goals.track'
        key2 = key + '_end'
        # if we are tracking ***ly_goals but we are not on the appropriate day, then just remove it from all_track_targets
        if key1 in all_track_targets and dt != iso_info[key2]:
            all_track_targets.remove(key1) 

    if to_show:
        print('Showing track targets for', track_date)
        show_tracks_for_date(track_date, all_track_targets, track_targets_path, is_all)
        return

    if '{}.track'.format(track_target) not in all_track_targets:
        raise_fail_error("Error. Target is not tracked.")

    ignore = Ignore()
    ignored_tracks = ignore.get_ignored_tracks()
    if track_target in ignored_tracks:
        print(bcolors.FAIL + "\n\tError, this is an ignored track. \n\tPlease unignore it first with unignore_track.py\n" + bcolors.ENDC)
        return

    with open('{}/track_targets/{}.track'.format(track_path, track_target), 'a') as _in:
        _in.write('{ds},{val}\n'.format(ds=track_date, val=track_value))
Ejemplo n.º 20
0
    def test_save(self):
        exposure = self.project_manager.project_config.has("exposure")
        exposure = exposure.clone()

        exposure.push("updated", vs.Value.boolObject(True))

        self.project_manager.update("exposure", exposure, auto_save=False)
        self.project_manager.save(TEST_PTV_SAVEPATH)

        updated_project = ProjectManager(TEST_PTV_SAVEPATH)

        self.assertEqual(
            exposure.has("updated").getBool(),
            updated_project.project_config.has("exposure").has(
                "updated").getBool())
Ejemplo n.º 21
0
def test_propagate_blockages():
    from generic import NexusError
    from simulation import Simulation
    from project_manager import ProjectManager

    from test_simulation_module import get_test_workflow, n_test_workflows

    sims = []
    for n in range(n_test_workflows):
        sims.extend(get_test_workflow(n).list())
    #end for

    for s in sims:
        assert (not s.block)
        assert (not s.block_subcascade)
    #end for

    pm = ProjectManager()
    pm.add_simulations(sims)

    pm.propagate_blockages()

    nb = 5
    dn = len(sims) // nb
    for b in range(nb):
        s = sims[nb * b]
        s.block = True
    #end for

    pm.propagate_blockages()

    def assert_blocked(sim):
        assert (sim.block)
        assert (sim.block_subcascade)

    #end def assert_blocked

    for b in range(nb):
        s = sims[nb * b]
        s.traverse_full_cascade(assert_blocked)
    #end for

    Simulation.clear_all_sims()
Ejemplo n.º 22
0
def test_resolve_file_collisions():
    from generic import NexusError
    from simulation import Simulation
    from project_manager import ProjectManager

    from test_simulation_module import get_test_workflow, n_test_workflows

    divert_nexus_log()

    sims = []
    for n in range(n_test_workflows):
        sims.extend(get_test_workflow(n).list())
    #end for

    pm = ProjectManager()
    pm.add_simulations(sims)

    pm.resolve_file_collisions()

    s1 = sims[len(sims) // 2]
    s2 = sims[len(sims) // 2 + 1]

    s2.locdir = s1.locdir
    s2.outfile = s1.outfile

    try:
        pm.resolve_file_collisions()
        raise FailedTest
    except NexusError:
        None
    except FailedTest:
        failed()
    except Exception as e:
        failed(str(e))
    #end try

    restore_nexus_log()

    Simulation.clear_all_sims()
Ejemplo n.º 23
0
def main(track_target, min_value, max_value, direction, aggregator, units):
    if direction not in ['up', 'down']:
        raise_fail_error("Error. Direction must be in [up, down]. For more info:\n\tpython start_track.py -h")
    if aggregator not in ['mean', 'sum', 'max', 'min']:
        raise_fail_error("Error. Aggregator must be in [mean, sum, max, min]. For more info:\n\tpython start_track.py -h")
    pm = ProjectManager()
    personal_dir = pm.personal_dir
    track_targets_dir = '{}/track_targets'.format(personal_dir)

    all_track_targets = os.listdir(track_targets_dir)
    if '{}.track'.format(track_target) in all_track_targets:
        raise_fail_error("Error. Tracking already exists")

    with open('{}/{}.track'.format(track_targets_dir, track_target), 'w') as _in:
        _in.write('{min},{max},{dir},{agg},{units}\n'.format(
            min=min_value,
            max=max_value,
            dir=direction,
            agg=aggregator,
            units=units,
        ))
Ejemplo n.º 24
0
def test_traverse_cascades():
    from simulation import Simulation
    from project_manager import ProjectManager

    from test_simulation_module import get_test_workflow, n_test_workflows

    sims = []
    for n in range(n_test_workflows):
        sims.extend(get_test_workflow(n).list())
    #end for

    pm = ProjectManager()
    pm.add_simulations(sims)

    pm.traverse_cascades()

    def count_visits(sim, visit_counts):
        i = sim.simid
        if i not in visit_counts:
            visit_counts[i] = 1
        else:
            visit_counts[i] += 1
        #end if

    #end def count_visits

    counts = dict()

    pm.traverse_cascades(count_visits, counts)

    assert (len(counts) == len(sims))
    for s in sims:
        assert (s.simid in counts)
        assert (counts[s.simid] == 1)
    #end for

    Simulation.clear_all_sims()
Ejemplo n.º 25
0
def test_add_simulations():
    from simulation import Simulation
    from project_manager import ProjectManager

    from test_simulation_module import get_test_workflow
    sims = get_test_workflow(1)

    pm = ProjectManager()
    pm.add_simulations(sims.list())

    assert (list(pm.cascades.keys()) == [sims.s1.simid])
    assert (list(pm.progressing_cascades.keys()) == [sims.s1.simid])
    assert (id(pm.cascades[sims.s1.simid]) == id(sims.s1))
    assert (id(pm.progressing_cascades[sims.s1.simid]) == id(sims.s1))

    assert (len(pm.simulations) == 3)
    n = 0
    for s in sims:
        assert (s.simid in pm.simulations)
        assert (id(pm.simulations[s.simid]) == id(s))
        n += 1
    #end for
    assert (n == 3)

    pm = ProjectManager()
    pm.add_simulations()
    assert (len(pm.simulations) == len(Simulation.all_sims))
    n = 0
    for s in Simulation.all_sims:
        assert (s.simid in pm.simulations)
        assert (id(pm.simulations[s.simid]) == id(s))
        n += 1
    #end for
    assert (n >= 3)

    Simulation.clear_all_sims()
Ejemplo n.º 26
0
class TestAlgorithmManager(unittest.TestCase):
    def setUp(self):
        SETTINGS.current_audio_source = ProjectManager.AUDIO_NOAUDIO
        self.project_manager = ProjectManager(TEST_PTV_FILEPATH)
        self.stitcher_controller = self.project_manager.create_controller()
        self.manager = AlgorithmManager(self.stitcher_controller)
        with open(TEST_RIG_PARAMETERS_FILEPATH, "r") as rig_params_file:
            self.rig_parameters = rig_params_file.read()

    def test_create(self):
        self.assertIsInstance(AlgorithmManager.create_algorithm(CalibrationRunner.name, self.rig_parameters), CalibrationRunner)

    def test_algorithm_running(self):
        self.manager.start_calibration(self.rig_parameters)
        algorithm = self.manager.algorithm_scheduler.scheduled_algorithms[CalibrationRunner.name]
        self.manager.get_next_algorithm(self.project_manager.panorama)
        self.assertIn(algorithm, self.manager.running_algorithms)

    def test_cancel(self):
        self.manager.start_calibration(self.rig_parameters)
        algorithm = self.manager.algorithm_scheduler.scheduled_algorithms[CalibrationRunner.name]
        self.manager.get_next_algorithm(self.project_manager.panorama)
        self.manager.cancel_running_algorithms()
        self.assertFalse(self.manager.running_algorithms)
Ejemplo n.º 27
0
def test_check_dependencies():
    from simulation import Simulation
    from project_manager import ProjectManager

    from test_simulation_module import get_test_workflow

    divert_nexus_log()

    sims = get_test_workflow(1)

    pm = ProjectManager()
    pm.add_simulations(sims.list())

    idc = id(pm.cascades)
    idp = id(pm.progressing_cascades)

    pm.check_dependencies()

    restore_nexus_log()

    Simulation.clear_all_sims()
Ejemplo n.º 28
0
def run_project(*args,**kwargs):
    pm = ProjectManager()
    pm.add_simulations(*args,**kwargs)
    pm.run_project()
Ejemplo n.º 29
0
    def __call__(self,**kwargs):

        # guard against invalid settings
        not_allowed = set(kwargs.keys()) - self.all_vars
        if len(not_allowed)>0:
            self.error('unrecognized variables provided.\n  You provided: '+str(list(not_allowed))+'\n  Allowed variables are: '+str(list(vars)))
        #end if

        # extract settings based on keyword groups
        kw = Settings.kw_set(self.project_vars,kwargs)       # project settings
        gamess_kw = Settings.kw_set(self.gamess_vars,kwargs) # gamess settings
        if len(kwargs)>0:
            self.error('some settings keywords have not been accounted for\nleftover keywords: {0}\nthis is a developer error'.format(sorted(kwargs.keys())))
        #end if

        # transfer project variables to project base class
        for name,value in kw.iteritems():
            Pobj.__dict__[name] = value
        #end for

        # process project manager settings
        if 'debug' in kw and kw.debug:
            Pobj.verbose = True
        #end if
        if 'mode' in kw:
            Pobj.set_mode(kw.mode)
        #end if

        # process machine settings
        if 'machine_info' in kw:
            machine_info = Pobj.machine_info
            del Pobj.machine_info
            if isinstance(machine_info,dict) or isinstance(machine_info,obj):
                for machine_name,minfo in machine_info.iteritems():
                    mname = machine_name.lower()
                    if Machine.exists(mname):
                        machine = Machine.get(mname)
                        machine.incorporate_user_info(minfo)
                    else:
                        self.error('machine {0} is unknown\n  cannot set machine_info'.format(machine_name))
                    #end if
                #end for
            else:
                self.error('machine_info must be a dict or obj\n  you provided type '+machine_info.__class__.__name__)
            #end if
        #end if
        if 'machine' in kw:
            machine_name = kw.machine
            if not Machine.exists(machine_name):
                Pobj.class_error('machine {0} is unknown'.format(machine_name))
            #end if
            Job.machine = machine_name
            ProjectManager.machine = Machine.get(machine_name)
            #del Pobj.machine
            if 'account' in kw:
                account = Pobj.account
                #del Pobj.account
                if not isinstance(account,str):
                    self.error('account for {0} must be a string\n  you provided: {1}'.format(machine_name,account))
                #end if
                ProjectManager.machine.account = account
            #end if
            if 'machine_mode' in kw:
                machine_mode = kw.machine_mode
                if machine_mode in Machine.modes:
                    machine_mode = Machine.modes[machine_mode]
                #end if
                if machine_mode==Machine.modes.interactive:
                    if ProjectManager.machine==None:
                        ProjectManager.class_error('no machine specified for interactive mode')
                    #end if
                    if not isinstance(ProjectManager.machine,Supercomputer):
                        self.error('interactive mode is not supported for machine type '+ProjectManager.machine.__class__.__name__)
                    #end if
                    if not 'interactive_cores' in kw:
                        self.error('interactive mode requested, but interactive_cores not set')
                    #end if
                    ProjectManager.machine = ProjectManager.machine.interactive_representation(Pobj.interactive_cores)
                    del Pobj.interactive_cores
                #end if
                del Pobj.machine_mode
            #end if
        #end if

        # process simulation settings
        if 'local_directory' in kw:
            Pobj.file_locations.append(kw.local_directory)
        #end if
        if 'skip_submit' in kw:
            Pobj.skip_submission = Pobj.skip_submit
            del Pobj.skip_submit
        #end if
        if 'file_locations' in kw:
            fl = kw.file_locations
            if isinstance(fl,str):
                Pobj.file_locations.extend([fl])
            else:
                Pobj.file_locations.extend(list(fl))
            #end if
        #end if
        if not 'pseudo_dir' in kw:
            Pobj.pseudopotentials = Pseudopotentials()
        else:
            pseudo_dir = kw.pseudo_dir
            Pobj.file_locations.append(pseudo_dir)
            if not os.path.exists(pseudo_dir):
                self.error('pseudo_dir "{0}" does not exist'.format(pseudo_dir),trace=False)
            #end if
            files = os.listdir(pseudo_dir)
            ppfiles = []
            for f in files:
                pf = os.path.join(pseudo_dir,f)
                if os.path.isfile(pf):
                    ppfiles.append(pf)
                #end if
            #end for
            Pobj.pseudopotentials = Pseudopotentials(ppfiles)        
        #end if

        # more simulation/project manager settings processing
        mode = Pobj.mode
        modes = Pobj.modes
        if mode==modes.stages:
            stages = Pobj.stages
        elif mode==modes.all:
            stages = list(Pobj.primary_modes)
        else:
            stages = [kw.mode]
        #end if
        allowed_stages = set(Pobj.primary_modes)
        if isinstance(stages,str):
            stages = [stages]
        #end if
        if len(stages)==0:
            stages = list(Pobj.primary_modes)
            #self.error('variable stages must be a list of primary modes.\n  Options are '+str(list(allowed_stages)))
        elif 'all' in stages:
            stages = list(Pobj.primary_modes)
        else:
            forbidden = set(Pobj.stages)-allowed_stages
            if len(forbidden)>0:
                self.error('some stages provided are not primary stages.\n  You provided '+str(list(forbidden))+'\n  Options are '+str(list(allowed_stages)))
            #end if
        #end if
        Pobj.mode = modes.stages
        Pobj.stages     = stages
        Pobj.stages_set = set(Pobj.stages)

        # process gamess settings
        Gamess.settings(**gamess_kw)

        return
Ejemplo n.º 30
0
def main(goal_date, goal_timeframe):
    pm = ProjectManager()
    personal_dir = pm.personal_dir

    # Everything will be based on the week, so the overlapping
    # days may be put into different quarters/months/years

    goal_date, dt = get_date_from_string(goal_date)
    iso_info = get_iso_info(dt)

    timeframe_dict = {
        'yearly': 1,
        'quarterly': 2,
        'monthly': 3,
        'weekly': 4,
        'daily': 4,
    }
    if goal_timeframe not in timeframe_dict:
        raise_fail_error(
            "Error. Please use:\n\tpython goals.py [YYYY-MM-DD] [daily,weekly,quarterly,yearly]"
        )
    timeframe_number = timeframe_dict[goal_timeframe]

    year = iso_info['year']
    quarter = iso_info['quarter']
    month = iso_info['month']
    week = iso_info['week']

    path_additions = {
        1: str(year),
        2: 'q{}'.format(str(quarter)),
        3: 'm{}'.format(str(month)),
        4: 'w{}'.format(str(week)),
    }
    full_dir_path = '{}/goals'.format(personal_dir)
    for i in range(1, timeframe_number + 1):
        full_dir_path += '/{}'.format(path_additions[i])

    call(['mkdir', '-p', full_dir_path])
    if goal_timeframe == 'daily':
        goal_name = goal_date
    else:
        start_day = iso_info['{}_start'.format(goal_timeframe[:-2])]
        end_day = iso_info['{}_end'.format(goal_timeframe[:-2])]

        goal_name = '{}_goal_{}--{}'.format(goal_timeframe, start_day.date(),
                                            end_day.date())

    default_string = \
"""context for the goals:


min_goal:

goal:

stretch_goal:


evaluation of the goals:"""

    pm.modify_file(
        goal_name,
        full_dir_path,
        default_string,
    )
Ejemplo n.º 31
0
	def test_get_profile_path(self):
		manager = ProjectManager()
		manager.get_profile_path()
		self.assertTrue(manager.get_profile_path)
Ejemplo n.º 32
0
#!/usr/bin/env python

import os
from channel import Listener
from project_manager import ProjectManager
from library import *

workspace_path = os.path.join(os.getcwd(), '../workspace')

project_manager = ProjectManager()
project_manager.set_workspace(workspace_path)

class ProjectManagerServer(Listener):
    def __init__(self):
        self.subscribe('workspace', 'list', 'add')
        self.subscribe('workspace', 'list', 'request')
        self.subscribe('workspace', 'library', 'request')

    def on_message(self, channel, data):
        if channel == ('workspace', 'list', 'request'):
            self.publish(('workspace', 'list', 'response'), project_manager.get_projects())
        elif channel == ('workspace', 'library', 'request'):
            self.publish(('workspace', 'library', 'response'), project_manager.get_library())
        elif channel == ('workspace', 'list', 'add'):
            project_manager.add_project(data['name'])

# this will handle requests on a separate thread
pms = ProjectManagerServer()

# serve website on main thread
import staticfileserver
Ejemplo n.º 33
0
def run_project(*args, **kwargs):
    pm = ProjectManager()
    pm.add_simulations(*args, **kwargs)
    pm.run_project()
Ejemplo n.º 34
0
Archivo: project.py Proyecto: jyamu/qmc
    def __call__(self,**kwargs):
        vars = set(['machine','account','generate_only','verbose','debug','mode',
                    'local_directory','remote_directory','runs','results','sleep',
                    'file_locations','load_images','trace','machine_mode','stages',
                    'pseudo_dir','skip_submit','interactive_cores','monitor',
                    'status_only','machine_info'])

        keys = set(kwargs.keys())
        not_allowed = keys - vars
        if len(not_allowed)>0:
            Pobj.class_error('unrecognized variables provided.\n  You provided: '+str(list(not_allowed))+'\n  Allowed variables are: '+str(list(vars)),'settings')
        #end if

        for name,value in kwargs.iteritems():
            Pobj.__dict__[name] = value
        #end for

        if 'debug' in kwargs and kwargs['debug']:
            Pobj.verbose = True
        #end if
        if 'mode' in kwargs:
            Pobj.set_mode(kwargs['mode'])
        #end if
        if 'machine_info' in kwargs:
            machine_info = Pobj.machine_info
            del Pobj.machine_info
            if isinstance(machine_info,dict) or isinstance(machine_info,obj):
                for machine_name,minfo in machine_info.iteritems():
                    mname = machine_name.lower()
                    if Machine.exists(mname):
                        machine = Machine.get(mname)
                        machine.incorporate_user_info(minfo)
                    else:
                        Pobj.class_error('machine {0} is unknown\n  cannot set machine_info'.format(machine_name),'settings')
                    #end if
                #end for
            else:
                Pobj.class_error('machine_info must be a dict or obj\n  you provided type '+machine_info.__class__.__name__,'settings')
            #end if
        #end if
        if 'machine' in kwargs:
            machine_name = kwargs['machine']
            if not Machine.exists(machine_name):
                Pobj.class_error('machine {0} is unknown'.format(machine_name),'settings')
            #end if
            Job.machine = machine_name
            ProjectManager.machine = Machine.get(machine_name)
            #del Pobj.machine
            if 'account' in kwargs:
                account = Pobj.account
                #del Pobj.account
                if not isinstance(account,str):
                    Pobj.class_error('account for {0} must be a string\n  you provided: {1}'.format(machine_name,account),'settings')
                #end if
                ProjectManager.machine.account = account
            #end if
            if 'machine_mode' in kwargs:
                machine_mode = kwargs['machine_mode']
                if machine_mode in Machine.modes:
                    machine_mode = Machine.modes[machine_mode]
                #end if
                if machine_mode==Machine.modes.interactive:
                    if ProjectManager.machine==None:
                        ProjectManager.class_error('no machine specified for interactive mode','settings')
                    #end if
                    if not isinstance(ProjectManager.machine,Supercomputer):
                        Pobj.class_error('interactive mode is not supported for machine type '+ProjectManager.machine.__class__.__name__,'settings')
                    #end if
                    if not 'interactive_cores' in kwargs:
                        Pobj.class_error('interactive mode requested, but interactive_cores not set','settings')
                    #end if
                    ProjectManager.machine = ProjectManager.machine.interactive_representation(Pobj.interactive_cores)
                    del Pobj.interactive_cores
                #end if
                del Pobj.machine_mode
            #end if
        #end if
        if 'local_directory' in kwargs:
            Pobj.file_locations.append(kwargs['local_directory'])
        #end if
        if 'skip_submit' in kwargs:
            Pobj.skip_submission = Pobj.skip_submit
            del Pobj.skip_submit
        #end if
        if 'file_locations' in kwargs:
            fl = kwargs['file_locations']
            if isinstance(fl,str):
                Pobj.file_locations.extend([fl])
            else:
                Pobj.file_locations.extend(list(fl))
            #end if
        #end if
        if not 'pseudo_dir' in kwargs:
            Pobj.pseudopotentials = Pseudopotentials()
        else:
            pseudo_dir = kwargs['pseudo_dir']
            Pobj.file_locations.append(pseudo_dir)
            files = os.listdir(pseudo_dir)
            ppfiles = []
            for f in files:
                pf = os.path.join(pseudo_dir,f)
                if os.path.isfile(pf):
                    ppfiles.append(pf)
                #end if
            #end for
            Pobj.pseudopotentials = Pseudopotentials(ppfiles)        
        #end if

        mode = Pobj.mode
        modes = Pobj.modes
        if mode==modes.stages:
            stages = Pobj.stages
        elif mode==modes.all:
            stages = list(Pobj.primary_modes)
        else:
            stages = [kwargs['mode']]
        #end if
        allowed_stages = set(Pobj.primary_modes)
        if isinstance(stages,str):
            stages = [stages]
        #end if
        if len(stages)==0:
            stages = list(Pobj.primary_modes)
            #Pobj.class_error('variable stages must be a list of primary modes.\n  Options are '+str(list(allowed_stages)),'settings')
        elif 'all' in stages:
            stages = list(Pobj.primary_modes)
        else:
            forbidden = set(Pobj.stages)-allowed_stages
            if len(forbidden)>0:
                Pobj.class_error('some stages provided are not primary stages.\n  You provided '+str(list(forbidden))+'\n  Options are '+str(list(allowed_stages)),'settings')
            #end if
        #end if
        Pobj.mode = modes.stages
        Pobj.stages     = stages
        Pobj.stages_set = set(Pobj.stages)

        return
Ejemplo n.º 35
0
class MainWindow(QMainWindow):
    OFFSET_FOR_THE_IMAGE = 55
    signal = pyqtSignal()
    clickSignal = pyqtSignal(str)

    def __init__(self):
        super().__init__()
        self.berry_detection_bounding_box = None
        self.berry_image = 'berry_picture.jpg'
        self.berry_image_difference = None
        self.mdiArea = QMdiArea()
        self.background = "background.jpg"
        self.threadpool = QThreadPool()
        self.signal.connect(self.finished_find)
        self.clickSignal.connect(self.clicked_berry)
        self.picture_window = None
        self.text_window = None
        print("Multithreading with maximum %d threads" %
              self.threadpool.maxThreadCount())
        self.init_ui()

    def init_ui(self):
        icons_path = "icons/"

        self.setWindowTitle("Berry GUI")
        self.setGeometry(100, 200, 1280, 775)
        self.statusBar()
        extract_action = QAction("Save & Exit", self)
        extract_action.setShortcut("Ctrl+q")
        extract_action.setStatusTip("Leave the app")
        extract_action.triggered.connect(self.quit)

        extract_action_edit = QAction("Show files", self)
        extract_action_edit.setShortcut("Ctrl+f")
        extract_action_edit.setStatusTip("Looking for files")
        extract_action_edit.triggered.connect(self.quit)

        openEditor = QAction("Editor", self)
        openEditor.setShortcut("Ctrl+E")
        openEditor.setStatusTip("Open Editor")
        openEditor.triggered.connect(self.open_editor)

        openFile = QAction("Open File", self)
        openFile.setShortcut("Ctrl+o")
        openFile.setStatusTip("Open File")
        # openFile.triggered.connect(self.file_Open)

        mainMenu = self.menuBar()
        fileMenu = mainMenu.addMenu("&File")
        fileMenu.addAction(extract_action)
        fileMenu.addAction(openFile)
        fileMenu = mainMenu.addMenu("&Editor")
        fileMenu.addAction(openEditor)
        # fileMenu = mainMenu.addMenu("&Help")
        # fileMenu.addAction(help)

        self.setWindowIcon(QIcon(icons_path + "berry_icon.png"))

        extract_action_toolbar_berry = QAction(
            QIcon(icons_path + "flatberry.png"), "Connect to the berries",
            self)
        extract_action_toolbar_berry.triggered.connect(self.open_project)

        self.toolBar = self.addToolBar("BeRRY")
        self.toolBar.addAction(extract_action_toolbar_berry)

        extract_action_toolbar_berry = QAction(
            QIcon(icons_path + "camera.png"), "Take Picture Using Webcam",
            self)
        extract_action_toolbar_berry.triggered.connect(self.show_picture)

        self.toolBar = self.addToolBar("Camera toolbar")
        self.toolBar.addAction(extract_action_toolbar_berry)

        extract_action_toolbar_berry = QAction(
            QIcon(icons_path + "lights.png"), "Flashes the lights", self)
        # extract_action_toolbar_berry.triggered.connect(self.light_sequence)

        self.toolBar = self.addToolBar("Lights toolbar")
        self.toolBar.addAction(extract_action_toolbar_berry)

        extract_action_toolbar_berry = QAction(QIcon(""), "Opens the Editor",
                                               self)
        extract_action_toolbar_berry.triggered.connect(self.open_editor)

        self.toolBar = self.addToolBar("Editor")
        self.toolBar.addAction(extract_action_toolbar_berry)

        extract_action_toolbar_berry = QAction(QIcon(""), "Set the image",
                                               self)
        # extract_action_toolbar_berry.triggered.connect(self.reset_background)

        self.toolBar = self.addToolBar("Reset Background")
        self.toolBar.addAction(extract_action_toolbar_berry)

        save_action = QAction(QIcon(icons_path + 'save.png'),
                              'Saves the currently open code window', self)
        save_action.triggered.connect(self.save_file)
        self.toolBar = self.addToolBar('Save code')
        self.toolBar.addAction(save_action)

        run_action = QAction(QIcon(icons_path + 'play.png'),
                             'Runs the project', self)
        run_action.triggered.connect(self.run_project)
        self.toolBar = self.addToolBar('Run project')
        self.toolBar.addAction(run_action)

        # self.layout = QGridLayout()
        # self.reset_background()

        self.mdiArea.setHorizontalScrollBarPolicy(Qt.ScrollBarAlwaysOff)
        self.mdiArea.setVerticalScrollBarPolicy(Qt.ScrollBarAsNeeded)
        bg = QPixmap(self.background)
        bg.scaled(self.size(), Qt.KeepAspectRatioByExpanding)
        self.mdiArea.setBackground(QBrush(bg))
        self.mdiArea.setOption(QMdiArea.DontMaximizeSubWindowOnActivation)
        self.setCentralWidget(self.mdiArea)

        self.picture_window = PictureWindow(self.background, self.clickSignal)
        self.mdiArea.addSubWindow(self.picture_window)
        self.picture_window.showMaximized()

        # self.setMouseTracking(True)
        # self.mousePressEvent(self)
        # self.mouse_position_tracker(self)

        self.show()

    def help_window(self):
        self.newWindow.show()

    def quit_window(self):
        print("Quiting out, Thanks...")
        choice = QMessageBox.question(self, "Close Application",
                                      "Are you sure you want to quit?",
                                      QMessageBox.Yes | QMessageBox.No)
        if choice == QMessageBox.Yes:
            print("Quiting Berry GUI")
            sys.exit()
        else:
            pass

    def open_editor(self):
        child = TextWindow()
        sw = self.mdiArea.addSubWindow(child)
        sw.setWindowFlags(Qt.WindowCloseButtonHint | Qt.WindowStaysOnTopHint)
        child.show()

    def show_picture(self):
        self.threadpool.start(Worker(self.manager.find_berries, self.signal))

    @pyqtSlot(str)
    def clicked_berry(self, name):
        if self.text_window is None:
            self.text_window = TextWindow()
            self.text_sub = self.mdiArea.addSubWindow(self.text_window)
            self.text_sub.setWindowFlags(Qt.WindowCloseButtonHint
                                         | Qt.WindowStaysOnTopHint)
        filename = self.manager.pick_berry(name)
        self.text_window.load_file(filename)
        self.text_sub.setWindowTitle(name)
        self.text_window.show()

    def save_file(self):
        self.text_window.save_file()

    def run_project(self):
        self.save_file()
        self.threadpool.start(Worker(self.manager.project.run_project))

    @pyqtSlot()
    def finished_find(self):
        print('Finished finding berries')
        # sw.setWindowFlags()
        self.picture_window.set_picture(self.manager.current_image())
        self.picture_window.fit_window()
        self.picture_window.show_berries(self.manager.berry_map)
        self.picture_window.show()

    def quit(self):
        print("Quiting out, Thanks...")
        choice = QMessageBox.question(self, "Close Application",
                                      "Are you sure you want to quit?",
                                      QMessageBox.Yes | QMessageBox.No)
        if choice == QMessageBox.Yes:
            print("Quiting Berry GUI")
            sys.exit()
        else:
            pass

            # This function pulls in the initial berry picture and iw will set it as the background of the Gui.

    def reset_background(self):

        label = QLabel(self)
        pixmap = QPixmap('background.jpg')
        label.setPixmap(pixmap)

        label.resize(pixmap.width(), pixmap.height())
        label.move(0, self.OFFSET_FOR_THE_IMAGE)

        self.layout.addWidget(label)

        label.resize(pixmap.width(), pixmap.height())
        label.move(0, self.OFFSET_FOR_THE_IMAGE)

        self.layout.addWidget(label)

        label = QLabel(self)
        # pixmap = QPixmap('cleaned_berry_boxes.png')
        label.setPixmap(pixmap)

        label.resize(pixmap.width(), pixmap.height())
        label.move(0, self.OFFSET_FOR_THE_IMAGE)

        self.layout.addWidget(label)
        self.show()

    def open_project(self):
        dialog = QFileDialog()
        filepath = dialog.getExistingDirectory(
            self, 'Choose existing project or create a new folder', './')
        self.manager = ProjectManager(filepath)
        self.manager.sync_project()