Beispiel #1
0
def main():
    f = open("food_diary.json", 'r')
    try:
        data = json.load(f)
    except:
        data = {}

    c = open('calories.json', 'r')
    try:
        calories = json.load(c)
    except:
        calories = {}

    f.close()
    c.close()

    cal = Calories(calories)
    fd = FoodDiary(data, cal)
    cli = CLI(fd)

    cli.start()

    f = open("food_diary.json", 'w')
    json.dump(data, f, indent=4)
    f.close()

    c = open("calories.json", 'w')
    json.dump(calories, c, indent=4)
    c.close()
Beispiel #2
0
    def createCLI(self):
        cli = CLI(self.num)
        # cli.logging(False)
        cli.log('Starting Up')

        # this maps the CLI looks pretty
        time.sleep(1)
        cli.log('Loading 3...')
        time.sleep(1)
        cli.log('Loading 2...')
        time.sleep(1)
        cli.log('Loading 1...')
        time.sleep(1)

        # pass details
        cli.defineMapperOne(5001 + (self.num - 1) * 10, self.ip)
        cli.defineMapperTwo(5002 + (self.num - 1) * 10, self.ip)
        cli.defineReducer(5003 + (self.num - 1) * 10, self.ip)
        cli.definePRM(5004 + (self.num - 1) * 10, self.ip)

        cli.log('Enter commands below. Use ctrl+c to exit.')
        boo = True
        while (boo):
            try:
                command = raw_input('> ')
                cli.handleCommand(command.split())
            except KeyboardInterrupt:
                boo = False
            time.sleep(1)

        # exiting
        cli.log('Exiting')
Beispiel #3
0
def main():
    if len(sys.argv) < 2:
        print("Serial not specified")
        return

    path = sys.argv[1]
    if not Path(path).exists():
        print("Not found:", sys.argv[1])
        return

    cli = CLI(path)
    sensitive = get_sensitive(cli, 'acceleration')

    try:
        data = collect(cli)
        bias = [
            (data[Attitude.ROLL_LEFT] + data[Attitude.ROLL_RIGHT]) / 2,
            (data[Attitude.PITCH_DOWN] + data[Attitude.PITCH_UP]) / 2,
            (data[Attitude.FLAT] + data[Attitude.REVERSE]) / 2,
        ]
        gain = [
            sensitive * sensitive / (data[Attitude.ROLL_RIGHT] - bias[0]),
            sensitive * sensitive / (data[Attitude.PITCH_UP] - bias[1]),
            sensitive * sensitive / (data[Attitude.REVERSE] - bias[2]),
        ]
        print("bias:", bias)
        print("gain:", gain)
    except EOFError:
        pass

    cli.close()
Beispiel #4
0
    def test_migrate(self):
        CLI().main(['progname', 'migrate'])

        self.mock_load_repo.assert_called_once_with(self.cwd)
        repo = self.mock_load_repo.return_value
        self.mock_migrate_repo.assert_called_once_with(repo)
        self.mock_sys_exit.assert_called_once_with(0)
def main():
    """
    The main entry point of the program.
    """
    cli = CLI(api_key_file=API_KEY_FILE)
    history = InMemoryHistory()

    # Build Autocomplete
    methods = cli.client.context.allowed_api_calls
    autocomplete = build_autocomplete(cli.client)

    while True:
        try:
            text = prompt('Arsenal >> ',
                          completer=ArsenalCompleter(methods, autocomplete),
                          history=history,
                          auto_suggest=AutoSuggestFromHistory())
            if text:
                text = parse_command(cli.client, text)
                firethread = FireThread(text, cli)
                firethread.start()
                firethread.join()
                print('')
        except Reset:
            cli.client.context = cli.client.get_current_context()
            methods = cli.client.context.allowed_api_calls
            autocomplete = build_autocomplete(cli.client)
        except ShellExit:
            pass
        except EOFError:
            exit_arsenal()
        except KeyboardInterrupt:
            exit_arsenal()
        except Exception as exception:  # pylint: disable=broad-except
            print(exception)
