Blob Blame Raw


import os


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

  def gen_internalurl(self, subpath):
    assert type(subpath) is str
    assert subpath[-1] != '/'
    return self.internalurl + '/' + subpath

  def iswriteaccess(self, request, path):
    return True

  def create(self, subpath):
    raise Exception()

  def delete(self, subpath):
    raise Exception()