# Copyright 2015 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 . # # =*= License: GPL-3+ =*= import glob import os import icklib class StateDirectory(object): def __init__(self): self.dirname = None def set_dirname(self, dirname): self.dirname = dirname def get_project_state_path(self, project_name): return os.path.join(self.dirname, project_name, 'project.yaml') def get_git_directory(self, project_name): return os.path.join(self.dirname, project_name, 'git') def get_apt_directory(self): # pragma: no cover return os.path.join(self.dirname, 'debian') def get_build_infos(self, project_name): result = [] pattern = os.path.join( self.dirname, project_name, 'builds', '*', 'build.yaml') for info_filename in glob.glob(pattern): build_info = icklib.BuildInformation() build_info.set_filename(info_filename) build_info.load() result.append(build_info) return sorted(result, key=lambda bi: bi.build_number) def create_new_build(self, project_name, new_build_number): build_dir = self._get_dirname_for_build_info( project_name, new_build_number) build_filename = os.path.join(build_dir, 'build.yaml') os.makedirs(build_dir) build_info = icklib.BuildInformation() build_info.build_number = new_build_number build_info.set_filename(build_filename) build_info.save() return build_info def _get_dirname_for_build_info(self, project_name, build_number): return os.path.join( self.dirname, project_name, 'builds', str(build_number)) def update_build_info(self, project_name, build_info): build_info.save() def create_statedir_from_ick(ick): # pragma: no cover statedir = icklib.StateDirectory() statedir.set_dirname(ick['state']) return statedir