diff options
Diffstat (limited to 'ick2lib/app.py')
-rw-r--r-- | ick2lib/app.py | 99 |
1 files changed, 0 insertions, 99 deletions
diff --git a/ick2lib/app.py b/ick2lib/app.py deleted file mode 100644 index 1f7cb25..0000000 --- a/ick2lib/app.py +++ /dev/null @@ -1,99 +0,0 @@ -# Copyright 2017 Lars Wirzenius -# -# This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. -# -# This program is distributed in the hope that it will be useful, -# but WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -# GNU General Public License for more details. -# -# You should have received a copy of the GNU General Public License -# along with this program. If not, see <http://www.gnu.org/licenses/>. -# -# =*= License: GPL-3+ =*= - - -import logging -import os -import random - - -import cliapp -import yaml - - -import ick2lib - - -class ApiApp(cliapp.Application): - - def add_settings(self): - self.settings.boolean( - ['debug'], - 'Turn on debug mode (incl. for yarn tests)' - ) - - self.settings.string( - ['pid-file'], - 'Store application PID in FILE', - metavar='FILE' - ) - - self.settings.string( - ['port-file'], - 'Store randomly chosen listening port (in debug mode) in FILE', - metavar='FILE' - ) - - self.settings.string( - ['projects'], - 'Read project list from YAML format FILE', - metavar='FILE' - ) - - def write_pid_file(self): - write_file(self.settings['pid-file'], str(os.getpid())) - - def pick_random_port(self): - return random.randint(1025, 32767) - - def write_port_file(self, port): - write_file(self.settings['port-file'], str(port)) - - def load_projects(self, filename): - with open(filename) as f: - projects_config = yaml.safe_load(f) - - projects = {} - for name, config in projects_config['projects'].items(): - p = ick2lib.Project(name) - p.set_git(config['git']) - projects[name] = p - for shell in config['shell_steps']: - p.add_build_step(shell) - - return projects - - def process_args(self, args): - assert self.settings['debug'] - - projects = {} - if os.path.exists(self.settings['projects']): - projects = self.load_projects(self.settings['projects']) - - self.write_pid_file() - port = self.pick_random_port() - self.write_port_file(port) - - apiapp = ick2lib.ApiService() - apiapp.set_projects(projects) - apiapp.run_debug(port) - - -def write_file(filename, content): - logging.info('Writing file %s: %r', filename, content) - with open(filename, 'w') as f: - f.write('{}\n'.format(content)) |