|
|
e5b0ac |
|
|
|
e5b0ac |
|
|
|
e5b0ac |
import os
|
|
|
e5b0ac |
|
|
|
e5b0ac |
|
|
|
e5b0ac |
class RepotypeBase:
|
|
|
e5b0ac |
def __init__(self, name):
|
|
|
e5b0ac |
self.name = name
|
|
|
e5b0ac |
self.server = None
|
|
|
e5b0ac |
self.config = None
|
|
|
e5b0ac |
self.path = None
|
|
|
e5b0ac |
|
|
|
e5b0ac |
def check_config(self, server, config):
|
|
|
e5b0ac |
config['internalurl'] = str(config['internalurl'] or '')
|
|
|
e5b0ac |
while config['internalurl'][-1] == '/':
|
|
|
e5b0ac |
del config['internalurl'][-1]
|
|
|
e5b0ac |
assert config['internalurl']
|
|
|
e5b0ac |
config['path'] = server.fixpath(config['path'], root = True)
|
|
|
e5b0ac |
|
|
|
e5b0ac |
def configure(self, server, config):
|
|
|
e5b0ac |
self.server = server
|
|
|
e5b0ac |
self.config = config
|
|
|
e5b0ac |
self.check_config(self.server, self.config)
|
|
|
e5b0ac |
self.internalurl = config['internalurl']
|
|
|
e5b0ac |
self.path = config['path']
|
|
|
e5b0ac |
|
|
|
e5b0ac |
def parentdir(self, path):
|
|
|
e5b0ac |
assert type(path) is str
|
|
|
e5b0ac |
assert path[0] == '/'
|
|
|
e5b0ac |
assert path[-1] != '/'
|
|
|
e5b0ac |
return '/'.join(path.split('/')[:-1])
|
|
|
e5b0ac |
|
|
|
e5b0ac |
def mkdir(self, path):
|
|
|
e5b0ac |
assert type(path) is str
|
|
|
e5b0ac |
assert path[0] == '/'
|
|
|
e5b0ac |
assert path[-1] != '/'
|
|
|
e5b0ac |
os.makedirs(path, exist_ok = True)
|
|
|
e5b0ac |
|
|
|
e5b0ac |
def gen_path(self, subpath):
|
|
|
e5b0ac |
assert type(subpath) is str
|
|
|
e5b0ac |
assert subpath[-1] != '/'
|
|
|
e5b0ac |
return self.path + '/' + subpath
|
|
|
e5b0ac |
|
|
|
e5b0ac |
def gen_internalurl(self, subpath):
|
|
|
e5b0ac |
assert type(subpath) is str
|
|
|
e5b0ac |
assert subpath[-1] != '/'
|
|
|
e5b0ac |
return self.internalurl + '/' + subpath
|
|
|
e5b0ac |
|
|
|
e5b0ac |
def create(self, subpath):
|
|
|
e5b0ac |
raise Exception()
|
|
|
e5b0ac |
|
|
|
e5b0ac |
def delete(self, subpath):
|
|
|
e5b0ac |
raise Exception()
|