[2] | 1 | #!/usr/bin/env python |
---|
| 2 | """ |
---|
| 3 | Updates dataset.size column. |
---|
| 4 | Remember to backup your database before running. |
---|
| 5 | """ |
---|
| 6 | |
---|
| 7 | import sys, os, ConfigParser |
---|
| 8 | import galaxy.app |
---|
| 9 | |
---|
| 10 | assert sys.version_info[:2] >= ( 2, 4 ) |
---|
| 11 | |
---|
| 12 | def main(): |
---|
| 13 | ini_file = sys.argv.pop(1) |
---|
| 14 | conf_parser = ConfigParser.ConfigParser( {'here':os.getcwd()} ) |
---|
| 15 | conf_parser.read( ini_file ) |
---|
| 16 | configuration = {} |
---|
| 17 | for key, value in conf_parser.items( "app:main" ): |
---|
| 18 | configuration[key] = value |
---|
| 19 | app = galaxy.app.UniverseApplication( global_conf = ini_file, **configuration ) |
---|
| 20 | |
---|
| 21 | #Step through Datasets, determining size on disk for each. |
---|
| 22 | print "Determining the size of each dataset..." |
---|
| 23 | for row in app.model.Dataset.table.select().execute(): |
---|
| 24 | purged = app.model.Dataset.get( row.id ).purged |
---|
| 25 | file_size = app.model.Dataset.get( row.id ).file_size |
---|
| 26 | if file_size is None and not purged: |
---|
| 27 | size_on_disk = app.model.Dataset.get( row.id ).get_size() |
---|
| 28 | print "Updating Dataset.%d with file_size: %d" %( row.id, size_on_disk ) |
---|
| 29 | app.model.Dataset.table.update( app.model.Dataset.table.c.id == row.id ).execute( file_size=size_on_disk ) |
---|
| 30 | app.shutdown() |
---|
| 31 | sys.exit(0) |
---|
| 32 | |
---|
| 33 | if __name__ == "__main__": |
---|
| 34 | main() |
---|