Use custom templates for Git repositories
[aur.git] / scripts / git-integration / init-repos.py
blob5c4fcfe243de044f0814409b05b71f810c8d0acb
1 #!/usr/bin/python3
3 import configparser
4 import mysql.connector
5 import os
6 import pygit2
7 import re
8 import shlex
9 import sys
11 config = configparser.RawConfigParser()
12 config.read(os.path.dirname(os.path.realpath(__file__)) + "/../../conf/config")
14 aur_db_host = config.get('database', 'host')
15 aur_db_name = config.get('database', 'name')
16 aur_db_user = config.get('database', 'user')
17 aur_db_pass = config.get('database', 'password')
18 aur_db_socket = config.get('database', 'socket')
20 repo_base_path = config.get('serve', 'repo-base')
21 repo_regex = config.get('serve', 'repo-regex')
22 template_path = config.get('serve', 'template-path')
24 def die(msg):
25 sys.stderr.write("%s\n" % (msg))
26 exit(1)
28 db = mysql.connector.connect(host=aur_db_host, user=aur_db_user,
29 passwd=aur_db_pass, db=aur_db_name,
30 unix_socket=aur_db_socket)
31 cur = db.cursor()
33 cur.execute("SELECT Name FROM PackageBases")
34 repos = [row[0] for row in cur]
35 db.close()
37 for repo in repos:
38 if not re.match(repo_regex, repo):
39 die('invalid repository name: %s' % (repo))
41 i = 1
42 n = len(repos)
44 for repo in repos:
45 print("[%s/%d] %s" % (str(i).rjust(len(str(n))), n, repo))
47 repo_path = repo_base_path + '/' + repo + '.git/'
48 pygit2.init_repository(repo_path, True, 48, template_path=template_path)
50 i += 1