-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
major refactoring improving configuration system
it now has a default file with mostly all configuration, and a user config where it choses
- Loading branch information
1 parent
042c16c
commit 8e579c4
Showing
14 changed files
with
245 additions
and
252 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,6 @@ | ||
output/ | ||
config.yml | ||
*~ | ||
Gemfile.lock | ||
vendor/bundle | ||
.bundle |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
source 'http://rubygems.org' | ||
|
||
gem 'bio' | ||
gem 'deep_merge' | ||
gem 'configatron', :github => 'markbates/configatron' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
require 'configatron/core' | ||
|
||
require 'yaml' | ||
|
||
# | ||
# | ||
# | ||
module ConfigBlast | ||
# | ||
def initialize(*args) | ||
# setup config defaults | ||
@store = Configatron::RootStore.new | ||
@store.config.default = File.expand_path('default.yml') | ||
@store.config.user = File.expand_path('config.yml') | ||
end | ||
|
||
def reload_config(config_path = nil) | ||
config_path = @store.config.user if config_path.nil? | ||
# get configuration from default yml file | ||
logger.info("loads configuration from defaults: #{@store.config.default}") | ||
@store.configure_from_hash(YAML.load_file(@store.config.default)) | ||
logger.info("loads configuration from user: #{config_path}") | ||
@store.configure_from_hash(YAML.load_file(config_path)) | ||
# process the configuration to adjust paths and values | ||
process_config | ||
logger.debug('loaded and processed configuration files') | ||
end | ||
|
||
private | ||
|
||
# create output dir if does not exist | ||
def create_output_dir | ||
begin | ||
Dir.mkdir @store.output.dir unless Dir.exist?(@store.output.dir) | ||
rescue | ||
logger.error(msg = 'Could not create output directory') | ||
raise msg | ||
end | ||
# create output dir with timestamp | ||
begin | ||
if !@store.key?(:force_folder) | ||
@store.output.dir += File::Separator + | ||
Time.now.strftime('%Y_%m_%d-%H_%M_%S') + | ||
'-' + srand.to_s[3..6] | ||
Dir.mkdir @store.output.dir | ||
else | ||
@store.output.dir += File::Separator + @store.force_folder | ||
Dir.mkdir(@store.output.dir) unless Dir.exist?(@store.output.dir) | ||
end | ||
rescue StandardError => e | ||
logger.error msg = "Could not create output directory (why: #{e.message})" | ||
raise msg | ||
end | ||
end | ||
|
||
# | ||
# | ||
# Set config variables | ||
def process_config | ||
# optional arguments | ||
@store.identity_threshold *= 100 | ||
# convert paths to an absolutes | ||
@store.output.dir = File.expand_path(@store.output.dir) | ||
@store.db.parent = File.expand_path(@store.db.parent) | ||
@store.query.parent = File.expand_path(@store.query.parent) | ||
# create the output directory | ||
create_output_dir | ||
# | ||
logger.debug('query_parent: ' + @store.query.parent) | ||
logger.debug('db_parent: ' + @store.db.parent) | ||
# | ||
fail 'Databases must be defined in config.yml.' if @store.db.list.nil? | ||
fail 'Folders must be defined in config.yml.' if @store.query.folders.nil? | ||
# set existing dbs | ||
logger.info("loads databases (from directory '#{@store.db.parent}'): " + | ||
@store.db.list.join(', ')) | ||
end | ||
end |
Oops, something went wrong.