Beispiel #6
0
    def test_clone(self):
        src_url = "/origin/url"
        CLI().main(['progname', 'clone', src_url])

        self.mock_clone_repo.assert_called_once_with(src=src_url,
                                                     dest=self.cwd)
        self.mock_sys_exit.assert_called_once_with(0)
    def __init__(self, config, sgdb=None):
        Main._check_configuration(config)

        self.cli = CLI()
        self.config = config
        self.log = LOG(self.config.get("log_dir", None))

        self.sgdb = sgdb
        if self.sgdb is None and not self.config.get("new_migration", None):
            if self.config.get("database_engine") == 'mysql':
                from mysql import MySQL
                self.sgdb = MySQL(config)
            elif self.config.get("database_engine") == 'oracle':
                from oracle import Oracle
                self.sgdb = Oracle(config)
            elif self.config.get("database_engine") == 'mssql':
                from mssql import MSSQL
                self.sgdb = MSSQL(config)
            elif self.config.get("database_engine") == 'postgresql':
                from postgresql import PostgreSQL
                self.sgdb = PostgreSQL(config)
            else:
                raise Exception("engine not supported '%s'" % self.config.get("database_engine"))

        self.db_migrate = SimpleDBMigrate(self.config)
Beispiel #8
0
    def __init__(self,
                 board_size=8,
                 player1_type=HumanPlayer,
                 player2_type=HumanPlayer):
        self.console = CLI()
        self.board = Board(board_size)
        self.manager = Manager()

        self.p1 = player1_type(Disk.DARK)
        if issubclass(player1_type, HumanPlayer):
            self.p1.set_console(self.console)
        if issubclass(player1_type, SimplePlayer):
            self.p1.set_manager(self.manager)
        if issubclass(player1_type, Player02):
            self.p1.set_minimax_variables(self.manager)

        self.p2 = player2_type(Disk.LIGHT)
        if issubclass(player2_type, HumanPlayer):
            self.p2.set_console(self.console)
        if issubclass(player2_type, SimplePlayer) or issubclass(
                player2_type, Player02):
            self.p2.set_manager(self.manager)
        if issubclass(player2_type, Player02):
            self.p2.set_minimax_variables(self.manager)

        self.current_player = self.p1
Beispiel #9
0
 def _verify_if_exception_is_invalid_user(self, exception):
     import pdb
     pdb.set_trace()
     #TODO validar como isso funciona no mongodb
     if 'ORA-01017' in exception.__str__():
         try:
             cli = CLI()
             cli.msg(
                 '\nPlease inform dba user/password to connect to database "%s"\nUser:'
                 % (self.__host), "END")
             dba_user = self.std_in.readline().strip()
             passwd = self.get_pass()
             conn = self.__driver.connect(dsn=self.__host,
                                          user=dba_user,
                                          password=passwd)
             cursor = conn.cursor()
             cursor.execute("create user %s identified by %s" %
                            (self.__user, self.__passwd))
             cursor.execute("grant connect, resource to %s" % (self.__user))
             cursor.execute("grant create public synonym to %s" %
                            (self.__user))
             cursor.execute("grant drop public synonym to %s" %
                            (self.__user))
             cursor.close()
             conn.close()
         except Exception, e:
             raise Exception("check error: %s" % e)
Beispiel #10
0
    def test_default_viewer(self):
        CLI().main(['progname', 'view'])

        self.mock_load_repo.assert_called_once_with(self.cwd)
        repo = self.mock_load_repo.return_value
        self.mock_view_pics.assert_called_once_with(repo, None)
        self.mock_sys_exit.assert_called_once_with(0)
Beispiel #11
0
    def test_list_default(self):
        CLI().main(['progname', 'list'])

        self.mock_load_repo.assert_called_once_with(self.cwd)
        repo = self.mock_load_repo.return_value
        self.mock_list_pics.assert_called_once_with(repo, 'all')
        self.mock_sys_exit.assert_called_once_with(0)
Beispiel #12
0
    def test_add_without_processing(self):
        files = ['file1', 'file2', 'file3']
        CLI().main(['progname', 'add'] + files + ['--noprocess'])

        self.mock_load_repo.assert_called_once_with(self.cwd)
        repo = self.mock_load_repo.return_value
        self.mock_add_pics.assert_called_once_with(repo, files, False, None)
        self.mock_sys_exit.assert_called_once_with(0)
