#NEWLINE# def handle_noargs( self , **options ) : #NEWLINE# #INDENT# if options [ 'time' ] : #NEWLINE# #INDENT# start_time = datetime . datetime . now ( ) #NEWLINE# #UNINDENT# call_command ( 'syncdb' ) #NEWLINE# db_table = Geoname . _meta . db_table #NEWLINE# db_opts = get_cmd_options ( ) #NEWLINE# fromfile_cmd = 'psql %(db_opts)s -f %(sql_file)s' #NEWLINE# fromfile_args = { #NEWLINE# #INDENT# 'db_opts' : db_opts , #NEWLINE# #UNINDENT# } #NEWLINE# copy_sql = ( 'COPY %s (geonameid,name,alternates,fclass,fcode,country,cc2,admin1,admin2,admin3,admin4,population,elevation,topo,timezone,moddate,point) FROM STDIN;' % db_table ) #NEWLINE# copy_cmd = 'gunzip -c %(gz_file)s | psql %(db_opts)s -c "%(copy_sql)s"' #NEWLINE# copy_args = { #NEWLINE# #INDENT# 'gz_file' : os . path . join ( GEONAMES_DATA , 'allCountries.gz' ) , #NEWLINE# 'db_opts' : db_opts , #NEWLINE# 'copy_sql' : copy_sql , #NEWLINE# #UNINDENT# } #NEWLINE# if ( not options [ 'no_geonames' ] ) : #NEWLINE# #INDENT# fromfile_args [ 'sql_file' ] = os . path . join ( GEONAMES_SQL , 'drop_geoname_indexes.sql' ) #NEWLINE# print ( ( fromfile_cmd % fromfile_args ) ) #NEWLINE# os . system ( ( fromfile_cmd % fromfile_args ) ) #NEWLINE# print ( ( copy_cmd % copy_args ) ) #NEWLINE# os . system ( ( copy_cmd % copy_args ) ) #NEWLINE# fromfile_args [ 'sql_file' ] = os . path . join ( GEONAMES_SQL , 'create_geoname_indexes.sql' ) #NEWLINE# print ( ( fromfile_cmd % fromfile_args ) ) #NEWLINE# os . system ( ( fromfile_cmd % fromfile_args ) ) #NEWLINE# print ( 'Finished PostgreSQL `COPY` from Geonames all countries data file.' ) #NEWLINE# #UNINDENT# db_table = Alternate . _meta . db_table #NEWLINE# copy_sql = ( 'COPY %s (alternateid,geoname_id,isolanguage,variant,preferred,short) FROM STDIN;' % db_table ) #NEWLINE# copy_cmd = 'zcat %(gz_file)s | psql %(db_opts)s -c "%(copy_sql)s"' #NEWLINE# copy_args = { #NEWLINE# #INDENT# 'gz_file' : os . path . join ( GEONAMES_DATA , 'alternateNames.gz' ) , #NEWLINE# 'db_opts' : get_cmd_options ( ) , #NEWLINE# 'copy_sql' : copy_cmd , #NEWLINE# #UNINDENT# } #NEWLINE# if ( not options [ 'no_alternates' ] ) : #NEWLINE# #INDENT# fromfile_args [ 'sql_file' ] = os . path . join ( GEONAMES_SQL , 'drop_alternate_indexes.sql' ) #NEWLINE# print ( ( fromfile_cmd % fromfile_args ) ) #NEWLINE# os . system ( ( fromfile_cmd % fromfile_args ) ) #NEWLINE# print ( ( copy_cmd % copy_args ) ) #NEWLINE# os . system ( ( copy_cmd % copy_args ) ) #NEWLINE# print ( 'Finished PostgreSQL `COPY` from Geonames alternate names data file.' ) #NEWLINE# fromfile_args [ 'sql_file' ] = os . path . join ( GEONAMES_SQL , 'create_alternate_indexes.sql' ) #NEWLINE# print ( ( fromfile_cmd % fromfile_args ) ) #NEWLINE# os . system ( ( fromfile_cmd % fromfile_args ) ) #NEWLINE# #UNINDENT# if options [ 'time' ] : #NEWLINE# #INDENT# print ( ( '\nCompleted in %s' % ( datetime . datetime . now ( ) - start_time ) ) )