def files(self): print("Validating files:") _check_repository() if remote_repository(): _check_deploy_key()
def connection(self): print("Validating connection:") if remote_repository(): _check_ssh_connection() _check_mirror_connection() _check_github_token()
def configs(self): print("Validating repository:") _check_content() _check_database() if remote_repository(): _check_port()
def deploy(self): if output( "git branch -r --contains $(git log --pretty=format:'%h' -n 1) | sed s/^...//" ): return if remote_repository() and len(conf.updated) > 0: self._deploy_ssh() self._deploy_git()
def prepare_ssh(self): if not remote_repository(): return self._execute("eval $(ssh-agent); " "chmod 600 ./deploy_key; " "ssh-add ./deploy_key; " "mkdir -p ~/.ssh; " "chmod 0700 ~/.ssh; " "ssh-keyscan -t rsa -H %s >> ~/.ssh/known_hosts; " % conf.ssh_host)
def create(self): conf.packages.sort() for package in conf.packages: module = paths.pkg + "/" + package try: open(module + "/PKGBUILD") except FileNotFoundError: continue schema = self.get_schema(module) date = self.get_last_change(module) version = schema["version"] description = schema["description"] for name in schema["name"].split(" "): path = self.get_package_file(name, schema) if path: description = self.get_description(package, name, description) for prefix in ["html", "markdown"]: tr = getattr(self, prefix + "_table_tr") tr = tr.replace("$path", path) tr = tr.replace("$name", name) tr = tr.replace("$date", date) tr = tr.replace("$version", version) if prefix is "markdown": description = description.replace("\\", "\\\\") description = description.replace("*", "\*") description = description.replace("_", "\_") description = description.replace("|", "\|") tr = tr.replace("$description", description) tbody = getattr(self, prefix + "_table_tbody") setattr(self, prefix + "_table_tbody", tbody + tr) # Create html mirror if remote_repository(): self.move_to_mirror() self.replace_html_variables() self.compress() # Creade README.md if update_disabled("readme"): return self.move_to_root() self.replace_markdown_variables() self.commit_readme()
def prepare_ssh(self): if not remote_repository(): return execute_quietly(f""" eval $(ssh-agent); chmod 600 ./deploy_key; ssh-add ./deploy_key; mkdir -p ~/.ssh; chmod 0700 ~/.ssh; ssh-keyscan -t rsa -H {conf.ssh_host} >> ~/.ssh/known_hosts; """)
def create(self): if IS_DEVELOPMENT: return packages = output("pacman -Slq %s | sort" % conf.db) if packages.startswith("error: repository"): return else: packages = packages.split("\n") for name in packages: schema = self._get_schema(name) description = schema["description"] version = schema["version"] date = schema["date"] path = self._get_file_location(name, version) for prefix in ["html", "markdown"]: tr = getattr(self, prefix + "_table_tr") tr = tr.replace("$path", path) tr = tr.replace("$name", name) tr = tr.replace("$date", date) tr = tr.replace("$version", version) if prefix == "markdown": description = description.replace("\\", "\\\\") description = description.replace("*", "\*") description = description.replace("_", "\_") description = description.replace("|", "\|") tr = tr.replace("$description", description) tbody = getattr(self, prefix + "_table_tbody") setattr(self, prefix + "_table_tbody", tbody + tr) # Create html mirror if remote_repository(): self._move_to_mirror() self._replace_html_variables() self._compress() # Creade README.md if update_disabled("readme"): return self._move_to_root() self._replace_markdown_variables() self._commit_readme()
def _check_content(): valid = True content = ALIAS_CONFIGS if not remote_repository(): content = set(content) - set(SSH_CONFIGS) for name in content: if not get_attr_value(conf, name): valid = False break validate(error="%s must be defined in repository.yml" % name, target="content", valid=valid)
def _replace_markdown_variables(self): remote_path = self._get_remote_path() if not remote_repository(): conf.url = "file:///path/to/repository" for line in edit_file(paths.base + "/README.md"): line = line.replace("$remote_path", remote_path) line = line.replace("$content", self.markdown_table_tbody) line = line.replace("$database_capitalize", conf.db.capitalize()) line = line.replace("$database", conf.db) if not IS_TRAVIS and line.startswith("[<img src=\"https://img.shields.io/travis/"): line = "" line = line.replace("$path", conf.url) print(line)
def prepare_mirror(self): remote = output("git ls-files " + paths.mirror + " | awk -F / '{print $2}'").split("\n") files = os.listdir(paths.mirror) for f in ["validation_token", "packages_checked"]: if f in files: files.remove(f) if len(files) != len(remote) or not remote_repository(): return print(bold("Pull remote mirror directory files:")) strict_execute(f""" scp -i {paths.base}/deploy_key -P {conf.ssh_port} \ {conf.ssh_user}@{conf.ssh_host}:{conf.ssh_path}/* \ {paths.mirror}/; ssh -i {paths.base}/deploy_key -p {conf.ssh_port} \ {conf.ssh_user}@{conf.ssh_host} \ touch {conf.ssh_path}/*; """)