Move directory_hash_id into galaxy/util.py. Use util.directory_hash_id throughout.

This commit is contained in:
Dave Bouvier
2016-06-09 12:18:22 -04:00
parent b3edbcaec7
commit 4c6389fb05
8 changed files with 34 additions and 54 deletions
@@ -8,7 +8,6 @@ from ..collectl import cli
from ..collectl import processes
from galaxy import util
from galaxy.util import directory_hash
import logging
log = logging.getLogger( __name__ )
@@ -109,7 +108,7 @@ class CollectlPlugin( InstrumentPlugin ):
)
if self.saved_logs_path:
destination_rel_dir = os.path.join( *directory_hash.directory_hash_id( job_id ) )
destination_rel_dir = os.path.join( *util.directory_hash_id( job_id ) )
destination_rel_path = os.path.join( destination_rel_dir, rel_path )
destination_path = os.path.join( self.saved_logs_path, destination_rel_path )
destination_dir = os.path.dirname( destination_path )
+1 -2
View File
@@ -34,11 +34,10 @@ from galaxy.util.dictifiable import Dictifiable
from galaxy.security import get_permitted_actions
from galaxy.util import Params, restore_text, send_mail
from galaxy.util import ready_name_for_url, unique_id
from galaxy.util import unicodify
from galaxy.util import unicodify, directory_hash_id
from galaxy.util.multi_byte import is_multi_byte
from galaxy.util.hash_util import new_secure_hash
from galaxy.util.bunch import Bunch
from galaxy.util.directory_hash import directory_hash_id
from galaxy.util.sanitize_html import sanitize_html
from galaxy.web.framework.helpers import to_unicode
from galaxy.web.form_builder import (AddressField, CheckboxField, HistoryField,
+1 -2
View File
@@ -12,10 +12,9 @@ import logging
import threading
from xml.etree import ElementTree
from galaxy.util import umask_fix_perms, force_symlink, safe_makedirs, safe_relpath
from galaxy.util import umask_fix_perms, force_symlink, safe_makedirs, safe_relpath, directory_hash_id
from galaxy.exceptions import ObjectInvalid, ObjectNotFound
from galaxy.util.sleeper import Sleeper
from galaxy.util.directory_hash import directory_hash_id
from galaxy.util.odict import odict
try:
from sqlalchemy.orm import object_session
+1 -2
View File
@@ -13,8 +13,7 @@ import time
from datetime import datetime
from galaxy.exceptions import ObjectNotFound, ObjectInvalid
from galaxy.util import string_as_bool, umask_fix_perms, safe_relpath
from galaxy.util.directory_hash import directory_hash_id
from galaxy.util import string_as_bool, umask_fix_perms, safe_relpath, directory_hash_id
from galaxy.util.sleeper import Sleeper
from .s3_multipart_upload import multipart_upload
from ..objectstore import ObjectStore, convert_bytes
+29
View File
@@ -113,6 +113,35 @@ def is_uuid( value ):
return False
def directory_hash_id( id ):
"""
>>> directory_hash_id( 100 )
['000']
>>> directory_hash_id( "90000" )
['090']
>>> directory_hash_id("777777777")
['000', '777', '777']
>>> directory_hash_id("135ee48a-4f51-470c-ae2f-ce8bd78799e6")
['1', '3', '5']
"""
s = str( id )
l = len( s )
# Shortcut -- ids 0-999 go under ../000/
if l < 4:
return [ "000" ]
if not is_uuid(s):
# Pad with zeros until a multiple of three
padded = ( ( 3 - len( s ) % 3 ) * "0" ) + s
# Drop the last three digits -- 1000 files per directory
padded = padded[:-3]
# Break into chunks of three
return [ padded[ i * 3:(i + 1 ) * 3 ] for i in range( len( padded ) // 3 ) ]
else:
# assume it is a UUID
return list(iter(s[0:3]))
def get_charset_from_http_headers( headers, default=None ):
rval = headers.get('content-type', None )
if rval and 'charset=' in rval:
-31
View File
@@ -1,31 +0,0 @@
from galaxy.util import is_uuid
def directory_hash_id( id ):
"""
>>> directory_hash_id( 100 )
['000']
>>> directory_hash_id( "90000" )
['090']
>>> directory_hash_id("777777777")
['000', '777', '777']
>>> directory_hash_id("135ee48a-4f51-470c-ae2f-ce8bd78799e6")
['1', '3', '5']
"""
s = str( id )
l = len( s )
# Shortcut -- ids 0-999 go under ../000/
if l < 4:
return [ "000" ]
if not is_uuid(s):
# Pad with zeros until a multiple of three
padded = ( ( 3 - len( s ) % 3 ) * "0" ) + s
# Drop the last three digits -- 1000 files per directory
padded = padded[:-3]
# Break into chunks of three
return [ padded[ i * 3:(i + 1 ) * 3 ] for i in range( len( padded ) // 3 ) ]
else:
# assume it is a UUID
return list(iter(s[0:3]))
@@ -507,17 +507,3 @@ def sort_by_attr( seq, attr ):
intermed = map( None, map( getattr, seq, ( attr, ) * len( seq ) ), xrange( len( seq ) ), seq )
intermed.sort()
return map( operator.getitem, intermed, ( -1, ) * len( intermed ) )
def directory_hash_id( id ):
s = str( id )
l = len( s )
# Shortcut -- ids 0-999 go under ../000/
if l < 4:
return [ "000" ]
# Pad with zeros until a multiple of three
padded = ( ( ( 3 - len( s ) ) % 3 ) * "0" ) + s
# Drop the last three digits -- 1000 files per directory
padded = padded[:-3]
# Break into chunks of three
return [ padded[i * 3:(i + 1) * 3] for i in range( len( padded ) // 3 ) ]
+1 -1
View File
@@ -269,7 +269,7 @@ def create_repository( app, name, type, description, long_description, user_id,
# Create an admin role for the repository.
create_repository_admin_role( app, repository )
# Determine the repository's repo_path on disk.
dir = os.path.join( app.config.file_path, *galaxy.webapps.tool_shed.model.directory_hash_id( repository.id ) )
dir = os.path.join( app.config.file_path, *util.directory_hash_id( repository.id ) )
# Create directory if it does not exist.
if not os.path.exists( dir ):
os.makedirs( dir )