Пример #1
0
    def run(self):
        WorldManager().generate()
        Engine.register_listeners()
        CLI().add_message('Good day, Player! Welcome to Labyrinth')

        dimensions = None
        while dimensions is None:
            CLI().add_event_message('choose_dimensions')
            Renderer().update_screen()
            dimensions = CLI().get_player_input('dimensions')

        self.config['world']['width'] = dimensions[0]
        self.config['world']['height'] = dimensions[1]

        self.make_new_world()

        CLI().add_event_message('choose_command', 'Enter commands!')

        game_over = False
        while not game_over:
            command = None
            while command is None:
                Renderer().update_screen()
                command = CLI().get_player_input('command')

            if CommandProcessor().is_valid(command):
                Engine.execute(command)

            if command == 'exit':
                game_over = True

            EventSystem().update()
            Renderer().update_screen()
Пример #2
0
def create_app():
    app = Flask(__name__)
    app.config.from_mapping(config)

    from core.cli import CLI
    from core.database import db

    from apps.user import UserModule
    from apps.post import PostModule
    from apps.comment import CommentModule
    from apps.category import CategoryModule
    from apps.file import FileModule

    cli = CLI()
    cors = CORS()
    migrate = Migrate()

    user = UserModule()
    post = PostModule()
    comment = CommentModule()
    category = CategoryModule()
    file = FileModule()

    cors.init_app(app)
    cli.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)

    user.init_app(app)
    post.init_app(app)
    comment.init_app(app)
    category.init_app(app)
    file.init_app(app)

    return app
Пример #3
0
    def init(self, config):
        self.config = config

        CLI().init(config)
        WorldManager().init(config)
        Renderer().init(config)
        CommandProcessor().init(config)
        EventSystem().init(config)

        CLI().add_message('Finished initialization.')
Пример #4
0
    def get_history(self):
        total = len(CLI().history)
        n_last = self.config['renderer']['cli_history_trail']
        history_slice = CLI().history[-n_last:]

        start_idx = total - n_last if total - n_last > 0 else 0
        return [
            f"[{start_idx + 1 + i}]\t" + entry
            for i, entry in enumerate(history_slice)
        ]
Пример #5
0
def main():
    """ Package/CLI entry point """

    # Validate config.cfg, init Config singleton
    try:
        Config("config.cfg")

    # If failure in configuration, don't even
    except Exception as e:
        print(f"Error reading config.cfg:\n\t{e}")
        exit(1)

    # Validate items in notes directory, init Book singleton
    try:
        Book()

    except Exception as e:
        print(f"Error building notes dir:\n\t{e}")
        exit(1)

    # Pass args to our CLI module and execute
    try:
        CLI(sys.argv)

    except Exception as e:
        print(f"Error executing command:\n\t{e}")
Пример #6
0
 def rsync_from_local_to_remote(self, from_path, to_path):
     args = [
         'rsync', '-a', '--port=' + str(self.ssh_creds.ssh.port), '-e',
         'ssh -o StrictHostKeyChecking=no', from_path,
         '{}:{}'.format(self.get_ssh_connection_str(), to_path)
     ]
     return CLI.sshpass(args, self.ssh_creds.password)
Пример #7
0
def create_app(test_config=None):
    app = Flask(__name__, static_folder=config['STATIC_FOLDER'])
    if test_config is not None:
        app.config.from_mapping(test_config)
    app.config.from_mapping(config)

    from core.cli import CLI
    from core.database import db

    from apps.user import UserModule
    from apps.food import FoodModule
    from apps.store import StoreModule
    from apps.order import OrderModule
    from apps.driver import DriverModule
    # from apps.category_access import CategoryAccessModule

    cli = CLI()
    cors = CORS()
    migrate = Migrate()
    jwt = JWTManager(app)

    user = UserModule()
    food = FoodModule()
    store = StoreModule()
    order = OrderModule()
    driver = DriverModule()
    # category_access = CategoryAccessModule()

    jwt.init_app(app)
    cli.init_app(app)
    cors.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)

    user.init_app(app)
    food.init_app(app)
    store.init_app(app)
    order.init_app(app)
    driver.init_app(app)
    # category_access.init_app(app)

    return app
Пример #8
0
    def update(self):
        while not self.events.empty():
            event = self.events.get()

            listeners = self.get_listeners(event)
            for lr in listeners:
                if lr is event.target:
                    lr.receive(event)

            # Broadcast event messages
            CLI().receive(event)
Пример #9
0
def create_app(test_config=None):
    app = Flask(__name__)
    if test_config is not None:
        app.config.from_mapping(test_config)
    app.config.from_mapping(config)

    from core.cli import CLI
    from core.database import db

    from apps.user import UserModule
    from apps.file import FileModule
    from apps.job import JobModule
    from apps.category_access import CategoryAccessModule

    cli = CLI()
    cors = CORS()
    migrate = Migrate()
    jwt = JWTManager(app)

    user = UserModule()
    file = FileModule()
    job = JobModule()
    category_access = CategoryAccessModule()

    jwt.init_app(app)
    cli.init_app(app)
    cors.init_app(app)
    db.init_app(app)
    migrate.init_app(app, db)

    user.init_app(app)
    file.init_app(app)
    job.init_app(app)
    category_access.init_app(app)

    return app
Пример #10
0
    def save(self):
        if self.world is None:
            return

        dt = datetime.today()
        save_name = f'Labyrinth_{dt.strftime("%d_%m_%Y__%H_%M_%S")}.pickle'
        file = f"{os.getcwd()}/{self.config['paths']['saves']}/{save_name}"

        with open(file, 'wb') as save_file:
            recursion_limit = 0
            success = False
            while not success:
                try:
                    pickle.dump(self.world, save_file)
                    CLI().add_message(
                        f'Saved map with recursion limit {recursion_limit}')
                    success = True
                except RecursionError:
                    recursion_limit += 1000
                    sys.setrecursionlimit(recursion_limit)
Пример #11
0
    def init(self, config):
        self.config = config
        self.width = config['world']['width']
        self.height = config['world']['height']

        CLI().add_event_message('InitWorldManager')
Пример #12
0
 def init(self, config):
     self.config = config
     self.events = Queue()
     self.listeners = {}
     CLI().add_event_message('InitEventSystem')
Пример #13
0
 def init(self, config: dict):
     self.config = config
     CLI().add_event_message('InitRenderer')
Пример #14
0
 def make_new_world(self):
     self.init(self.config)
     WorldManager().generate()
     Engine.register_listeners()
     CLI().add_event_message('WorldCreated')
Пример #15
0
 def popen(args, **options):
     popen = CLI(args, **options)
     popen.wait()
     return popen
Пример #16
0
from core.cli import CLI
from core.memory import Memory
import sys

if __name__ == "__main__":
    cli = CLI()
    cli.listen_to_commands()
Пример #17
0
 def popen_cmd(self, args):
     return CLI.sshpass([
         'ssh', '-oStrictHostKeyChecking=no',
         self.get_ssh_connection_str(), '-p',
         str(self.ssh_creds.ssh.port)
     ] + args, self.ssh_creds.password)
Пример #18
0
 def init(self, config):
     self.config = config
     CLI().add_event_message('InitCommandProcessor')