Beispiel #1
0
 def post(self, request, app_name, env_name, app_path):
     action = request.data['action']
     if action == 'rename':
         env_path = _get_existent_env_path(app_path, env_name)
         new_env_name = request.data['name']
         check_name(new_env_name)
         new_env_path = _get_absent_env_path(app_path, new_env_name)
         stop_patsaks(get_id(request.dev_name, app_name, env_name))
         write_file(new_env_path, new_env_name)
         schema_prefix = get_id(request.dev_name, app_name) + ':'
         execute_sql(
             'SELECT ak.rename_schema(%s, %s)',
             (schema_prefix + env_name.lower(),
              schema_prefix + new_env_name.lower()))
         os.remove(env_path)
         return HttpResponse()
     if action == 'eval':
         request.lock.release()
         request.lock = None
         if env_name == _RELEASE_ENV_NAME:
             env_name = None
         response = send_to_ecilop(
             'EVAL ' + get_id(request.dev_name, app_name, env_name),
             request.data['expr'])
         assert response
         status = response[0]
         result = response[1:]
         assert status in ('E', 'F', 'S')
         if status == 'E':
             raise Error(result, status=NOT_FOUND)
         return {'ok': status == 'S', 'result': result}
     raise Error('Unknown action: "%s"' % action)
Beispiel #2
0
 def post(self, request, app_name, env_name, app_path):
     action = request.data['action']
     if action == 'rename':
         env_path = _get_existent_env_path(app_path, env_name)
         new_env_name = request.data['name']
         check_name(new_env_name)
         new_env_path = _get_absent_env_path(app_path, new_env_name)
         stop_patsaks(get_id(request.dev_name, app_name, env_name))
         write_file(new_env_path, new_env_name)
         schema_prefix = get_id(request.dev_name, app_name) + ':'
         execute_sql('SELECT ak.rename_schema(%s, %s)',
                     (schema_prefix + env_name.lower(),
                      schema_prefix + new_env_name.lower()))
         os.remove(env_path)
         return HttpResponse()
     if action == 'eval':
         request.lock.release()
         request.lock = None
         if env_name == _RELEASE_ENV_NAME:
             env_name = None
         response = send_to_ecilop(
             'EVAL ' + get_id(request.dev_name, app_name, env_name),
             request.data['expr'])
         assert response
         status = response[0]
         result = response[1:]
         assert status in ('E', 'F', 'S')
         if status == 'E':
             raise Error(result, status=NOT_FOUND)
         return {'ok': status == 'S', 'result': result}
     raise Error('Unknown action: "%s"' % action)
Beispiel #3
0
 def delete(self, request, app_name, env_name, app_path):
     env_path = _get_existent_env_path(app_path, env_name)
     stop_patsaks(get_id(request.dev_name, app_name, env_name))
     os.remove(env_path)
     execute_sql('SELECT ak.drop_schema(%s)',
                 (get_id(request.dev_name, app_name, env_name), ))
     return HttpResponse()
Beispiel #4
0
 def delete(self, request, app_name, env_name, app_path):
     env_path = _get_existent_env_path(app_path, env_name)
     stop_patsaks(get_id(request.dev_name, app_name, env_name))
     os.remove(env_path)
     execute_sql(
         'SELECT ak.drop_schema(%s)',
         (get_id(request.dev_name, app_name, env_name),))
     return HttpResponse()
Beispiel #5
0
 def delete(self, request, app_name, app_path):
     app_id = get_id(request.dev_name, app_name)
     stop_patsaks(app_id)
     domains = json.loads(read_file(app_path.domains).lower())
     _purge_domains(domains)
     for domain in domains:
         os.remove(ROOT.domains[domain])
     try:
         os.remove(ROOT.devs[request.dev_name].libs[app_name])
     except OSError, error:
         assert error.errno == errno.ENOENT
Beispiel #6
0
 def post(self, request, app_name, app_path):
     command, args = parse_git_command(request.data['command'])
     host_id = get_id(request.dev_name, app_name)
     if command in ('commit', 'merge', 'pull', 'rebase', 'reset', 'revert'):
         _purge_domains(json.loads(read_file(app_path.domains)))
     else:
         host_id += ':'
     stop_patsaks(host_id)
     return HttpResponse(
         _make_git_runner(request, app_name).run(command, *args),
         'text/plain; charset=utf-8')