Beispiel #13
0
def main(args):
    if len(args) > 0:
        cli = CLI()
        cli.run()
    else:
        appctxt = AppContext()  # 1. Instantiate ApplicationContext
        exit_code = appctxt.run()  # 2. Invoke appctxt.app.exec_()
        sys.exit(exit_code)
Beispiel #14
0
    def test_backup_to_many(self):
        backup_urls = ['/backup1/url', '/backup2/url', '/backup3/url']
        CLI().main(['progname', 'backup'] + backup_urls)

        self.mock_load_repo.assert_called_once_with(self.cwd)
        repo = self.mock_load_repo.return_value
        self.mock_backup_repo.assert_called_once_with(repo, *backup_urls)
        self.mock_sys_exit.assert_called_once_with(0)
Beispiel #15
0
    def test_backup(self):
        backup_url = '/backup/url'
        CLI().main(['progname', 'backup', backup_url])

        self.mock_load_repo.assert_called_once_with(self.cwd)
        repo = self.mock_load_repo.return_value
        self.mock_backup_repo.assert_called_once_with(repo, backup_url)
        self.mock_sys_exit.assert_called_once_with(0)
Beispiel #16
0
    def test_merge(self):
        others = ['repoA', 'repoB', 'repoC']
        CLI().main(['progname', 'merge'] + others)

        self.mock_load_repo.assert_called_once_with(self.cwd)
        repo = self.mock_load_repo.return_value
        self.mock_merge_repos.assert_called_once_with(repo, *others)
        self.mock_sys_exit.assert_called_once_with(0)
Beispiel #17
0
    def test_supplied_viewer(self):
        prog = 'fooview fooviewarg --fooviewopt'
        CLI().main(['progname', 'view', '--viewer', prog])

        self.mock_load_repo.assert_called_once_with(self.cwd)
        repo = self.mock_load_repo.return_value
        self.mock_view_pics.assert_called_once_with(repo, prog)
        self.mock_sys_exit.assert_called_once_with(0)
Beispiel #18
0
    def test_remove(self):
        files = ['file1', 'file2', 'file3']
        CLI().main(['progname', 'remove'] + files)

        self.mock_load_repo.assert_called_once_with(self.cwd)
        repo = self.mock_load_repo.return_value
        self.mock_remove_pics.assert_called_once_with(repo, files)
        self.mock_sys_exit.assert_called_once_with(0)
Beispiel #19
0
    def test_check(self):
        self.mock_check_pics.return_value = ([], [])
        CLI().main(['progname', 'check'])

        self.mock_load_repo.assert_called_once_with(self.cwd)
        repo = self.mock_load_repo.return_value
        self.mock_check_pics.assert_called_once_with(repo)
        self.mock_sys_exit.assert_called_once_with(0)
Beispiel #20
0
    def test_add(self):
        files = ['file1', 'file2', 'file3']
        CLI().main(['progname', 'add'] + files)

        self.mock_load_repo.assert_called_once_with(self.cwd)
        repo = self.mock_load_repo.return_value
        self.mock_add_pics.assert_called_once_with(repo, files, True, None)
        self.mock_sys_exit.assert_called_once_with(0)
Beispiel #21
0
def main():
    """'
    Big O(n^3)
    Initiate the application
    """
    init_data()
    assign_deliveries()
    CLI().run()
Beispiel #22
0
    def testInvalidCommand(self):

        cli = CLI()

        # Check for incorrect command
        with self.assertRaises(ClindException):

            cli.processCommand("not a command")
Beispiel #23
0
    def test_add_with_process_recipe(self):
        files = ['file1', 'file2', 'file3']
        recipe = 'FOO.BAR'
        CLI().main(['progname', 'add'] + files + ['--recipe', recipe])

        self.mock_load_repo.assert_called_once_with(self.cwd)
        repo = self.mock_load_repo.return_value
        self.mock_add_pics.assert_called_once_with(repo, files, True, recipe)
        self.mock_sys_exit.assert_called_once_with(0)
