This commit is contained in:
Michael 2018-12-11 12:38:41 +05:00
parent f7c1a0e219
commit aca25db85d
12 changed files with 36 additions and 34 deletions

2
.gitignore vendored
View file

@ -5,3 +5,5 @@
/apidocs /apidocs
/gitosis/test/tmp /gitosis/test/tmp
/.coverage /.coverage
.idea
venv

View file

@ -1,5 +1,5 @@
import os, logging import os, logging
from ConfigParser import NoSectionError, NoOptionError from configparser import NoSectionError, NoOptionError
from gitosis import group from gitosis import group

View file

@ -3,7 +3,7 @@ import sys
import logging import logging
import optparse import optparse
import errno import errno
import ConfigParser import configparser
log = logging.getLogger('gitosis.app') log = logging.getLogger('gitosis.app')
@ -31,7 +31,7 @@ class App(object):
cfg = self.create_config(options) cfg = self.create_config(options)
try: try:
self.read_config(options, cfg) self.read_config(options, cfg)
except CannotReadConfigError, e: except CannotReadConfigError as e:
log.error(str(e)) log.error(str(e))
sys.exit(1) sys.exit(1)
self.setup_logging(cfg) self.setup_logging(cfg)
@ -53,13 +53,13 @@ class App(object):
return parser return parser
def create_config(self, options): def create_config(self, options):
cfg = ConfigParser.RawConfigParser() cfg = configparser.RawConfigParser()
return cfg return cfg
def read_config(self, options, cfg): def read_config(self, options, cfg):
try: try:
conffile = file(options.config) conffile = open(options.config)
except (IOError, OSError), e: except (IOError, OSError) as e:
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
# special case this because gitosis-init wants to # special case this because gitosis-init wants to
# ignore this particular error case # ignore this particular error case
@ -74,8 +74,8 @@ class App(object):
def setup_logging(self, cfg): def setup_logging(self, cfg):
try: try:
loglevel = cfg.get('gitosis', 'loglevel') loglevel = cfg.get('gitosis', 'loglevel')
except (ConfigParser.NoSectionError, except (configparser.NoSectionError,
ConfigParser.NoOptionError): configparser.NoOptionError):
pass pass
else: else:
try: try:

View file

@ -2,7 +2,7 @@ import errno
import logging import logging
import os import os
from ConfigParser import NoSectionError, NoOptionError from configparser import NoSectionError, NoOptionError
log = logging.getLogger('gitosis.gitdaemon') log = logging.getLogger('gitosis.gitdaemon')
@ -14,13 +14,13 @@ def export_ok_path(repopath):
def allow_export(repopath): def allow_export(repopath):
p = export_ok_path(repopath) p = export_ok_path(repopath)
file(p, 'a').close() open(p, 'a').close()
def deny_export(repopath): def deny_export(repopath):
p = export_ok_path(repopath) p = export_ok_path(repopath)
try: try:
os.unlink(p) os.unlink(p)
except OSError, e: except OSError as e:
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
pass pass
else: else:

View file

@ -27,7 +27,7 @@ To plug this into ``gitweb``, you have two choices.
import os, urllib, logging import os, urllib, logging
from ConfigParser import NoSectionError, NoOptionError from configparser import NoSectionError, NoOptionError
from gitosis import util from gitosis import util
@ -106,7 +106,7 @@ def generate_project_list(config, path):
""" """
tmp = '%s.%d.tmp' % (path, os.getpid()) tmp = '%s.%d.tmp' % (path, os.getpid())
f = file(tmp, 'w') f = open(tmp, 'w')
try: try:
generate_project_list_fp(config=config, fp=f) generate_project_list_fp(config=config, fp=f)
finally: finally:
@ -157,7 +157,7 @@ def set_descriptions(config):
'description', 'description',
) )
tmp = '%s.%d.tmp' % (path, os.getpid()) tmp = '%s.%d.tmp' % (path, os.getpid())
f = file(tmp, 'w') f = open(tmp, 'w')
try: try:
print >>f, description print >>f, description
finally: finally:

View file

@ -1,5 +1,5 @@
import logging import logging
from ConfigParser import NoSectionError, NoOptionError from configparser import NoSectionError, NoOptionError
def _getMembership(config, user, seen): def _getMembership(config, user, seen):
log = logging.getLogger('gitosis.group.getMembership') log = logging.getLogger('gitosis.group.getMembership')

View file

