<s> """<STR_LIT>""" <EOL> import os <EOL> import gzip <EOL> import zipfile <EOL> from itertools import product <EOL> from django . conf import settings <EOL> from django . core import serializers <EOL> from django . db import router , DEFAULT_DB_ALIAS <EOL> from django . db . models import get_apps <EOL> try : <EOL> import bz2 <EOL> has_bz2 = True <EOL> except ImportError : <EOL> has_bz2 = False <EOL> def tables_used_by_fixtures ( fixture_labels , using = DEFAULT_DB_ALIAS ) : <EOL> """<STR_LIT>""" <EOL> fixture_count = <NUM_LIT:0> <EOL> loaded_object_count = <NUM_LIT:0> <EOL> fixture_object_count = <NUM_LIT:0> <EOL> tables = set ( ) <EOL> class SingleZipReader ( zipfile . ZipFile ) : <EOL> def __init__ ( self , * args , ** kwargs ) : <EOL> zipfile . ZipFile . __init__ ( self , * args , ** kwargs ) <EOL> if settings . DEBUG : <EOL> assert len ( self . namelist ( ) ) == <NUM_LIT:1> , "<STR_LIT>" <EOL> def read ( self ) : <EOL> return zipfile . ZipFile . read ( self , self . namelist ( ) [ <NUM_LIT:0> ] ) <EOL> compression_types = { <EOL> None : file , <EOL> '<STR_LIT>' : gzip . GzipFile , <EOL> '<STR_LIT>' : SingleZipReader <EOL> } <EOL> if has_bz2 : <EOL> compression_types [ '<STR_LIT>' ] = bz2 . BZ2File <EOL> app_module_paths = [ ] <EOL> for app in get_apps ( ) : <EOL> if hasattr ( app , '<STR_LIT>' ) : <EOL> for path in app . __path__ : <EOL> app_module_paths . append ( path ) <EOL> else : <EOL> app_module_paths . append ( app . __file__ ) <EOL> app_fixtures = [ os . path . join ( os . path . dirname ( path ) , '<STR_LIT>' ) for path in app_module_paths ] <EOL> for fixture_label in fixture_labels : <EOL> parts = fixture_label . split ( '<STR_LIT:.>' ) <EOL> if len ( parts ) > <NUM_LIT:1> and parts [ - <NUM_LIT:1> ] in compression_types : <EOL> compression_formats = [ parts [ - <NUM_LIT:1> ] ] <EOL> parts = parts [ : - <NUM_LIT:1> ] <EOL> else : <EOL> compression_formats = list ( compression_types . keys ( ) ) <EOL> if len ( parts ) == <NUM_LIT:1> : <EOL> fixture_name = parts [ <NUM_LIT:0> ] <EOL> formats = serializers . get_public_serializer_formats ( ) <EOL> else : <EOL> fixture_name , format = '<STR_LIT:.>' . join ( parts [ : - <NUM_LIT:1> ] ) , parts [ - <NUM_LIT:1> ] <EOL> if format in serializers . get_public_serializer_formats ( ) : <EOL> formats = [ format ] <EOL> else : <EOL> formats = [ ] <EOL> if not formats : <EOL> return set ( ) <EOL> if os . path . isabs ( fixture_name ) : <EOL> fixture_dirs = [ fixture_name ] <EOL> else : <EOL> fixture_dirs = app_fixtures + list ( settings . FIXTURE_DIRS ) + [ '<STR_LIT>' ] <EOL> for fixture_dir in fixture_dirs : <EOL> label_found = False <EOL> for combo in product ( [ using , None ] , formats , compression_formats ) : <EOL> database , format , compression_format = combo <EOL> file_name = '<STR_LIT:.>' . join ( <EOL> p for p in [ <EOL> fixture_name , database , format , compression_format <EOL> ] <EOL> if p <EOL> ) <EOL> full_path = os . path . join ( fixture_dir , file_name ) <EOL> open_method = compression_types [ compression_format ] <EOL> try : <EOL> fixture = open_method ( full_path , '<STR_LIT:r>' ) <EOL> if label_found : <EOL> fixture . close ( ) <EOL> return set ( ) <EOL> else : <EOL> fixture_count += <NUM_LIT:1> <EOL> objects_in_fixture = <NUM_LIT:0> <EOL> loaded_objects_in_fixture = <NUM_LIT:0> <EOL> try : <EOL> objects = serializers . deserialize ( format , fixture , using = using ) <EOL> for obj in objects : <EOL> objects_in_fixture += <NUM_LIT:1> <EOL> if router . allow_syncdb ( using , obj . object . __class__ ) : <EOL> loaded_objects_in_fixture += <NUM_LIT:1> <EOL> tables . add ( <EOL> obj . object . __class__ . _meta . db_table ) <EOL> loaded_object_count += loaded_objects_in_fixture <EOL> fixture_object_count += objects_in_fixture <EOL> label_found = True <EOL> except ( SystemExit , KeyboardInterrupt ) : <EOL> raise <EOL> except Exception : <EOL> fixture . close ( ) <EOL> return set ( ) <EOL> fixture . close ( ) <EOL> if objects_in_fixture == <NUM_LIT:0> : <EOL> return set ( ) <EOL> except Exception : <EOL> pass <EOL> return tables </s>