Beispiel #24
0
    def testName(self):

        cli = CLI()

        name = cli.processCommand("name")

        # Check that name command returns a string with space
        self.assertTrue(isinstance(name, str))
        self.assertTrue(" " in name)
Beispiel #25
0
 def __init__(self, questions, search_engines, storage, maxlength, paste):
     super(Core, self).__init__(name="core")
     self.storage = Storage(storage, parent=self)
     self.messages = MessageDatabase(questions, parent=self)
     self.search = Search(search_engines, parent=self)
     self.pingpong = PingPong(parent=self)
     self.flooding = Flooding(maxlength, paste, parent=self)
     self.cli = CLI(parent=self)
     self.log.info("load complete")
Beispiel #26
0
    def testRoll(self):

        cli = CLI()

        # Check roll command
        for i in range(100):

            r = cli.processCommand("roll 1d20")

            self.assertTrue(1 <= r <= 20)
Beispiel #27
0
class Config:
    _config = ConfigParser()
    _home_dir = expanduser("~")
    _config_dir = _home_dir + "/.mp_control"
    _cli = CLI()

    def _check_config(self):
        return path.exists(self._config_dir)

    def create_configs(self):
        os.mkdir(self._config_dir)
        with open(self._config_dir + "/config", "w"):
            pass

        self._cli.out("Enter the name of project: ", end='')
        project_name = input()

        self._cli.out(
            "Enter the name of project directory (the directory shoult exist in the home directory): ",
            end='')
        project_dir = input()

        self._cli.out(
            "Enter the link to the BuildTools.jar (example https://example.com/BuildTools.jar): ",
            end='')
        build_tool_link = input()

        self._config["PROJECT_INFO"] = {
            "name": project_name,
            "dir": self._home_dir + "/" + project_dir,
            "build_tool_link": build_tool_link
        }

        with open(self._config_dir + "/config", "w") as conf:
            self._config.write(conf)

    def get_project_name(self):
        return self._config["PROJECT_INFO"]["name"]

    def get_project_dir(self):
        return self._config["PROJECT_INFO"]["dir"]

    def get_link_to_buildtool(self):
        return self._config["PROJECT_INFO"]["build_tool_link"]

    def init(self, cli):
        self._cli = cli
        if not self._check_config():
            self.create_configs()
            self._cli.out("Configs have been created in " + self._config_dir +
                          " directory")

        self._config.read(self._config_dir + "/config")
        self._cli.set_history_path(self._config_dir)
Beispiel #28
0
 def test_parser(self):
     """Tests the correct behaviour of the parser method: an args string without a required input is
     passed to the method and the test checks if an exception is raised"""
     data_handler = DataHandler('')
     method_handler = MethodHandler(data_handler, '')
     cli_app = CLI(method_handler)
     args_exp = {'Ticker': {'Type': 'String', 'Required': 1}, 'StartDate': {'Type': 'Date', 'Required': 1},
                 'EndDate': {'Type': 'Date', 'Required': 1}, 'Currency': {'Type': 'String', 'Required': 1}}
     args_obtained = 'AAPL 2021/01/01 2021/02/14'
     with self.assertRaises(Exception):
         res = cli_app.parse_args(args_obtained, args_exp)
Beispiel #29
0
def main(args: str):
    logger = logging.getLogger(__name__)
    config = CLI().build_config(args)
    volunteers = v.Volunteers(config).build_volunteers()
    heuristic = config.heuristic.get_strategy(config.group_size)
    groups = heuristic.build_groups(volunteers)
    if config.output:
        with open("{}/output.json".format(config.output), 'w') as f:
            f.write(groups)
    else:
        logger.warning(groups)
Beispiel #30
0
def main():
    interface = CLI()

    commands = (("I", new_image), ("C", clear), ("L", colour_pixel),
                ("V", draw_vertical_segment), ("H", draw_horizontal_segment),
                ("F", fill_region), ("S", show), ("X", terminate))

    for token, fn in commands:
        interface.register_command(token, fn)

    interface.main_loop()