Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

see file size in file browser #3521

Closed
ggrrll opened this issue Apr 10, 2018 · 6 comments
Closed

see file size in file browser #3521

ggrrll opened this issue Apr 10, 2018 · 6 comments

Comments

@ggrrll
Copy link

ggrrll commented Apr 10, 2018

Hi,

I was wondering if there is a way (or if it's a planned feature ) to see the files size in the file browser, next to the modification time, for instance.

Thanks.

@takluyver
Copy link
Member

I don't think it's on the roadmap, but I don't see a problem with adding it, if someone wants to work on it.

The frontend and the API should treat it as optional information, because some storage backends may not have an easy way to calculate a size.

@ckilcrease
Copy link
Contributor

Sounds like a cool feature - could @ashleytqy, @rosaswaby, @danagilliann and I work on this together?

@takluyver
Copy link
Member

Absolutely! In general, if no-one has indicated that they're working on an issue, there's no need to ask permission to tackle it. :-)

Can you see what bits of code you'll need to look at?

@ashleytqy
Copy link
Contributor

ashleytqy commented Apr 14, 2018

is this the right place to start?

def _base_model(self, path):
"""Build the common base of a contents model"""
os_path = self._get_os_path(path)
info = os.lstat(os_path)
try:
last_modified = tz.utcfromtimestamp(info.st_mtime)
except (ValueError, OSError):
# Files can rarely have an invalid timestamp
# https://github.com/jupyter/notebook/issues/2539
# https://github.com/jupyter/notebook/issues/2757
# Use the Unix epoch as a fallback so we don't crash.
self.log.warning('Invalid mtime %s for %s', info.st_mtime, os_path)
last_modified = datetime(1970, 1, 1, 0, 0, tzinfo=tz.UTC)
try:
created = tz.utcfromtimestamp(info.st_ctime)
except (ValueError, OSError): # See above
self.log.warning('Invalid ctime %s for %s', info.st_ctime, os_path)
created = datetime(1970, 1, 1, 0, 0, tzinfo=tz.UTC)
# Create the base model.
model = {}
model['name'] = path.rsplit('/', 1)[-1]
model['path'] = path
model['last_modified'] = last_modified
model['created'] = created
model['content'] = None
model['format'] = None
model['mimetype'] = None
try:
model['writable'] = os.access(os_path, os.W_OK)
except OSError:
self.log.error("Failed to check write permissions on %s", os_path)
model['writable'] = False
return model

and

NotebookList.prototype.add_link = function (model, item) {
var that = this;
var running = (model.type === 'notebook' && this.sessions[model.path] !== undefined);
item.data('name',model.name);
item.data('path', model.path);
item.data('modified', model.last_modified);
item.data('type', model.type);
item.find(".item_name").text(bidi.applyBidi(model.name));
var icon = NotebookList.icons[model.type];
if (running) {
icon = 'running_' + icon;
}
var uri_prefix = NotebookList.uri_prefixes[model.type];
if (model.type === 'file' && this._is_viewable(model))
{
uri_prefix = 'view';
}
if (model.type === 'file' && this._is_pdflike(model))
{
uri_prefix = 'files';
}
if (model.type === 'file' && this._is_notebook(model))
{
uri_prefix = 'notebooks';
}
item.find(".item_icon").addClass(icon).addClass('icon-fixed-width');
var link = item.find("a.item_link")
.attr('href',
utils.url_path_join(
this.base_url,
uri_prefix,
utils.encode_uri_components(model.path)
)
);
item.find(".item_buttons .running-indicator").css('visibility', running ? '' : 'hidden');
// directory nav doesn't open new tabs
// files, notebooks do
if (model.type !== "directory") {
link.attr('target', IPython._target);
} else {
// Replace with a click handler that will use the History API to
// push a new route without reloading the page if the click is
// not modified (e.g., Ctrl-Click)
link.click(function (e) {
if(e.altKey || e.metaKey || e.shiftKey) {
return true;
}
window.history.pushState({
path: model.path
}, model.path, utils.url_path_join(
that.base_url,
'tree',
utils.encode_uri_components(model.path)
));
that.update_location(model.path);
return false;
});
}
// Add in the date that the file was last modified
item.find(".item_modified").text(utils.format_datetime(model.last_modified));
item.find(".item_modified").attr("title", moment(model.last_modified).format("YYYY-MM-DD HH:mm"));
};

@takluyver
Copy link
Member

Yep, that looks right. There are three kinds of model that the server can send to the frontend, for directories, notebooks, and files (i.e. files other than notebooks). It probably makes sense for notebooks and files to have a size field.

@takluyver
Copy link
Member

Fixed by #3539

@takluyver takluyver added this to the 5.5 milestone Apr 24, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 12, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants