mirror of
https://github.com/galaxyproject/galaxy.git
synced 2026-09-24 16:30:27 +08:00
Fix for '? lines'. When setting the peek, if the number of lines is not known, an estimate is made based on a small read.
This commit is contained in:
@@ -407,7 +407,15 @@ class Text( Data ):
|
||||
else:
|
||||
# Number of lines is not known ( this should not happen ), and auto-detect is
|
||||
# needed to set metadata
|
||||
dataset.blurb = "? lines"
|
||||
# This can happen when the file is larger than max_optional_metadata_filesize.
|
||||
# Perform a rough estimate by extrapolating number of lines from a small read.
|
||||
sample_size = min(self.max_optional_metadata_filesize, 1048576)
|
||||
dataset_fh = open( dataset.file_name )
|
||||
dataset_read = dataset_fh.read(sample_size)
|
||||
dataset_fh.close()
|
||||
sample_lines = dataset_read.count('\n')
|
||||
est_lines = int(sample_lines * (dataset.get_size() / float(sample_size)))
|
||||
dataset.blurb = "~%s lines" % util.commaify(str(est_lines))
|
||||
else:
|
||||
dataset.blurb = "%s lines" % util.commaify( str( line_count ) )
|
||||
else:
|
||||
|
||||
Reference in New Issue
Block a user