Beispiel #7
0
 def put(self, request, app_name, app_path, path):
     stop_patsaks(get_id(request.dev_name, app_name) + ':')
     parts = _check_path(path)
     try:
         write_file(app_path.code + '/' + path, request.raw_post_data)
     except IOError, error:
         raise (
             Error('"%s" is a folder.' % path)
             if error.errno == errno.EISDIR else
             Error('The folder "%s" doesn\'t exist.' % '/'.join(parts[:-1]),
                   status=NOT_FOUND))
Beispiel #8
0
 def delete(self, request, app_name, app_path):
     app_id = get_id(request.dev_name, app_name)
     stop_patsaks(app_id)
     domains = json.loads(read_file(app_path.domains).lower())
     _purge_domains(domains)
     for domain in domains:
         os.remove(ROOT.domains[domain])
     try:
         os.remove(ROOT.devs[request.dev_name].libs[app_name])
     except OSError, error:
         assert error.errno == errno.ENOENT
Beispiel #9
0
 def post(self, request, app_name, app_path):
     command, args = parse_git_command(request.data['command'])
     host_id = get_id(request.dev_name, app_name)
     if command in ('commit', 'merge', 'pull', 'rebase', 'reset', 'revert'):
         _purge_domains(json.loads(read_file(app_path.domains)))
     else:
         host_id += ':'
     stop_patsaks(host_id)
     return HttpResponse(
         _make_git_runner(request, app_name).run(command, *args),
         'text/plain; charset=utf-8')
Beispiel #10
0
 def put(self, request, app_name, app_path, path):
     stop_patsaks(get_id(request.dev_name, app_name) + ':')
     parts = _check_path(path)
     try:
         write_file(app_path.code + '/' + path, request.raw_post_data)
     except IOError, error:
         raise (Error('"%s" is a folder.' %
                      path) if error.errno == errno.EISDIR else
                Error('The folder "%s" doesn\'t exist.' %
                      '/'.join(parts[:-1]),
                      status=NOT_FOUND))
Beispiel #11
0
 def post(self, request, app_name, app_path):
     _purge_domains(json.loads(read_file(app_path.domains)))
     stop_patsaks(get_id(request.dev_name, app_name))
     git_runner = _make_git_runner(request, app_name)
     git_runner.run('add', '-A')
     args = ['commit', '-qm', request.data['message']]
     if request.data.get('amend'):
         args += ('--amend', '--reset-author')
     output = git_runner.run(*args)
     if output:
         raise Error(output)
     return HttpResponse()
Beispiel #12
0
 def post(self, request, app_name, app_path):
     _purge_domains(json.loads(read_file(app_path.domains)))
     stop_patsaks(get_id(request.dev_name, app_name))
     git_runner = _make_git_runner(request, app_name)
     git_runner.run('add', '-A')
     args = ['commit', '-qm', request.data['message']]
     if request.data.get('amend'):
         args += ('--amend', '--reset-author')
     output = git_runner.run(*args)
     if output:
         raise Error(output)
     return HttpResponse()
Beispiel #13
0
 def post(self, request, app_name, app_path):
     stop_patsaks(get_id(request.dev_name, app_name) + ':')
     prefix = app_path.code + '/'
     action = request.data['action']
     if action == 'mkdir':
         path = request.data['path']
         _check_path(path)
         try:
             os.makedirs(prefix + path)
         except OSError, error:
             assert error.errno == errno.EEXIST
             raise Error('The entry "%s" already exists.' % path,
                         'Please choose another name.')
         return HttpResponse(status=CREATED)
Beispiel #14
0
 def post(self, request, app_name, app_path):
     stop_patsaks(get_id(request.dev_name, app_name) + ':')
     prefix = app_path.code + '/'
     action = request.data['action']
     if action == 'mkdir':
         path = request.data['path']
         _check_path(path)
         try:
             os.makedirs(prefix + path)
         except OSError, error:
             assert error.errno == errno.EEXIST
             raise Error('The entry "%s" already exists.' % path,
                         'Please choose another name.')
         return HttpResponse(status=CREATED)
