Example #1
0
 def populate_burst_disk_usage(bursts):
     """
     Adds a disk_usage field to each burst object.
     The disk usage is computed as the sum of the datatypes generated by a burst
     """
     sizes = dao.compute_bursts_disk_size([b.id for b in bursts])
     for b in bursts:
         b.disk_size = format_bytes_human(sizes[b.id])
Example #2
0
 def populate_burst_disk_usage(bursts):
     """
     Adds a disk_usage field to each burst object.
     The disk usage is computed as the sum of the datatypes generated by a burst
     """
     sizes = dao.compute_bursts_disk_size([b.id for b in bursts])
     for b in bursts:
         b.disk_size = format_bytes_human(sizes[b.id])
Example #3
0
    def current_weight(self):
        """
        Return a dictionary with information about current burst's weight.
        """
        result = {'process_time': None,
                  'datatypes_number': self.datatypes_number,
                  'disk_size': format_bytes_human(self.disk_size) if self.disk_size is not None else None,
                  'number_of_workflows': self.workflows_number,
                  'start_time': self.start_time,
                  'error': self.error_message}

        if self.finish_time is not None and self.start_time is not None:
            result['process_time'] = format_timedelta(self.finish_time - self.start_time)

        return result
Example #4
0
    def profile(self, logout=False, save=False, **data):
        """
        Display current user's profile page.
        On POST: logout, or save password/email.
        """
        if cherrypy.request.method == 'POST' and logout:
            raise cherrypy.HTTPRedirect('/user/logout')
        template_specification = dict(mainContent="user/profile",
                                      title="User Profile")
        user = common.get_logged_user()

        if cherrypy.request.method == 'POST' and save:
            try:
                form = EditUserForm()
                data = form.to_python(data)
                if data.get(KEY_PASSWORD):
                    user.password = hash_password(data[KEY_PASSWORD])
                if data.get(KEY_EMAIL):
                    user.email = data[KEY_EMAIL]
                old_password = None
                if data.get('old_password'):
                    old_password = hash_password(data['old_password'])
                self.user_service.edit_user(user, old_password)
                if old_password:
                    common.set_info_message("Changes Submitted!")
                else:
                    common.set_info_message("Submitted!  No password changed.")
            except formencode.Invalid as excep:
                template_specification[
                    common.KEY_ERRORS] = excep.unpack_errors()
            except UsernameException as excep:
                self.logger.exception(excep)
                user = common.get_logged_user()
                common.add2session(common.KEY_USER,
                                   self.user_service.get_user_by_id(user.id))
                common.set_error_message(
                    "Could not save changes. Probably wrong old password!!")
        else:
            # Update session user since disk size might have changed from last time to profile.
            user = self.user_service.get_user_by_id(user.id)
            common.add2session(common.KEY_USER, user)

        template_specification['user_used_disk_human'] = format_bytes_human(
            self.user_service.compute_user_generated_disk_size(user.id))
        return self.fill_default_attributes(template_specification)
Example #5
0
 def retrieve_projects_for_user(self, user_id, current_page=1):
     """
     Return a list with all Projects visible for current user.
     """
     start_idx = PROJECTS_PAGE_SIZE * (current_page - 1)
     total = dao.get_projects_for_user(user_id, is_count=True)
     available_projects = dao.get_projects_for_user(user_id, start_idx, PROJECTS_PAGE_SIZE)
     pages_no = total // PROJECTS_PAGE_SIZE + (1 if total % PROJECTS_PAGE_SIZE else 0)
     for prj in available_projects:
         fns, sta, err, canceled, pending = dao.get_operation_numbers(prj.id)
         prj.operations_finished = fns
         prj.operations_started = sta
         prj.operations_error = err
         prj.operations_canceled = canceled
         prj.operations_pending = pending
         prj.disk_size = dao.get_project_disk_size(prj.id)
         prj.disk_size_human = format_bytes_human(prj.disk_size)
     self.logger.debug("Displaying " + str(len(available_projects)) + " projects in UI for user " + str(user_id))
     return available_projects, pages_no
Example #6
0
 def retrieve_projects_for_user(self, user_id, current_page=1):
     """
     Return a list with all Projects visible for current user.
     """
     start_idx = PROJECTS_PAGE_SIZE * (current_page - 1)
     total = dao.get_projects_for_user(user_id, is_count=True)
     available_projects = dao.get_projects_for_user(user_id, start_idx, PROJECTS_PAGE_SIZE)
     pages_no = total // PROJECTS_PAGE_SIZE + (1 if total % PROJECTS_PAGE_SIZE else 0)
     for prj in available_projects:
         fns, sta, err, canceled, pending = dao.get_operation_numbers(prj.id)
         prj.operations_finished = fns
         prj.operations_started = sta
         prj.operations_error = err
         prj.operations_canceled = canceled
         prj.operations_pending = pending
         prj.disk_size = dao.get_project_disk_size(prj.id)
         prj.disk_size_human = format_bytes_human(prj.disk_size)
     self.logger.debug("Displaying " + str(len(available_projects)) + " projects in UI for user " + str(user_id))
     return available_projects, pages_no
    def profile(self, logout=False, save=False, **data):
        """
        Display current user's profile page.
        On POST: logout, or save password/email.
        """
        if cherrypy.request.method == 'POST' and logout:
            raise cherrypy.HTTPRedirect('/user/logout')
        template_specification = dict(mainContent="profile", title="User Profile")
        user = common.get_logged_user()

        if cherrypy.request.method == 'POST' and save:
            try:
                form = EditUserForm()
                data = form.to_python(data)
                if data.get(KEY_PASSWORD):
                    user.password = md5(data[KEY_PASSWORD]).hexdigest()
                if data.get(KEY_EMAIL):
                    user.email = data[KEY_EMAIL]
                old_password = None
                if data.get('old_password'):
                    old_password = md5(data['old_password']).hexdigest()
                self.user_service.edit_user(user, old_password)
                if old_password:
                    common.set_info_message("Changes Submitted!")
                else:
                    common.set_info_message("Submitted!  No password changed.")
            except formencode.Invalid as excep:
                template_specification[common.KEY_ERRORS] = excep.unpack_errors()
            except UsernameException as excep:
                self.logger.exception(excep)
                user = common.get_logged_user()
                common.add2session(common.KEY_USER, self.user_service.get_user_by_id(user.id))
                common.set_error_message("Could not save changes. Probably wrong old password!!")
        else:
            #Update session user since disk size might have changed from last time to profile.
            user = self.user_service.get_user_by_id(user.id)
            common.add2session(common.KEY_USER, user)

        template_specification['user_used_disk_human'] = format_bytes_human(
            self.user_service.compute_user_generated_disk_size(user.id))
        return self.fill_default_attributes(template_specification)
            except formencode.Invalid, excep:
                template_specification[
                    common.KEY_ERRORS] = excep.unpack_errors()
            except UsernameException, excep:
                self.logger.exception(excep)
                user = common.get_logged_user()
                common.add2session(common.KEY_USER,
                                   self.user_service.get_user_by_id(user.id))
                common.set_error_message(
                    "Could not save changes. Probably wrong old password!!")
        else:
            #Update session user since disk size might have changed from last time to profile.
            user = self.user_service.get_user_by_id(user.id)
            common.add2session(common.KEY_USER, user)

        template_specification['user_used_disk_human'] = format_bytes_human(
            self.user_service.compute_user_generated_disk_size(user.id))
        return self.fill_default_attributes(template_specification)

    @cherrypy.expose
    @handle_error(redirect=True)
    @check_user
    def logout(self):
        """
        Logging out user and clean session
        """
        user = common.remove_from_session(common.KEY_USER)
        if user is not None:
            self.logger.debug("User " + user.username +
                              " is just logging out!")
        common.remove_from_session(common.KEY_PROJECT)
        common.remove_from_session(common.KEY_BURST_CONFIG)
                else:
                    common.set_info_message("Submitted!  No password changed.")
            except formencode.Invalid, excep:
                template_specification[common.KEY_ERRORS] = excep.unpack_errors()
            except UsernameException, excep:
                self.logger.exception(excep)
                user = common.get_logged_user()
                common.add2session(common.KEY_USER, self.user_service.get_user_by_id(user.id))
                common.set_error_message("Could not save changes. Probably wrong old password!!")
        else:
            # Update session user since disk size might have changed from last time to profile.
            user = self.user_service.get_user_by_id(user.id)
            common.add2session(common.KEY_USER, user)

        template_specification["user_used_disk_human"] = format_bytes_human(
            self.user_service.compute_user_generated_disk_size(user.id)
        )
        return self.fill_default_attributes(template_specification)

    @cherrypy.expose
    @handle_error(redirect=True)
    @check_user
    def logout(self):
        """
        Logging out user and clean session
        """
        user = common.remove_from_session(common.KEY_USER)
        if user is not None:
            self.logger.debug("User " + user.username + " is just logging out!")
        common.remove_from_session(common.KEY_PROJECT)
        common.remove_from_session(common.KEY_BURST_CONFIG)