Fix the remaining 1334 flake8 errors in scripts/ . Close #391.

This commit is contained in:
Nicola Soranzo
2016-02-18 15:45:15 +00:00
parent f5277a654a
commit 93348e7199
55 changed files with 1513 additions and 1439 deletions
+16 -8
View File
@@ -10,19 +10,21 @@ Run from the ~/scripts/data_libraries directory:
%sh build_lucene_index.sh
"""
import sys
import os
import csv
import urllib, urllib2
import ConfigParser
import csv
import os
import sys
import urllib
import urllib2
new_path = [ os.path.join( os.getcwd(), "lib" ) ]
new_path.extend( sys.path[1:] ) # remove scripts/ from the path
new_path.extend( sys.path[1:] ) # remove scripts/ from the path
sys.path = new_path
import galaxy.model.mapping
from galaxy import config, model
def main( ini_file ):
sa_session, gconfig = get_sa_session( ini_file )
max_size = float( gconfig.get( "fulltext_max_size", 100 ) ) * 1048576
@@ -37,11 +39,13 @@ def main( ini_file ):
if os.path.exists( dataset_file ):
os.remove( dataset_file )
def build_index( search_url, dataset_file ):
url = "%s/index?%s" % ( search_url, urllib.urlencode( { "docfile" : dataset_file } ) )
request = urllib2.Request( url )
request.get_method = lambda: "PUT"
response = urllib2.urlopen( request )
urllib2.urlopen( request )
def create_dataset_file( dataset_iter ):
dataset_file = os.path.join( os.getcwd(), "full-text-search-files.csv" )
@@ -52,6 +56,7 @@ def create_dataset_file( dataset_iter ):
out_handle.close()
return dataset_file
def get_lddas( sa_session, max_size, ignore_exts ):
for ldda in sa_session.query( model.LibraryDatasetDatasetAssociation ).filter_by( deleted=False ):
if ( float( ldda.dataset.get_size() ) > max_size or ldda.extension in ignore_exts ):
@@ -60,6 +65,7 @@ def get_lddas( sa_session, max_size, ignore_exts ):
fname = ldda.dataset.get_file_name()
yield ldda.id, fname, _get_dataset_metadata(ldda).replace("\n", " ")
def _get_dataset_metadata(ldda):
"""Retrieve descriptions and information associated with a dataset.
"""
@@ -73,6 +79,7 @@ def _get_dataset_metadata(ldda):
return "%s %s %s %s %s" % (lds.name or "", lds_info, ldda.metadata.dbkey,
ldda.message, folder_info)
def _get_folder_info(folder):
"""Get names and descriptions for all parent folders except top level.
"""
@@ -81,11 +88,12 @@ def _get_folder_info(folder):
folder_info = _get_folder_info(folder.parent)
folder_info += " %s %s" % (
folder.name.replace("Unnamed folder", ""),
folder.description or "")
folder.description or "")
return folder_info
def get_sa_session( ini_file ):
conf_parser = ConfigParser.ConfigParser( { 'here':os.getcwd() } )
conf_parser = ConfigParser.ConfigParser( { 'here': os.getcwd() } )
conf_parser.read( ini_file )
kwds = dict()
for key, value in conf_parser.items( "app:main" ):
+10 -7
View File
@@ -8,32 +8,33 @@ data library search section for more details.
Run from the ~/scripts/data_libraries directory:
%sh build_whoosh_index.sh
"""
import sys, os, csv, urllib, urllib2, ConfigParser
import ConfigParser
import os
import sys
new_path = [ os.path.join( os.getcwd(), "lib" ) ]
new_path.extend( sys.path[1:] ) # remove scripts/ from the path
new_path.extend( sys.path[1:] ) # remove scripts/ from the path
sys.path = new_path
# Whoosh is compatible with Python 2.5+ Try to import Whoosh and set flag to indicate whether search is enabled.
try:
from whoosh.filedb.filestore import FileStorage
from whoosh.fields import Schema, STORED, ID, KEYWORD, TEXT
from whoosh.index import Index
from whoosh.fields import Schema, STORED, TEXT
whoosh_search_enabled = True
schema = Schema( id=STORED, name=TEXT, info=TEXT, dbkey=TEXT, message=TEXT )
import galaxy.model.mapping
from galaxy import config, model
import pkg_resources
pkg_resources.require( "SQLAlchemy >= 0.4" )
except ImportError, e:
whoosh_search_enabled = False
schema = None
def build_index( sa_session, whoosh_index_dir ):
storage = FileStorage( whoosh_index_dir )
index = storage.create_index( schema )
writer = index.writer()
def to_unicode( a_basestr ):
if type( a_basestr ) is str:
return unicode( a_basestr, 'utf-8' )
@@ -50,6 +51,7 @@ def build_index( sa_session, whoosh_index_dir ):
writer.commit()
print "Number of active library datasets indexed: ", lddas_indexed
def get_lddas( sa_session ):
for ldda in sa_session.query( model.LibraryDatasetDatasetAssociation ).filter_by( deleted=False ):
id = ldda.id
@@ -66,6 +68,7 @@ def get_lddas( sa_session ):
message = ''
yield id, name, info, dbkey, message
def get_sa_session_and_needed_config_settings( ini_file ):
conf_parser = ConfigParser.ConfigParser( { 'here' : os.getcwd() } )
conf_parser.read( ini_file )