def update_free_space(self):
        """
        update the amount of free space currently available
        """
        # get the disk usage
        space = psutil.disk_usage(self.target_dir)

        #give ourselves a cushion for other processes
        self.free_space = int(.9 * space.free)

        self.free_size_str = file_tools.size_string(self.free_space)
Example #2
0
    def update_free_space(self):
        """
        update the amount of free space currently available
        this should go in file_tools
        """
        # get the disk usage
        space = psutil.disk_usage(self.target_dir)

        # give ourselves a cushion for other processes
        self.free_space = int(.9 * space.free)

        self.free_size_str = file_tools.size_string(self.free_space)
Example #3
0
def update_free_space(request):
    """
    update the amount of free space currently available
    this should go in file_tools
    """
    # get the disk usage
    space = psutil.disk_usage(configuration.target_dir)

    # give ourselves a cushion for other processes
    free_space = int(.9 * space.free)
    free_size_str = file_tools.size_string(free_space)

    request.session['free_space'] = free_space
    request.session['free_size_str'] = free_size_str
    request.session.modified = True
Example #4
0
def make_leaf(title, path):
    '''
    return a populated tree leaf
    '''
    if session.files.accessible(path):
        if os.path.isfile(path):
            size = os.path.getsize(path)
            is_folder = False
        elif os.path.isdir(path):
            size = session.files.get_size(path)
            is_folder = True

    session.files.bundle_size += size
    
    size_string = file_tools.size_string(size)
    return {"title": title + " (" + size_string + ")",
            "key": path,
            "folder": is_folder,
            "data":{"size":size}}
Example #5
0
def make_leaf(title, path, files):
    '''
    return a populated tree leaf
    '''
    if files.accessible(path):
        if os.path.isfile(path):
            size = os.path.getsize(path)
            is_folder = False
        elif os.path.isdir(path):
            size = files.get_size(path)
            is_folder = True

    files.bundle_size += size

    size_string = file_tools.size_string(size)
    return {'title': title + ' (' + size_string + ')',
            'key': path,
            'folder': is_folder,
            'data': {'size': size}}
Example #6
0
def return_bundle(tree, message):
    """
    formats the return message from get_bundle
    """
    # validate that the currently selected bundle will fit in the target space
    upload_enabled = session.validate_space_available()
    # disable the upload if there isn't enough space in the intermediate directory
    tree[0]['enabled'] = upload_enabled
    if not upload_enabled:
        message = message + ' The amount of data you are trying to transfer is larger ' \
            'than the space available in the Uploader Controller.  '\
            'Reduce the size of the data set or contact an administrator to help address this issue.'

    session.files.bundle_size_str = file_tools.size_string(session.files.bundle_size)
    if message != "":
        tree[0]['data'] = 'Bundle: %s, Free: %s, Warning: %s' % (session.files.bundle_size_str, configuration.free_size_str, message)
    else:
        tree[0]['data'] = 'Bundle: %s, Free: %s' % (session.files.bundle_size_str, configuration.free_size_str)

    retval = json.dumps(tree)
    return HttpResponse(retval, content_type="application/json")
Example #7
0
def get_bundle(request):
    """
    return a tree structure containing directories and files to be uploaded
    """
    files = FileManager()

    tree = []

    try:

        tar_man.clean_target_directory(configuration.target_dir)

        files.error_string = ''

        print 'get pseudo directory'
        tree, lastnode = get_archive_tree(request)
        files.bundle_size = 0

        request.session['bundle_size'] = files.bundle_size
        request.session['bundle_size_str'] = file_tools.size_string(files.bundle_size)
        request.session.modified = True

        pathstring = request.POST.get('packet')

        # can get a request with 0 paths, return empty bundle
        if not pathstring:
            return return_bundle(request, tree, '')

        paths = json.loads(pathstring)

        # if no paths, return the empty archive structure
        if not paths:
            return return_bundle(request, tree, '')

        common_path = request.session['data_dir']

        # add a final separator
        common_path = os.path.join(common_path, '')

        # used later to modify arc names
        files.common_path = common_path

        for itempath in paths:
            # title
            item = os.path.basename(itempath)

            # tree structure
            # handle rood directory slightly differently
            if configuration.data_dir == itempath:
                head, tail = os.path.split(itempath)
                clipped_path = tail
            else:
                clipped_path = itempath.replace(common_path, '')

            subdirs = []
            make_tree(lastnode, subdirs, clipped_path, item, itempath, files)

        request.session['common_path'] = files.common_path
        request.session['bundle_size'] = files.bundle_size
        request.session['bundle_size_str'] = file_tools.size_string(files.bundle_size)
        request.session.modified = True

        return return_bundle(request, tree, files.error_string)

    except Exception, ex:
        print_err(ex)
        return return_bundle(request, tree, 'get_bundle failed:  ' + ex.message)