@ -8,8 +8,8 @@ import os
import sys import sys
from pkg_resources import resource_filename from pkg_resources import resource_filename
from cStringIO import StringIO from io import StringIO
from ConfigParser import RawConfigParser from configparser import RawConfigParser
from gitosis import repository from gitosis import repository
from gitosis import run_hook from gitosis import run_hook
@ -54,7 +54,7 @@ def symlink_config(git_dir):
tmp = '%s.%d.tmp' % (dst, os.getpid()) tmp = '%s.%d.tmp' % (dst, os.getpid())
try: try:
os.unlink(tmp) os.unlink(tmp)
except OSError, e: except OSError as e:
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
pass pass
else: else:
@ -80,7 +80,7 @@ def init_admin_repository(
# can't rely on setuptools and all kinds of distro packaging to # can't rely on setuptools and all kinds of distro packaging to
# have kept our templates executable, it seems # have kept our templates executable, it seems
os.chmod(os.path.join(git_dir, 'hooks', 'post-update'), 0755) os.chmod(os.path.join(git_dir, 'hooks', 'post-update'), 0o755)
if not repository.has_initial_commit(git_dir): if not repository.has_initial_commit(git_dir):
log.info('Making initial commit...') log.info('Making initial commit...')
@ -119,7 +119,7 @@ class Main(app.App):
def handle_args(self, parser, cfg, options, args): def handle_args(self, parser, cfg, options, args):
super(Main, self).handle_args(parser, cfg, options, args) super(Main, self).handle_args(parser, cfg, options, args)
os.umask(0022) os.umask(0o022)
log.info('Reading SSH public key...') log.info('Reading SSH public key...')
pubkey = read_ssh_pubkey() pubkey = read_ssh_pubkey()
@ -141,7 +141,7 @@ class Main(app.App):
user=user, user=user,
) )
log.info('Running post-update hook...') log.info('Running post-update hook...')
util.mkdir(os.path.expanduser('~/.ssh'), 0700) util.mkdir(os.path.expanduser('~/.ssh'), 0o700)
run_hook.post_update(cfg=cfg, git_dir=admin_repository) run_hook.post_update(cfg=cfg, git_dir=admin_repository)
log.info('Symlinking ~/.gitosis.conf to repository...') log.info('Symlinking ~/.gitosis.conf to repository...')
symlink_config(git_dir=admin_repository) symlink_config(git_dir=admin_repository)

View file

@ -36,7 +36,7 @@ def init(
if _git is None: if _git is None:
_git = 'git' _git = 'git'
util.mkdir(path, 0750) util.mkdir(path, 0o750)
args = [ args = [
_git, _git,
'--git-dir=.', '--git-dir=.',
@ -131,7 +131,7 @@ class GitCheckoutIndexError(GitExportError):
def export(git_dir, path): def export(git_dir, path):
try: try:
os.mkdir(path) os.mkdir(path)
except OSError, e: except OSError as e:
if e.errno == errno.EEXIST: if e.errno == errno.EEXIST:
pass pass
else: else:

View file

@ -19,7 +19,7 @@ def post_update(cfg, git_dir):
export = os.path.join(git_dir, 'gitosis-export') export = os.path.join(git_dir, 'gitosis-export')
try: try:
shutil.rmtree(export) shutil.rmtree(export)
except OSError, e: except OSError as e:
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
pass pass
else: else:
@ -63,7 +63,7 @@ class Main(app.App):
parser.error('Missing argument HOOK.') parser.error('Missing argument HOOK.')
log = logging.getLogger('gitosis.run_hook') log = logging.getLogger('gitosis.run_hook')
os.umask(0022) os.umask(0o022)
git_dir = os.environ.get('GIT_DIR') git_dir = os.environ.get('GIT_DIR')
if git_dir is None: if git_dir is None:

View file

@ -141,7 +141,7 @@ def serve(
p = topdir p = topdir
for segment in repopath.split(os.sep)[:-1]: for segment in repopath.split(os.sep)[:-1]:
p = os.path.join(p, segment) p = os.path.join(p, segment)
util.mkdir(p, 0750) util.mkdir(p, 0o750)
repository.init(path=fullpath) repository.init(path=fullpath)
gitweb.set_descriptions( gitweb.set_descriptions(
@ -178,7 +178,7 @@ class Main(app.App):
parser.error('Missing argument USER.') parser.error('Missing argument USER.')
main_log = logging.getLogger('gitosis.serve.main') main_log = logging.getLogger('gitosis.serve.main')
os.umask(0022) os.umask(0o022)
cmd = os.environ.get('SSH_ORIGINAL_COMMAND', None) cmd = os.environ.get('SSH_ORIGINAL_COMMAND', None)
if cmd is None: if cmd is None:
@ -197,7 +197,7 @@ class Main(app.App):
user=user, user=user,
command=cmd, command=cmd,
) )
except ServingError, e: except ServingError as e:
main_log.error('%s', e) main_log.error('%s', e)
sys.exit(1) sys.exit(1)

View file

@ -25,7 +25,7 @@ def readKeys(keydir):
continue continue
path = os.path.join(keydir, filename) path = os.path.join(keydir, filename)
f = file(path) f = open(path)
for line in f: for line in f:
line = line.rstrip('\n') line = line.rstrip('\n')
yield (basename, line) yield (basename, line)
@ -63,15 +63,15 @@ def filterAuthorizedKeys(fp):
def writeAuthorizedKeys(path, keydir): def writeAuthorizedKeys(path, keydir):
tmp = '%s.%d.tmp' % (path, os.getpid()) tmp = '%s.%d.tmp' % (path, os.getpid())
try: try:
in_ = file(path) in_ = open(path)
except IOError, e: except IOError as e:
if e.errno == errno.ENOENT: if e.errno == errno.ENOENT:
in_ = None in_ = None
else: else:
raise raise
try: try:
out = file(tmp, 'w') out = open(tmp, 'w')
try: try:
if in_ is not None: if in_ is not None:
for line in filterAuthorizedKeys(in_): for line in filterAuthorizedKeys(in_):

View file

@ -1,11 +1,11 @@
import errno import errno
import os import os
from ConfigParser import NoSectionError, NoOptionError from configparser import NoSectionError, NoOptionError
def mkdir(*a, **kw): def mkdir(*a, **kw):
try: try:
os.mkdir(*a, **kw) os.mkdir(*a, **kw)
except OSError, e: except OSError as e:
if e.errno == errno.EEXIST: if e.errno == errno.EEXIST:
pass pass
else: else: