Example #1
0
def add_report_nginx_api(report):
    #    import htpasswd
    str_name = standardize_str(report.proxy_path)
    conf_text = """
location /report/%s {
auth_basic "username is 'report'  ";
auth_basic_user_file /etc/passwords/%s;

}
    """ % (report.proxy_path, standardize_str(report.proxy_path))
    logging.debug("+ pw registration ---> %s" % (str_name))
    kw = {
        'url':
        os.path.join(reportconf.get('api_url', 'localhost'), 'api', 'new',
                     str_name),
        'data':
        json.dumps({
            'conf': conf_text,
            'username': '******',
            'password': report.password
        }),
        'auth': ("nginxuser", 'nginxpw'),
    }
    logging.debug("+ %s ---> %s" % (kw['url'], kw['data']))
    keeptrying(requests.post, 50, **kw)
Example #2
0
def mkdir_course(sender, instance, **kwargs):
    from kooplex.lib.filesystem import mkdir_course_share
    from kooplex.lib.fs_dirname import Dirname
    instance.folder = standardize_str(instance.folder)
    c_ids = [ c.id for c in Course.objects.filter(folder = instance.folder) ]
    if len(c_ids) == 1:
        c_id = c_ids.pop()
        assert c_id == instance.id, "Folder name %s is already taken" % instance.folder
    assert len(c_ids) == 0, "Folder name %s is already taken" % instance.folder
    c_ids = [ c.id for c in Course.objects.filter(folder = instance.folder) ]
    if len(c_ids) == 1:
        c_id = c_ids.pop()
        assert c_id == instance.id, "Folder name %s is already taken" % instance.folder
    assert len(c_ids) == 0, "Folder name %s is already taken" % instance.folder
    is_new = instance.id is None
    if is_new:
        mkdir_course_share(instance)
    else:
        old = Course.objects.get(id = instance.id)
        f_o = Dirname.course(old)
        f_n = Dirname.course(instance)
        try:
            os.rename(f_o, f_n)
            logger.info("%s folder rename %s -> %s" % (instance, f_o, f_n))
        except Exception as e:
            logger.warning("failed to rename %s folder rename %s -> %s -- %s" % (instance, f_o, f_n, e))
        for b in UserCourseBinding.objects.filter(course = old):
            f_o = Dirname.courseworkdir(b)
            b_ = UserCourseBinding(course = instance, user = b.user)
            f_n = Dirname.courseworkdir(b_)
            try:
                os.rename(f_o, f_n)
                logger.info("%s folder rename %s -> %s" % (instance, f_o, f_n))
            except Exception as e:
                logger.warning("failed to rename %s folder rename %s -> %s -- %s" % (instance, f_o, f_n, e))
Example #3
0
def remove_report_nginx_api(report):
    str_name = standardize_str(report.proxy_path)
    kw = {
        'url':
        os.path.join(reportconf.get('api_url', 'localhost'), 'api', 'remove',
                     str_name),
        'data':
        json.dumps({}),
        'auth': ("nginxuser", 'nginxpw'),
    }
    logging.debug("- %s ---> %s" % (kw['url'], kw['data']))
    return keeptrying(requests.delete, 5, **kw)
Example #4
0
def new(request):
    logger.debug("user %s" % request.user)
    user = request.user
    user_id = request.POST.get('user_id')
    try:
        assert user_id is not None and int(
            user_id) == user.id, "user id mismatch: %s tries to save %s %s" % (
                request.user, request.user.id, request.POST.get('user_id'))
        containername = "%s-%s" % (user.username,
                                   standardize_str(request.POST.get('name')))
        for container in user.profile.containers:
            assert container.name != containername, "Not a unique name"
        logger.debug("name is okay: %s" % containername)
        image = Image.objects.get(id=request.POST.get('image'))
        Container.objects.create(user=user, name=containername, image=image)
        messages.info(
            request,
            'Your new container is created with name %s' % containername)
        return redirect('container:list')
    except Exception as e:
        logger.error("New container not created -- %s" % e)
        messages.error(request, 'Creation of a new container is refused.')
        return redirect('indexpage')
Example #5
0
 def report(report):
     return os.path.join(Dirname.reportroot(report.creator), standardize_str(report.name), report.ts_human)
Example #6
0
 def proxy_path_latest(self):
     info = { 
             'reportuser': self.report.creator,
             'reportname': standardize_str(self.report.name),
             }
     return KOOPLEX['spawner']['pattern_proxypath_latest'] % info
Example #7
0
 def safename(self):
     return standardize_str(self.name)
Example #8
0
 def cleanname(self):
     return standardize_str(self.project_name)
Example #9
0
 def cleanname(self):
     return standardize_str(self.project_name)
Example #10
0
 def cleansubcategory_name(self):
     return 'default' if self.subcategory_name else standardize_str(
         self.subcategory_name)
Example #11
0
 def safecourseid(self):
     return standardize_str(self.courseid)
Example #12
0
 def cleanname(self):
     return standardize_str(self.library_name)
Example #13
0
 def report_with_tag(report):
     return os.path.join(Dirname.reportroot(report.creator),
                         standardize_str(report.name), report.tag_name)
Example #14
0
 def report(report):
     return os.path.join(Dirname.reportroot(report.creator),
                         standardize_str(report.name))
Example #15
0
 def cleanname(self):
     return standardize_str(self.name)
Example #16
0
 def safename(self):
     return standardize_str(self.name)
Example #17
0
 def uniquename(self):
     try:
         return "%s-%s" % (self.creator.username, standardize_str(self.name))
     except AttributeError:
         return standardize_str(self.name)
Example #18
0
 def cleantag_name(self):
     return '' if self.tag_name == '' else standardize_str(self.tag_name)