Beispiel #15
0
    def put(self, request, app_name, app_path):
        domains_lower = set(json.loads(read_file(app_path.domains).lower()))
        new_domains = []
        new_domains_lower = set()
        has_akshell = False
        with ROOT.locks.domains.acquire_exclusive():
            for new_domain in request.data:
                new_domain_lower = new_domain.lower()
                if new_domain_lower in new_domains_lower:
                    continue
                match = _DOMAIN_RE.match(new_domain_lower)
                if not match:
                    raise Error(
                        '"%s" is not a valid domain name.' % new_domain, '''\
Domain name must consist of two or three parts separated by dots. \
Each part must consist of Latin letters, digits, and hyphens; \
it must not start or end with a hyphen.''')
                if new_domain_lower.endswith(_AKSHELL_SUFFIX):
                    if has_akshell:
                        raise Error(
                            'Only one akshell.com subdomain is provided.')
                    has_akshell = True
                if new_domain_lower not in domains_lower:
                    _check_domain_is_free(new_domain_lower)
                if match.group(1) and match.group(2) not in domains_lower:
                    _check_domain_is_free(match.group(2))
                new_domains.append(new_domain)
                new_domains_lower.add(new_domain_lower)
            app_id = get_id(request.dev_name, app_name)
            stop_patsaks(app_id)
            for new_domain_lower in new_domains_lower.difference(
                    domains_lower):
                write_file(ROOT.domains[new_domain_lower], app_id)
            old_domains_lower = domains_lower.difference(new_domains_lower)
            for old_domain_lower in old_domains_lower:
                os.remove(ROOT.domains[old_domain_lower])
        _purge_domains(old_domains_lower)
        write_file(app_path.domains, json.dumps(new_domains))
        return HttpResponse()
Beispiel #16
0
    def put(self, request, app_name, app_path):
        domains_lower = set(json.loads(read_file(app_path.domains).lower()))
        new_domains = []
        new_domains_lower = set()
        has_akshell = False
        with ROOT.locks.domains.acquire_exclusive():
            for new_domain in request.data:
                new_domain_lower = new_domain.lower()
                if new_domain_lower in new_domains_lower:
                    continue
                match = _DOMAIN_RE.match(new_domain_lower)
                if not match:
                    raise Error(
                        '"%s" is not a valid domain name.' % new_domain, '''\
Domain name must consist of two or three parts separated by dots. \
Each part must consist of Latin letters, digits, and hyphens; \
it must not start or end with a hyphen.''')
                if new_domain_lower.endswith(_AKSHELL_SUFFIX):
                    if has_akshell:
                        raise Error(
                            'Only one akshell.com subdomain is provided.')
                    has_akshell = True
                if new_domain_lower not in domains_lower:
                    _check_domain_is_free(new_domain_lower)
                if match.group(1) and match.group(2) not in domains_lower:
                    _check_domain_is_free(match.group(2))
                new_domains.append(new_domain)
                new_domains_lower.add(new_domain_lower)
            app_id = get_id(request.dev_name, app_name)
            stop_patsaks(app_id)
            for new_domain_lower in new_domains_lower.difference(domains_lower):
                write_file(ROOT.domains[new_domain_lower], app_id)
            old_domains_lower = domains_lower.difference(new_domains_lower)
            for old_domain_lower in old_domains_lower:
                os.remove(ROOT.domains[old_domain_lower])
        _purge_domains(old_domains_lower)
        write_file(app_path.domains, json.dumps(new_domains))
        return HttpResponse()
Beispiel #17
0
def _stop_dev_patsaks(dev_name):
    for app_name in os.listdir(ROOT.devs[dev_name]):
        stop_patsaks(get_id(dev_name, app_name))
Beispiel #18
0
def _stop_dev_patsaks(dev_name):
    for app_name in os.listdir(ROOT.devs[dev_name]):
        stop_patsaks(get_id(dev_name, app_name))