stagit

static git page generator  https://git.ce9e.org
git clone https://git.ce9e.org/stagit.git

commit
fbf4f98f3a62573c07f71691f1e5c485fb53281b
parent
8ef8e7ebbbf23f159a042a8083a6fe16198d27ea
Author
Tobias Bengfort <tobias.bengfort@posteo.de>
Date
2020-03-29 19:45
access: rm admin repo

Diffstat

M gitolite/post-update.py 6 +-----
M gitolite/stagit.py 90 ++----------------------------------------------------------

2 files changed, 4 insertions, 92 deletions


diff --git a/gitolite/post-update.py b/gitolite/post-update.py

@@ -7,8 +7,4 @@ import stagit
    7     7 
    8     8 
    9     9 repo = os.environ['STAGIT_REPO']
   10    -1 
   11    -1 if repo == stagit.ADMIN_REPO:
   12    -1 	stagit.update_admin()
   13    -1 else:
   14    -1 	stagit.render_html(repo)
   -1    10 stagit.render_repo(repo)

diff --git a/gitolite/stagit.py b/gitolite/stagit.py

@@ -5,19 +5,13 @@ import subprocess
    5     5 import configparser
    6     6 
    7     7 USER = 'git'
    8    -1 ADMIN_REPO = 'stagit-admin'
    9     8 
   10     9 WWW_DIR = '/var/www/git/'
   11    10 REPO_DIR = os.path.expanduser('~/repos/')
   12    -1 ADMIN_DIR = os.path.expanduser('~/.stagit/')
   -1    11 CONF_PATH = os.path.expanduser('~/stagit.conf')
   13    12 
   14    -1 SHELL = '/usr/lib/stagit/shell'
   15    13 UPDATE_HOOK = '/usr/lib/stagit/hooks/update'
   16    14 POST_UPDATE_HOOK = '/usr/lib/stagit/hooks/post-update'
   17    -1 CONF = '/usr/lib/stagit/conf.skel'
   18    -1 
   19    -1 KEY_OPTS = 'no-port-forwarding,no-X11-forwarding,no-agent-forwarding,no-pty'
   20    -1 KEY_TPL = 'command="%s %%s",%s %%s' % (SHELL, KEY_OPTS)
   21    15 
   22    16 
   23    17 if os.environ.get('USER') != USER:
@@ -31,17 +25,8 @@ def get_repo_dir(repo):
   31    25 
   32    26 class Config:
   33    27 	def __init__(self):
   34    -1 		self._cache = None
   35    -1 
   36    -1 	@property
   37    -1 	def config(self):
   38    -1 		if not self._cache:
   39    -1 			self._cache = configparser.ConfigParser()
   40    -1 			self._cache.read(os.path.join(ADMIN_DIR, 'conf'))
   41    -1 		return self._cache
   42    -1 
   43    -1 	def invalidate(self):
   44    -1 		self._cache = None
   -1    28 		self.config = configparser.ConfigParser()
   -1    29 		self.config.read(CONF_PATH)
   45    30 
   46    31 	def _iter_sets(self, repo, prefix):
   47    32 		try:
@@ -78,34 +63,6 @@ class Config:
   78    63 config = Config()
   79    64 
   80    65 
   81    -1 def update_admin_dir():
   82    -1 	subprocess.call(
   83    -1 		['git', 'checkout', '-f', '--quiet'],
   84    -1 		cwd=get_repo_dir(ADMIN_REPO),
   85    -1 		env={
   86    -1 			**os.environ,
   87    -1 			'GIT_WORK_TREE': ADMIN_DIR,
   88    -1 		},
   89    -1 	)
   90    -1 	config.invalidate()
   91    -1 
   92    -1 
   93    -1 def update_keys():
   94    -1 	keydir = os.path.join(ADMIN_DIR, 'keydir')
   95    -1 	lines = []
   96    -1 
   97    -1 	for fn in os.listdir(keydir):
   98    -1 		if fn.endswith('.pub'):
   99    -1 			path = os.path.join(keydir, fn)
  100    -1 			name = fn[:-4]
  101    -1 			with open(path) as fh:
  102    -1 				lines.append(KEY_TPL % (name, fh.read()))
  103    -1 
  104    -1 	with open(os.path.expanduser('~/.ssh/authorized_keys'), 'w') as fh:
  105    -1 		for line in lines:
  106    -1 			fh.write(line)
  107    -1 
  108    -1 
  109    66 def update_daemon_export_ok(repo):
  110    67 	export_ok = os.path.join(get_repo_dir(repo), 'git-daemon-export-ok')
  111    68 	if config.is_public(repo):
@@ -124,49 +81,8 @@ def update_repo(repo):
  124    81 	shutil.copy(POST_UPDATE_HOOK, os.path.join(path, 'hooks', 'post-update'))
  125    82 
  126    83 
  127    -1 def update_admin():
  128    -1 	update_admin_dir()
  129    -1 	update_keys()
  130    -1 	for repo in config.iter_repos():
  131    -1 		update_repo(repo)
  132    -1 		update_daemon_export_ok(repo)
  133    -1 
  134    -1 
  135    84 def render_html(repo):
  136    85 	if config.is_public(repo):
  137    86 		target_dir = os.path.join(WWW_DIR, repo)
  138    87 		os.makedirs(target_dir, exist_ok=True)
  139    88 		subprocess.check_call(['stagit', get_repo_dir(repo)], cwd=target_dir)
  140    -1 
  141    -1 
  142    -1 def bootstrap(keyfile):
  143    -1 	update_repo(ADMIN_REPO)
  144    -1 	repodir = get_repo_dir(ADMIN_REPO)
  145    -1 
  146    -1 	if not os.path.exists(ADMIN_DIR):
  147    -1 		workdir = os.path.join(REPO_DIR, '.bootstrap')
  148    -1 		keydir = os.path.join(workdir, 'keydir')
  149    -1 		os.mkdir(workdir)
  150    -1 		os.mkdir(keydir)
  151    -1 		shutil.copy(CONF, os.path.join(workdir, 'conf'))
  152    -1 		shutil.copy(keyfile, os.path.join(workdir, 'keydir', 'admin.pub'))
  153    -1 
  154    -1 		subprocess.call(
  155    -1 			['git', 'add', 'conf', 'keydir/admin.pub'],
  156    -1 			cwd=repodir, env={**os.environ, 'GIT_WORK_TREE': workdir},
  157    -1 		)
  158    -1 		subprocess.call(
  159    -1 			['git', 'commit', '-m', 'bootstrap'],
  160    -1 			cwd=repodir, env={**os.environ, 'GIT_WORK_TREE': workdir},
  161    -1 		)
  162    -1 
  163    -1 		os.unlink(os.path.join(workdir, 'conf'))
  164    -1 		os.unlink(os.path.join(workdir, 'keydir', 'admin.pub'))
  165    -1 		os.rmdir(os.path.join(workdir, 'keydir'))
  166    -1 		os.rmdir(os.path.join(workdir))
  167    -1 
  168    -1 	update_admin()
  169    -1 
  170    -1 
  171    -1 if __name__ == '__main__':
  172    -1 	bootstrap(sys.argv[1])