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)
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))
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)
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')
def report(report): return os.path.join(Dirname.reportroot(report.creator), standardize_str(report.name), report.ts_human)
def proxy_path_latest(self): info = { 'reportuser': self.report.creator, 'reportname': standardize_str(self.report.name), } return KOOPLEX['spawner']['pattern_proxypath_latest'] % info
def safename(self): return standardize_str(self.name)
def cleanname(self): return standardize_str(self.project_name)
def cleanname(self): return standardize_str(self.project_name)
def cleansubcategory_name(self): return 'default' if self.subcategory_name else standardize_str( self.subcategory_name)
def safecourseid(self): return standardize_str(self.courseid)
def cleanname(self): return standardize_str(self.library_name)
def report_with_tag(report): return os.path.join(Dirname.reportroot(report.creator), standardize_str(report.name), report.tag_name)
def report(report): return os.path.join(Dirname.reportroot(report.creator), standardize_str(report.name))
def cleanname(self): return standardize_str(self.name)
def safename(self): return standardize_str(self.name)
def uniquename(self): try: return "%s-%s" % (self.creator.username, standardize_str(self.name)) except AttributeError: return standardize_str(self.name)
def cleantag_name(self): return '' if self.tag_name == '' else standardize_str(self.tag_name)