Skip to content

Commit

Permalink
Appease Standardrb
Browse files Browse the repository at this point in the history
  • Loading branch information
moseshll committed Oct 20, 2023
1 parent 7a604c1 commit 96d75a7
Show file tree
Hide file tree
Showing 16 changed files with 133 additions and 172 deletions.
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ require "rspec/core/rake_task"

RSpec::Core::RakeTask.new(:spec)

task :default => :spec
task default: :spec
36 changes: 17 additions & 19 deletions exe/catchup
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
#!/usr/bin/env ruby

require 'date_named_file'
require 'hathifiles_database'
require 'dotenv'
require 'date'
require "date_named_file"
require "hathifiles_database"
require "dotenv"
require "date"

HF_FILES = '/htapps/archive/hathifiles'
LOGFILE_DIR ='../logs/hathifiles_database'
HF_FILES = "/htapps/archive/hathifiles"
LOGFILE_DIR = "../logs/hathifiles_database"

def usage
puts "
Usage:
Usage:
ruby #{__FILE__} <start_date_or_keyword> <'dev' or 'production'>
e.g ruby #{__FILE__} 20211101 production
ruby #{__FILE__} first_of_month dev # or just 'fom'
Expand All @@ -25,15 +25,15 @@ usage if ARGV.size != 2

devprod = ARGV[1].downcase
envfilename = case devprod.downcase
when 'dev'
'.devenv'
when 'prod'
'.env'
else
puts "\nUnknown target '#{devprod}'"
usage
exit 1
end
when "dev"
".devenv"
when "prod"
".env"
else
puts "\nUnknown target '#{devprod}'"
usage
exit 1
end
envfile = Pathname.new(__dir__).parent + envfilename

start_date = ARGV[0].downcase
Expand All @@ -44,11 +44,9 @@ elsif %w[yesterday].include? start_date
start_date = today - 1
end



Dotenv.load(envfile)

connection_string = ENV['HATHIFILES_MYSQL_CONNECTION']
connection_string = ENV["HATHIFILES_MYSQL_CONNECTION"]
connection = HathifilesDatabase.new(connection_string)

connection.logger.info "Connecting to #{connection_string}"
Expand Down
23 changes: 11 additions & 12 deletions exe/swap_production_and_reindex
Original file line number Diff line number Diff line change
@@ -1,23 +1,23 @@
#!/usr/bin/env ruby

require 'date_named_file'
require 'hathifiles_database'
require 'dotenv'
require "date_named_file"
require "hathifiles_database"
require "dotenv"

HF_FILES = '/htapps/archive/hathifiles'
LOGFILE_DIR ='../logs/hathifiles_database'
HF_FILES = "/htapps/archive/hathifiles"
LOGFILE_DIR = "../logs/hathifiles_database"

envfile = Pathname.new(__dir__).parent + '.env'
devenvfile = Pathname.new(__dir__).parent + '.devenv'
envfile = Pathname.new(__dir__).parent + ".env"
# devenvfile = Pathname.new(__dir__).parent + ".devenv"

Dotenv.load(envfile)
connection_string = ENV['HATHIFILES_MYSQL_CONNECTION']
connection_string = ENV["HATHIFILES_MYSQL_CONNECTION"]
connection = HathifilesDatabase.new(connection_string)

production = connection.rawdb

Dotenv.load(envfile)
connection_string = ENV['HATHIFILES_MYSQL_CONNECTION']
connection_string = ENV["HATHIFILES_MYSQL_CONNECTION"]
reindex_connection = HathifilesDatabase.new(connection_string)

reindex = reindex_connection.rawdb
Expand All @@ -34,12 +34,11 @@ def ri(t)
"hathifiles_reindex.#{t}"
end


# Get tables that are in both
tables = production.tables.intersection(reindex.tables)

renames = tables.flat_map{|t| [[prod(t), tmp(t)], [ri(t), prod(t)], [tmp(t), ri(t)]]}
sql = "RENAME TABLE " + renames.map{|x| x.join(" TO ")}.join(', ')
renames = tables.flat_map { |t| [[prod(t), tmp(t)], [ri(t), prod(t)], [tmp(t), ri(t)]] }
sql = "RENAME TABLE " + renames.map { |x| x.join(" TO ") }.join(", ")

production.run(sql)

Expand Down
26 changes: 12 additions & 14 deletions hathifiles_database.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,19 @@ Gem::Specification.new do |spec|
spec.authors = ["Bill Dueber"]
spec.email = ["[email protected]"]

spec.summary = %q{Keep a database of the data in the hathifiles}
spec.summary = "Keep a database of the data in the hathifiles"
spec.homepage = "https://github.com/billdueber/hathifiles_database"
spec.license = "MIT"

spec.metadata["allowed_push_host"] = "http://gems.www.lib.umich.edu"

spec.metadata["homepage_uri"] = spec.homepage
spec.metadata["source_code_uri"] = spec.homepage
spec.metadata["changelog_uri"] = spec.homepage + '/CHANGELOG.md'
spec.metadata["changelog_uri"] = spec.homepage + "/CHANGELOG.md"

# Specify which files should be added to the gem when it is released.
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
spec.files = Dir.chdir(File.expand_path("..", __FILE__)) do
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
end
spec.bindir = "exe"
Expand All @@ -33,16 +33,14 @@ Gem::Specification.new do |spec|
spec.add_development_dependency "pry"
spec.add_development_dependency "yard"

spec.add_dependency 'dotenv'
spec.add_dependency 'ettin' # config
spec.add_dependency 'library_stdnums' # normalize
spec.add_dependency 'sequel'
spec.add_dependency 'hanami-cli' # command line

spec.add_dependency 'sqlite3'
spec.add_dependency 'mysql2'
spec.add_dependency 'tty-prompt'
spec.add_dependency 'date_named_file'

spec.add_dependency "dotenv"
spec.add_dependency "ettin" # config
spec.add_dependency "library_stdnums" # normalize
spec.add_dependency "sequel"
spec.add_dependency "hanami-cli" # command line

spec.add_dependency "sqlite3"
spec.add_dependency "mysql2"
spec.add_dependency "tty-prompt"
spec.add_dependency "date_named_file"
end
6 changes: 3 additions & 3 deletions lib/hathifiles_database.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# frozen_string_literal: true

require 'hathifiles_database/version'
require 'hathifiles_database/datafile'
require 'hathifiles_database/db/connection'
require "hathifiles_database/version"
require "hathifiles_database/datafile"
require "hathifiles_database/db/connection"

module HathifilesDatabase
def self.new(connection_string)
Expand Down
15 changes: 5 additions & 10 deletions lib/hathifiles_database/cli.rb
Original file line number Diff line number Diff line change
@@ -1,36 +1,31 @@
require 'date'
require 'hanami/cli'
require "date"
require "hanami/cli"

module HathifilesDatabase
module CLI
module Commands
extend Hanami::CLI::Registry

class Date8 < Date

def to_s
self.strftime('%Y%m%d')
strftime("%Y%m%d")
end

def self.range_since(dt)
dateify(dt).upto self.today
dateify(dt).upto today
end

def self.dateify(dt)
if dt.respond_to? :to_date
dt.to_date
else
self.parse(dt.to_s)
parse(dt.to_s)
end
end
end

class Update



end

end
end
end
6 changes: 3 additions & 3 deletions lib/hathifiles_database/columns.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Ordered as they are in the hathifiles
require 'library_stdnums'
require "library_stdnums"

module HathifilesDatabase
module Columns
Expand All @@ -13,13 +13,13 @@ class Column
# @param [Proc] transform_lambda Code to transform the data before storing
def initialize(column, table, transform_lambda = nil)
@column = column
@table = table.to_sym
@table = table.to_sym
@transform_lambda = transform_lambda
end

# @return [Boolean]
def scalar
raise 'Override #scalar for column types'
raise "Override #scalar for column types"
end
end

Expand Down
9 changes: 3 additions & 6 deletions lib/hathifiles_database/constants.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
# frozen_string_literal: true

# Ordered as they are in the hathifiles
require 'library_stdnums'
require 'logger'
require "library_stdnums"
require "logger"

module HathifilesDatabase
module Constants

LOGGER = Logger.new(STDERR)
LOGGER = Logger.new($stderr)

# Database table names
MAINTABLE = :hf
Expand All @@ -34,7 +33,5 @@ module Constants
content_provider_code

]

end
end

11 changes: 5 additions & 6 deletions lib/hathifiles_database/datafile.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
# frozen_string_literal: true

require 'zlib'
require_relative 'linespec'
require 'hathifiles_database/db/writer'
require 'delegate'
require "zlib"
require_relative "linespec"
require "hathifiles_database/db/writer"
require "delegate"

module HathifilesDatabase
class Datafile < SimpleDelegator
Expand Down Expand Up @@ -56,7 +56,7 @@ def dump_files_for_data_import(destination_dir, nodate_suffix: false)
filepaths = w_class.outputfile_paths_from_linespec(@linespec, output_dir: destination_dir, nodate_suffix: nodate_suffix)
writer = w_class.new(outputfile_paths: filepaths, maintable_name: @linespec.maintable_name)
line_number = 1
self.each do |line|
each do |line|
logger.info "#{line_number} lines processed" if line_number % 500_000 == 0
writer << line
line_number += 1
Expand All @@ -65,6 +65,5 @@ def dump_files_for_data_import(destination_dir, nodate_suffix: false)
logger.info ""
filepaths
end

end
end
Loading

0 comments on commit 96d75a7

Please sign in to comment.