From 46736e0e02d239554cf6cf6960a630f02dca0ac7 Mon Sep 17 00:00:00 2001 From: Sarav Shah Date: Mon, 27 Aug 2018 15:27:27 -0700 Subject: [PATCH 01/10] Delete all bin files --- bin/batch_run | 42 ----------- bin/cleanup | 23 ------ bin/completion_report | 41 ----------- bin/correct_version | 125 --------------------------------- bin/discovery_report | 30 -------- bin/get_total_objects | 26 ------- bin/mods_report | 54 -------------- bin/mods_report2 | 48 ------------- bin/pre-assemble | 36 ---------- bin/project_tag_report | 30 -------- bin/remediate | 155 ----------------------------------------- 11 files changed, 610 deletions(-) delete mode 100755 bin/batch_run delete mode 100755 bin/cleanup delete mode 100755 bin/completion_report delete mode 100755 bin/correct_version delete mode 100755 bin/discovery_report delete mode 100755 bin/get_total_objects delete mode 100755 bin/mods_report delete mode 100755 bin/mods_report2 delete mode 100755 bin/pre-assemble delete mode 100755 bin/project_tag_report delete mode 100755 bin/remediate diff --git a/bin/batch_run b/bin/batch_run deleted file mode 100755 index f1e50225..00000000 --- a/bin/batch_run +++ /dev/null @@ -1,42 +0,0 @@ -#! /bin/bash -# run with -# RAILS_ENV=production bundle exec bin/batch_run YAML_CONFIG [LIMIT_N] - -# Load YAML config file for the bundle of materials to be pre-assembled. -yaml=$1 -if [ $# == 2 ] ; then # if there is a limit specified use it, otherwise use the default of 100 - limit=$2 -else - limit=100 -fi - -echo "" -date -echo "PROCESSING $yaml" -echo "LIMIT = $limit" - -num_objects="$(bin/get_total_objects $yaml)" -num_runs=$[num_objects/limit + 1] -i="1" - -echo "$num_objects incomplete objects to process; will require an estimated $num_runs runs with limit of $limit" - -echo "" - -while [ $num_objects -gt 0 ]; do - echo "-------------------------------" - echo " ON RUN NUMBER $i OF $num_runs" - cmd="bundle exec bin/pre-assemble $yaml --limit $limit --resume" - echo $cmd - echo "-------------------------------" - bash -c "$cmd" - i=$[$i + 1] - num_objects="$(bin/get_total_objects $yaml)" - done - - echo "" - echo "COMPLETED $num_runs RUNS" - if [ "$num_objects" -ne "0" ] ; then - echo "***** WARNING! THERE ARE $num_objects OBJECTS LEFT *****" - fi - date diff --git a/bin/cleanup b/bin/cleanup deleted file mode 100755 index 5e2cb3d6..00000000 --- a/bin/cleanup +++ /dev/null @@ -1,23 +0,0 @@ -#! /usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../config/boot') - -def help(error_msg) - abort "#{error_msg}\n\nUsage:\n cleanup YAML_CONFIG_FILE stacks,dor,stage,symlinks,workflows [dry_run]\n" -end - -# Load YAML config file for the bundle of materials to be pre-assembled. -help "Incorrect N of arguments." if ARGV.size < 2 -yaml_config = ARGV.shift -help "YAML file not found." unless File.file? yaml_config -params = YAML.load(File.read yaml_config) - -steps = ARGV.shift.split(',').collect! { |x| x.to_sym } -dry_run = ARGV.shift ? true : false - -begin - b = PreAssembly::Bundle.new(PreAssembly::BundleContext.new(params)) - b.cleanup!(steps, dry_run) -rescue PreAssembly::BundleUsageError => e - help e.message -end diff --git a/bin/completion_report b/bin/completion_report deleted file mode 100755 index c7b40c90..00000000 --- a/bin/completion_report +++ /dev/null @@ -1,41 +0,0 @@ -#! /usr/bin/env ruby - -n = 50 # run 50 druids at a time against solr - -require File.expand_path(File.dirname(__FILE__) + '/../config/boot') - -def help(error_msg) - abort "#{error_msg}\n\nUsage:\n ./bin/completion_report YAML_CONFIG_FILE\n" -end - -help "Incorrect number of arguments." unless ARGV.size == 1 - -yaml_config = ARGV[0] -help "YAML file not found." unless File.file? yaml_config - -params = YAML.load(File.read yaml_config) -params['config_filename'] = yaml_config -progress_filename = params['progress_log_file'] - -completed_druids = Assembly::Utils.get_druids_from_log(progress_filename, true) - -help "no completed druids found in '#{progress_filename}'" if completed_druids.size == 0 - -puts "Running report with #{completed_druids.size} objects" - -batch_druids = completed_druids.each_slice(n).to_a - -report_filename = "../log/#{params['project_name']}_completion_report.csv" - -CSV.open(File.join(File.expand_path(File.dirname(__FILE__)), report_filename), "wb") do |csv| - # header row - csv << ["druid", "label", "dc:title", "source_id", "accessioned", "shelved", "purl", "total_files", "files_found"] - - batch_druids.each do |batch| - query_tag = "id:\"" + batch.join('" OR id:"') + "\"" - resp = Dor::SearchService.query query_tag, :rows => n, :fl => 'id, public_dc_title_t, wf_wps_facet, source_id_t, objectLabel_t, content_file_t' - resp.docs.each { |doc| csv << Assembly::Utils.solr_doc_parser(doc, true) } - end - - puts "Report written to #{report_filename}" -end diff --git a/bin/correct_version b/bin/correct_version deleted file mode 100755 index 1c707160..00000000 --- a/bin/correct_version +++ /dev/null @@ -1,125 +0,0 @@ -#! /usr/bin/env ruby -require File.expand_path(File.dirname(__FILE__) + '/../config/boot') - -# Run with -# RAILS_ENV=test bin/remediate_version apo_1 apo_2 -# Don't include druid: -# At least one APO druid is needed -# When testing or debugging, use an APO with few children if possible, large harvests can take quite a significant amount of time - -# This script handles cases ther accessionWF lacks an entry for the current workflow in versionMetadata, but accession WF is only behind. It uses the following remediation procedure - -# This will fix errors such as: -# sdr-ingest-transfer : druid:bj072xp1435 - Item error; caused by # - -require 'rubygems' -require 'dor-services' -require 'dor-workflow-service' -require 'harvestdor' -require 'logger' - -# Set Up the Various Paths -current_path = File.dirname(File.expand_path(__FILE__)) -log_path = current_path.split("/bin")[0] + "/log/correct_version/#{Time.now.to_i}/" -@target_repo = "dor" -@target_workflow = "accessionWF" - -# Make Sure at least APO Druid was provided -abort("At least one APO druid is required.") if ARGV.size == 0 - -# Set up the Overall Run Log -FileUtils.mkdir_p(log_path) -@run_log = Logger.new(log_path + "run.log") -@no_action_log = Logger.new(log_path + "versions_match.log") -@no_ingest_error_log = Logger.new(log_path + "one_version_ahead_no_ingest_error.log") -@ingest_error_log = Logger.new(log_path + "two_versions_ahead_and_ingest_error.log") -@too_many_ahead_log = Logger.new(log_path + "too_many_versions_ahead.log") - -def correct_versioning_on_druid(druid) - begin - item = Dor::Item.find(druid) - rescue - @run_log.error("The object #{druid} was not found via Dor::Item.find(pid).") - return - end - - dor_version = item.current_version.to_i # gets current version - - begin - workflow_xml = Nokogiri.parse(Dor::Config.workflow.client.workflow_resource["dor/objects/#{druid}/workflows"].get) # get all the workflow xml as one chunk - rescue - run_log.error("Failed to get workflow XML for #{druid}") - @run_log.error $!.backtrace - return - end - - if workflow_xml.xpath("//workflow[@id='#{@target_workflow}']/process[@version='#{dor_version}']").size > 0 # Test to if we have the latest dor workflow - # If we have the latest worflow, we're good, at least for the purpose of this script - @no_action_log.info(druid) - - elsif workflow_xml.xpath("//workflow[@id='#{@target_workflow}']/process[@version='#{dor_version - 1}']").size > 0 - begin - item.initialize_workflow(@target_workflow) - @no_ingest_error_log.info(druid) - rescue - @run_log.error("Failed to initialize accessioning for #{druid}") - @run_log.error $!.backtrace - end - - elsif workflow_xml.xpath("//workflow[@id='#{@target_workflow}']/process[@version='#{dor_version - 2}']").size > 0 - errorNode = workflow_xml.xpath("//workflow[@id='#{@target_workflow}']/process[@status='error']").first - unless errorNode.nil? - # We need to delete the latest version metadata - vmd = item.datastreams['versionMetadata'].ng_xml - vmd.xpath("//versionMetadata/version[@versionId=#{dor_version}]").remove - item.datastreams['versionMetadata'].content = vmd.to_xml - item.datastreams['versionMetadata'].dirty = true - - begin - item.datastreams['versionMetadata'].save - rescue - @run_log.error("Failed to save workflow datastream for #{druid}") - @run_log.error $!.backtrace - end - - begin - Dor::Config.workflow.client.update_workflow_status(@target_repo, druid, @target_workflow, errorNode['name'], 'waiting') - @ingest_error_log.info(druid) - rescue - @run_log.error("DorWorkflowservices error for #{druid}") - @run_log.error $!.backtrace - end - - end - - else - # We're more than ahead, log this as a Case 3 error and handle it elsewhere - @too_many_ahead_log.info(druid) - end -end - -# TODO: Lots of stuff ripe for parallelization here -ARGV.each do |apo| - @run_log.info("Starting version fixes for #{apo}") - - # oais_returned = true - begin - client = Harvestdor::Client.new - oais = client.oai_headers(:set => "is_governed_by_#{apo}") - rescue - @run_log.error("#{apo} failed. Possibly an invalid druid.") - @run_log.error $!.backtrace - # oais_return = false - next # Skip to the next APO - end - - @run_log.info("#{oais.size} records returned for APO #{apo}") - oais.each do |oai| - # Get the Druid Out of the Identifier - tuple = oai.identifier.split(':') - druid = tuple[tuple.size - 1] # This will not have the druid: prefix - druid = ("druid:" + druid).strip # Add druid back on TODO: Could be regex and avoid these three steps - correct_versioning_on_druid(druid) - end - @run_log.info("Completed version fixes for #{apo}") -end diff --git a/bin/discovery_report b/bin/discovery_report deleted file mode 100755 index a5b0d78b..00000000 --- a/bin/discovery_report +++ /dev/null @@ -1,30 +0,0 @@ -#! /usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../config/boot') - -def help(error_msg) - abort "#{error_msg}\n\nUsage:\n discovery_report YAML_CONFIG_FILE [confirm_checksums check_sourceids no_check_reg show_staged show_other show_smpl_cm]\n" -end - -# Load YAML config file for the bundle of materials to be pre-assembled. -help "Incorrect N of arguments." if ARGV.size == 0 -yaml_config = ARGV[0] - -report_params = {} -report_params[:confirm_checksums] = ARGV.include? 'confirm_checksums' -report_params[:check_sourceids] = ARGV.include? 'check_sourceids' -report_params[:no_check_reg] = ARGV.include? 'no_check_reg' -report_params[:show_staged] = ARGV.include? 'show_staged' -report_params[:show_other] = ARGV.include? 'show_other' -report_params[:show_smpl_cm] = ARGV.include? 'show_smpl_cm' - -help "YAML file not found." unless File.file? yaml_config -params = YAML.load(File.read yaml_config) -params['config_filename'] = yaml_config - -begin - b = PreAssembly::Bundle.new(PreAssembly::BundleContext.new(params)) - b.discovery_report(report_params) -rescue PreAssembly::BundleUsageError => e - help e.message -end diff --git a/bin/get_total_objects b/bin/get_total_objects deleted file mode 100755 index 7d153890..00000000 --- a/bin/get_total_objects +++ /dev/null @@ -1,26 +0,0 @@ -#! /usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../config/boot') - -def help(error_msg) - abort "#{error_msg}\n\nUsage:\n get_total_objects YAML_CONFIG_FILE\n" -end - -# Load YAML config file for the bundle of materials to be pre-assembled. -help "Incorrect N of arguments." unless ARGV.size == 1 -yaml_config = ARGV.shift -help "YAML file not found." unless File.file? yaml_config -params = YAML.load(File.read yaml_config) -params['config_filename'] = yaml_config -params['show_progress'] = false - -# get total number of objects -begin - b = PreAssembly::Bundle.new(PreAssembly::BundleContext.new(params)) - b.discover_objects - total_objects = b.digital_objects.size - objects_remaining = b.objects_to_process.size - puts objects_remaining -rescue PreAssembly::BundleUsageError => e - help e.message -end diff --git a/bin/mods_report b/bin/mods_report deleted file mode 100755 index 772ba535..00000000 --- a/bin/mods_report +++ /dev/null @@ -1,54 +0,0 @@ -#! /usr/bin/env ruby - -# Used to test descriptive Metadata generation given a YAML file referencing a MODs template and a manifest. This allows you to test how the MODs will be generated during pre-assembly. -# Iterate through each row in the manifest, use source ID to lookup DRUID, generate new MODs using MODs template. - -# Peter Mangiafico -# January 21, 2014 -# -# Run with -# RAILS_ENV=test bin/mods_report YAML_CONFIG_FILE.yml OUTPUT_DIRECTORY -require File.expand_path(File.dirname(__FILE__) + '/../config/boot') - -def help(error_msg) - abort "#{error_msg}\n\nUsage:\n ./bin/mods_report YAML_CONFIG_FILE.yml OUTPUT_DIRECTORY\n" -end - -help "Incorrect N of arguments." if ARGV.size != 2 -yaml_config = ARGV.shift -help "YAML file not found." unless File.file? yaml_config -params = YAML.load(File.read yaml_config) -params['config_filename'] = yaml_config -output_directory = ARGV.shift -help "Output directory not found or not a directory." unless File.directory? output_directory - -mods_template_file = File.join(params['bundle_dir'], params['desc_md_template']) -manifest_file = File.join(params['bundle_dir'], params['manifest']) - -# read in MODs template -mods_template_xml = IO.read(mods_template_file) - -# read input manifest -@items = PreAssembly::Bundle.import_csv(manifest_file) -limit = params['limit_n'] - -puts "Generating #{@items.size} MODs files from #{manifest_file} using MODs template of #{mods_template_file}" -puts "limiting to #{limit}" unless limit.blank? - -@items.each_with_index do |manifest_row, x| - break if (!limit.blank? && x > limit) - druid = manifest_row[:druid] - sourceid = manifest_row[params['manifest_cols']['source_id']] - identifier = druid.blank? ? sourceid : druid # what we will call the filename, either by druid or sourceid depending on the project - druid = druid.blank? ? "druid:oo000oo0001" : druid # we need a druid to instantiate the object, use the real druid if possible, otherwise just make one up - dig_obj = PreAssembly::DigitalObject.new(:pid => druid) - dig_obj.manifest_row = manifest_row - dig_obj.desc_md_template_xml = mods_template_xml - if dig_obj.create_desc_metadata_xml - output_mods_file = File.join(output_directory, "#{identifier.gsub('druid:', '')}.xml") - File.open(output_mods_file, 'w') { |fh| fh.puts dig_obj.desc_md_xml } - puts "Saving MODs for sourceID #{identifier} [#{x} of #{@items.size}]" - else - puts "Error: cannot generate desc md xml for #{identifier} [#{x} of #{@items.size}]" - end -end diff --git a/bin/mods_report2 b/bin/mods_report2 deleted file mode 100755 index 254c6548..00000000 --- a/bin/mods_report2 +++ /dev/null @@ -1,48 +0,0 @@ -#! /usr/bin/env ruby - -# Used to test descriptive Metadata generation given a MODs template and a manifest. This allows you to test how the MODs will be generated during pre-assembly. -# Iterate through each row in the manifest, generate MODs files using MODs template in output directory. - -# Peter Mangiafico -# August 21, 2015 -# -# Run with -# RAILS_ENV=test bin/mods_report2 manifest.csv mods_template.xml output_directory -require File.expand_path(File.dirname(__FILE__) + '/../config/boot') - -def help(error_msg) - abort "#{error_msg}\n\nUsage:\n ./bin/mods_report2 manifest.csv mods_template.xml output_directory\n" -end - -help "Incorrect N of arguments." if ARGV.size != 3 -manifest_file = ARGV.shift -help "manifest file file not found." unless File.file? manifest_file -mods_template_file = ARGV.shift -help "manifest file file not found." unless File.file? mods_template_file -output_directory = ARGV.shift -help "Output directory not found or not a directory." unless File.directory? output_directory - -# read in MODs template -mods_template_xml = IO.read(mods_template_file) - -# read input manifest -@items = PreAssembly::Bundle.import_csv(manifest_file) - -puts "Generating #{@items.size} MODs files from #{manifest_file} using MODs template of #{mods_template_file}" - -@items.each_with_index do |manifest_row, x| - druid = manifest_row[:druid] - sourceid = manifest_row[:sourceid] - identifier = (druid.blank? ? (sourceid.blank? ? x : sourceid) : druid) # what we will call the filename, either by druid or sourceid depending on the project - druid = druid.blank? ? "druid:oo000oo0001" : druid # we need a druid to instantiate the object, use the real druid if possible, otherwise just make one up - dig_obj = PreAssembly::DigitalObject.new(:pid => druid) - dig_obj.manifest_row = manifest_row - dig_obj.desc_md_template_xml = mods_template_xml - if dig_obj.create_desc_metadata_xml - output_mods_file = File.join(output_directory, "#{identifier.gsub('druid:', '')}.xml") - File.open(output_mods_file, 'w') { |fh| fh.puts dig_obj.desc_md_xml } - puts "Saving MODs for sourceID #{identifier} [#{x} of #{@items.size}]" - else - puts "Error: cannot generate desc md xml for #{identifier} [#{x} of #{@items.size}]" - end -end diff --git a/bin/pre-assemble b/bin/pre-assemble deleted file mode 100755 index f4024b42..00000000 --- a/bin/pre-assemble +++ /dev/null @@ -1,36 +0,0 @@ -#! /usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../config/boot') - -require 'optparse' -options = {} - -OptionParser.new do |opts| - opts.banner = "Usage:\n pre-assemble YAML_CONFIG_FILE [--resume] [--limit 200]\n" - opts.on("-r", "--resume", "Resume") do |_r| - options[:resume] = true - end - opts.on("-l [LIMIT]", "--limit [LIMIT]", "Limit") do |l| - options[:limit] = l || 200 - end -end.parse! - -abort "Incorrect N of arguments - you did not supply a YAML file." unless ARGV.size == 1 - -# Load YAML config file for the bundle of materials to be pre-assembled. - -yaml_config = ARGV.shift -abort "YAML file not found." unless File.file? yaml_config - -params = YAML.load(File.read yaml_config) -params['resume'] = true if options[:resume] -params['limit_n'] = options[:limit].to_i if options[:limit] -params['config_filename'] = yaml_config - -# Run pre-assembly. -begin - b = PreAssembly::Bundle.new(PreAssembly::BundleContext.new(params)) - b.run_pre_assembly -rescue PreAssembly::BundleUsageError => e - abort e.message -end diff --git a/bin/project_tag_report b/bin/project_tag_report deleted file mode 100755 index 892c667c..00000000 --- a/bin/project_tag_report +++ /dev/null @@ -1,30 +0,0 @@ -#! /usr/bin/env ruby - -require File.expand_path(File.dirname(__FILE__) + '/../config/boot') - -def help(error_msg) - abort "#{error_msg}\n\nUsage:\n ./bin/project_tag_report PROJECT_TAG\n" -end - -help "Incorrect number of arguments." unless ARGV.size == 1 - -project_tag = ARGV.shift - -query_tag = "project_tag_facet:\"#{project_tag}\"" - -resp = Dor::SearchService.query query_tag, :rows => 50000, :fl => 'id, public_dc_title_t, wf_wps_facet, source_id_t, objectLabel_t, content_file_t' - -project_file_name = project_tag.gsub(' ', '_').gsub('"', '') - -help "no results found for project tag '#{project_tag}'" if resp.docs.size == 0 - -report_filename = "../log/#{project_file_name}_tag_report.csv" - -puts "Running report with #{resp.docs.size} objects" - -CSV.open(File.join(File.expand_path(File.dirname(__FILE__)), report_filename), "wb") do |csv| - # header row - csv << ["druid", "label", "dc:title", "source_id", "accessioned", "shelved", "purl", "total_files", "files_found"] - resp.docs.each { |doc| csv << Assembly::Utils.solr_doc_parser(doc) } - puts "Report written to #{report_filename}" -end diff --git a/bin/remediate b/bin/remediate deleted file mode 100755 index 1822e797..00000000 --- a/bin/remediate +++ /dev/null @@ -1,155 +0,0 @@ -#! /usr/bin/env ruby - -# This action is used to remediate objects in some way that you define. -# You supply a list of druids to remediate in a CSV file and a Ruby file defining a method that operates on the objects. -# The code handles all logging and versioning as needed. - -# Run with -# RAILS_ENV=production bin/remediate INPUT_FILE.csv REMEDIATE_LOGIC_FILENAME.rb [PAUSE_TIME_IN_SECONDS] - -# eg. RAILS_ENV=production bin/remediate /dor/preassembly/remediation/revs_all_pids.csv /dor/preassembly/remediation/scripts/revs_rights_remediate.rb - -# You can specify an optional number of seconds to pause between each object (in seconds) after the remediation logic filename. If left off, no -# pause between objects will occur. This can be useful for large remediation jobs that are a low priority, which allows them to run at a slower pace -# and thus generating less concurrent load on the system while other higher priority jobs are running concurrently. -# You can also add in optional parameters to override defaults for checking if items are in accessioning or if they require versioning and set to false. -# Only do this if you are sure you know what you are doing for scripts that for some reason will not work with versioning! If you want to add these -# parameters, you must also specify the pause time (which could be 0). - -# RAILS_ENV=production bin/remediate INPUT_FILE.csv REMEDIATE_LOGIC_FILENAME.rb [PAUSE_TIME_IN_SECONDS] ignore_versioning ignore_accessioning - -# INPUT_FILE can be either a pre-assembly generated YAML log file or a CSV file with one column containing at least a list of druids -# If a pre-assembly YAML log file is passed in, the successfully accessioned druids will be used. -# For a CSV file, there should be a header with a column labeled "druid" which indicates which column contains the druid -# This file should be in a location where the script has read/write access to it. - -# e.g. -# druid,another_column -# druid:oo000oo0001,other stuff -# druid:oo000oo0002,ignored - -# REMEDIATE_LOGIC_FILENAME is a reference to a Ruby code file that defines what you want the remediation to do. An example of this -# file is in lib/remediation/remediate_project_example.rb Copy that file, and edit it somewhere the script can read it and then pass -# the filename to the script. - -# The result will be some screen output, a detailed .YML file in the same location and with the same name as the input CSV file. -# The input CSV file will be updated with two additional columns - a status indicating if remediation succeeded and a message. -# You can re-run remediation with the same CSV file and it will automatically skip already completed objects. - -# Note that unless your laptop has access to the Fedora instance you need to remediate (usually Production), -# you should probably run this from lyberservices-prod to have access to all mounts and configuration. - -require File.expand_path(File.dirname(__FILE__) + '/../config/boot') -require 'rubygems' -require 'csv' -require 'csv-mapper' - -def help(error_msg) - abort "#{error_msg}\n\nUsage:\n RAILS_ENV=XXXXX remediate INPUT_FILE REMEDIATE_LOGIC_FILENAME [PAUSE_TIME_SECONDS]\n" -end - -help "Incorrect N of arguments." if ARGV.size < 2 -input_file = ARGV[0] -remediate_logic_file = ARGV[1] -if ARGV.size > 2 - pause_time = ARGV[2].to_i -else - pause_time = 0 -end - -ignore_accessioning = true if ARGV.include? 'ignore_accessioning' # override config file if supplied -ignore_versioning = true if ARGV.include? 'ignore_versioning' # override config file if supplied - -help "Input file not found." unless File.file?(input_file) -help "REMEDIATE_LOGIC_FILE file not found." unless File.file?(remediate_logic_file) - -require remediate_logic_file - -if ignore_accessioning - puts "*** OVERRIDING CONFIG: Ignoring accessioning check" - Dor::Config.remediation.check_for_in_accessioning = false -end -if ignore_versioning - puts "*** OVERRIDING CONFIG: Ignoring versioning check" - Dor::Config.remediation.check_for_versioning_required = false -end - -source_path = File.dirname(input_file) -source_ext = File.extname(input_file) -source_name = File.basename(input_file, source_ext) - -help "Input file not a CSV or YAML/YML file." unless ['.csv', '.yml', '.yaml'].include? source_ext.downcase - -progress_log_file = File.join(source_path, source_name + '_log.yml') -csv_out = File.join(source_path, source_name + "_log.csv") - -# read in completed druids so we don't reprocess them -completed_druids = PreAssembly::Remediation::Item.get_druids(progress_log_file) - -# read input druids -if source_ext.downcase == '.csv' # read from CSV file - rows = CsvMapper.import(input_file) { read_attributes_from_file } - druids = rows.collect { |row| row.druid.include?("druid:") ? row.druid : "druid:#{row.druid}" } # add the druid prefix if missing from input file -else # this must be a YAML progress log file - druids = Assembly::Utils.get_druids_from_log(input_file, true) -end - -total_druids = druids.size -total_completed = completed_druids.size -total_to_process = total_druids - total_completed - -puts "Input file: #{input_file}" -puts "Found #{total_to_process} to remediate. Total in file: #{total_druids}. Already completed: #{total_completed}" -puts "Pausing #{pause_time} seconds between objects" if pause_time > 0 -puts "Started at #{Time.now}" -puts "" -$stdout.flush - -start_time = Time.now -total_success = 0 -total_failure = 0 -count = 0 -avg_time_per_object = 0 -total_time_remaining = 0 - -druids.each do |druid| - done = completed_druids.include?(druid) - unless done - count += 1 - item = PreAssembly::Remediation::Item.new(druid) - item.description = File.basename(remediate_logic_file) # added to the version description - item.extend(RemediationLogic) # add in our project specific methods - success = item.remediate - if success - total_success += 1 - result = "success" - else - result = "FAILURE" - total_failure += 1 - end - total_time = Time.now - start_time - - sleep pause_time if pause_time > 0 - - remaining_to_process = total_to_process - count - avg_time_per_object = total_time / count - total_time_remaining = (avg_time_per_object * remaining_to_process).floor - - status = "#{druid} : #{result} : #{count} of #{total_to_process} (#{remaining_to_process} remaining) : #{Time.now} : ~#{PreAssembly::Logging.seconds_to_string(total_time_remaining)} left" - item.log_to_progress_file(progress_log_file) - item.log_to_csv(csv_out) - puts status - $stdout.flush - end -end - -end_time = Time.now -total_time = ((end_time - start_time) / 1.hour).round(2) - -puts "" -puts "Input file: #{input_file}" -puts "Output file: #{csv_out}" -puts "Ended at #{end_time}. Total time: #{total_time} hours. Average time per object: #{(total_time * 3600 / total_to_process).round(2)} seconds (includes any pause time). Pause time: #{pause_time} seconds" -puts "Total in file: #{total_druids}. Total processed: #{total_to_process}. Successful: #{total_success}. Completed previously: #{total_completed}. Failed: #{total_failure}" - -$stdout.flush From 81125dbe7dad310e81915e56a61e213a7a0e2435 Mon Sep 17 00:00:00 2001 From: Sarav Shah Date: Mon, 27 Aug 2018 15:31:28 -0700 Subject: [PATCH 02/10] Add gems and update Rakefile --- Gemfile | 3 ++- Gemfile.lock | 37 ++++++++++++++++++++++++---- Rakefile | 68 +++------------------------------------------------- 3 files changed, 38 insertions(+), 70 deletions(-) diff --git a/Gemfile b/Gemfile index 018b727f..f5604bc9 100644 --- a/Gemfile +++ b/Gemfile @@ -30,9 +30,9 @@ gem 'turbolinks' gem 'resque', '~> 1.27' gem 'resque-lock' gem 'resque-pool' +gem 'config' group :test do - gem 'rspec', '~> 3.0' gem 'yard' gem 'solr_wrapper' gem 'jettywrapper' @@ -51,6 +51,7 @@ group :development do end group :development, :test do + gem 'rspec-rails' gem 'byebug' gem 'rspec-rails', '~> 3.7' gem 'rubocop', '~> 0.58' diff --git a/Gemfile.lock b/Gemfile.lock index 38188329..5a69a2c4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -97,6 +97,10 @@ GEM childprocess (0.9.0) ffi (~> 1.0, >= 1.0.11) concurrent-ruby (1.0.5) + config (1.7.0) + activesupport (>= 3.0) + deep_merge (~> 1.2.1) + dry-validation (>= 0.10.4) confstruct (0.2.7) connection_pool (2.2.2) coveralls (0.8.22) @@ -109,6 +113,7 @@ GEM csv-mapper (0.5.1) fastercsv daemons (1.2.6) + deep_merge (1.2.1) deprecation (0.99.0) activesupport diff-lcs (1.3) @@ -155,6 +160,33 @@ GEM nokogiri (~> 1.6) retries druid-tools (1.0.0) + dry-configurable (0.7.0) + concurrent-ruby (~> 1.0) + dry-container (0.6.0) + concurrent-ruby (~> 1.0) + dry-configurable (~> 0.1, >= 0.1.3) + dry-core (0.4.7) + concurrent-ruby (~> 1.0) + dry-equalizer (0.2.1) + dry-inflector (0.1.2) + dry-logic (0.4.2) + dry-container (~> 0.2, >= 0.2.6) + dry-core (~> 0.2) + dry-equalizer (~> 0.2) + dry-types (0.13.2) + concurrent-ruby (~> 1.0) + dry-container (~> 0.3) + dry-core (~> 0.4, >= 0.4.4) + dry-equalizer (~> 0.2) + dry-inflector (~> 0.1, >= 0.1.2) + dry-logic (~> 0.4, >= 0.4.2) + dry-validation (0.12.1) + concurrent-ruby (~> 1.0) + dry-configurable (~> 0.1, >= 0.1.3) + dry-core (~> 0.2, >= 0.2.1) + dry-equalizer (~> 0.2) + dry-logic (~> 0.4, >= 0.4.0) + dry-types (~> 0.13.1) edtf (3.0.4) activesupport (>= 3.0, < 6.0) equivalent-xml (0.6.0) @@ -336,10 +368,6 @@ GEM rsolr (2.2.1) builder (>= 2.1.2) faraday (>= 0.9.0) - rspec (3.8.0) - rspec-core (~> 3.8.0) - rspec-expectations (~> 3.8.0) - rspec-mocks (~> 3.8.0) rspec-core (3.8.0) rspec-support (~> 3.8.0) rspec-expectations (3.8.1) @@ -459,6 +487,7 @@ DEPENDENCIES capistrano (~> 3) capistrano-bundler capistrano-rvm + config coveralls csv-mapper dlss-capistrano (~> 3.1) diff --git a/Rakefile b/Rakefile index f6b70272..e85f9139 100644 --- a/Rakefile +++ b/Rakefile @@ -1,68 +1,6 @@ -require_relative 'config/application' -require 'rspec/core/rake_task' +# Add your own tasks in files placed in lib/tasks ending in .rake, +# for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. -begin - Bundler.setup(:default, :development) -rescue Bundler::BundlerError => e - $stderr.puts e.message - $stderr.puts "Run `bundle install` to install missing gems" - exit e.status_code -end +require_relative 'config/application' Rails.application.load_tasks - -Dir.glob('lib/tasks/*.rake').each { |r| import r } - -desc "Run specs" -RSpec::Core::RakeTask.new(:spec) - -task :default => :spec - -if ['test', 'development'].include? ENV['RAILS_ENV'] - require 'jettywrapper' - Jettywrapper.hydra_jetty_version = 'v7.3.0' # this keeps us on fedora 3, hydra-jetty v8.x moves to fedora 4. - - def load_order_files(fedora_files) - data_path = File.expand_path('../fedora_conf/data/', __FILE__) - fedora_files.delete_if { |f| f.strip.empty? } - fedora_files.map { |f| File.join(data_path, f.strip) } - end - - namespace :repo do - desc "Load XML file(s) into repo (fedora and solr), default: contents of 'load_order' file. With a glob: rake repo:load[fedora_conf/data/*.xml]" - task :load, [:glob] do |_task, args| - require 'active_fedora' - puts "travis_fold:start:repo-load\r" if ENV['TRAVIS'] == 'true' - - file_list = [] - if args.key?(:glob) - file_list = Dir.glob(args[:glob]) - else - puts 'No file glob was specified so file order and inclusion is determined by the load_order file' - fedora_files = File.foreach(File.join(File.expand_path('../fedora_conf/data/', __FILE__), 'load_order')).to_a - - file_list = load_order_files(fedora_files) - end - - errors = [] - i = 0 - - file_list.each do |file| - i += 1 - - handler = proc do |e, _attempt_number, _total_delay| - puts STDERR.puts "ERROR loading #{file}:\n#{e.message}\n#{e.backtrace.join "\n"}" - errors << file - end - with_retries(:max_tries => 3, :handler => handler, :rescue => [StandardError]) { |attempt| - puts "** File #{i}, Try #{attempt} ** repo:load foxml=#{file}" - pid = ActiveFedora::FixtureLoader.import_to_fedora(file) - ActiveFedora::FixtureLoader.index(pid) - } - end - puts 'Done loading repo files' - puts "ERROR in #{errors.size()} of #{i} files" if errors.size() > 0 - puts "travis_fold:end:repo-load\r" if ENV['TRAVIS'] == 'true' - end - end # :repo -end From 621427029e6c56bbdf150dea527061c315f5ffd7 Mon Sep 17 00:00:00 2001 From: Sarav Shah Date: Mon, 27 Aug 2018 15:31:48 -0700 Subject: [PATCH 03/10] Set up config/ in a more rails way --- .gitignore | 4 ++ config/application.rb | 5 ++- config/boot.rb | 7 ++- config/environments/development.rb | 27 ++++++++++- config/environments/production.rb | 2 +- config/environments/test.rb | 15 ++++++- config/initializers/config.rb | 50 +++++++++++++++++++++ config/initializers/dor_workflow_service.rb | 5 +++ config/settings.yml | 1 + config/settings/development.yml | 0 config/settings/production.yml | 0 config/settings/test.yml | 0 12 files changed, 109 insertions(+), 7 deletions(-) create mode 100644 config/initializers/config.rb create mode 100644 config/initializers/dor_workflow_service.rb create mode 100644 config/settings.yml create mode 100644 config/settings/development.yml create mode 100644 config/settings/production.yml create mode 100644 config/settings/test.yml diff --git a/.gitignore b/.gitignore index 07968053..937de7c7 100644 --- a/.gitignore +++ b/.gitignore @@ -23,3 +23,7 @@ coverage # Ignore master key for decrypting credentials and more. /config/master.key + +config/settings.local.yml +config/settings/*.local.yml +config/environments/*.local.yml diff --git a/config/application.rb b/config/application.rb index b8d6643f..0e98a378 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,10 +1,13 @@ require_relative 'boot' require 'rails/all' - +require 'assembly-utils' # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) +def noko_doc(x) + Nokogiri.XML(x) { |conf| conf.default_xml.noblanks } +end module PreAssembly class Application < Rails::Application diff --git a/config/boot.rb b/config/boot.rb index f54a4e85..95ac963d 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,3 +1,7 @@ +ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) + +require 'bundler/setup' # Set up gems listed in the Gemfile. + require 'rubygems' require 'bundler/setup' require 'logger' @@ -13,7 +17,6 @@ # ENV_FILE = PRE_ASSEMBLY_ROOT + "/config/cli_environments/#{environment}.rb" require_relative "cli_environments/#{environment}.rb" Dor::Config.dor_services.url ||= Dor::Config.dor.service_root -Dor::Config.workflow.client.configure(Dor::Config.workflow.url, :dor_services_url => Dor::Config.dor_services.url.gsub('/v1', '')) # Project dir in load path. $LOAD_PATH.unshift(PRE_ASSEMBLY_ROOT + '/lib') @@ -23,4 +26,4 @@ PreAssembly::Logging.setup PRE_ASSEMBLY_ROOT, environment # Load the project and its dependencies. -require 'pre_assembly' +require 'pre_assembly' \ No newline at end of file diff --git a/config/environments/development.rb b/config/environments/development.rb index 1519dca4..1311e3e4 100644 --- a/config/environments/development.rb +++ b/config/environments/development.rb @@ -13,12 +13,13 @@ config.consider_all_requests_local = true # Enable/disable caching. By default caching is disabled. - if Rails.root.join('tmp/caching-dev.txt').exist? + # Run rails dev:cache to toggle caching. + if Rails.root.join('tmp', 'caching-dev.txt').exist? config.action_controller.perform_caching = true config.cache_store = :memory_store config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{2.days.seconds.to_i}" + 'Cache-Control' => "public, max-age=#{2.days.to_i}" } else config.action_controller.perform_caching = false @@ -26,12 +27,34 @@ config.cache_store = :null_store end + # Store uploaded files on the local file system (see config/storage.yml for options) + config.active_storage.service = :local + + # Don't care if the mailer can't send. + config.action_mailer.raise_delivery_errors = false + + config.action_mailer.perform_caching = false + # Print deprecation notices to the Rails logger. config.active_support.deprecation = :log # Raise an error on page load if there are pending migrations. config.active_record.migration_error = :page_load + # Highlight code that triggered database queries in logs. + config.active_record.verbose_query_logs = true + + # Debug mode disables concatenation and preprocessing of assets. + # This option may cause significant delays in view rendering with a large + # number of complex assets. + config.assets.debug = true + + # Suppress logger output for asset requests. + config.assets.quiet = true + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true + # Use an evented file watcher to asynchronously detect changes in source code, # routes, locales, etc. This feature depends on the listen gem. config.file_watcher = ActiveSupport::EventedFileUpdateChecker diff --git a/config/environments/production.rb b/config/environments/production.rb index 5f7a71c3..40055ee7 100644 --- a/config/environments/production.rb +++ b/config/environments/production.rb @@ -54,7 +54,7 @@ config.log_level = :debug # Prepend all log lines with the following tags. - config.log_tags = [:request_id] + config.log_tags = [ :request_id ] # Use a different cache store in production. # config.cache_store = :mem_cache_store diff --git a/config/environments/test.rb b/config/environments/test.rb index 841ba3e2..0a38fd3c 100644 --- a/config/environments/test.rb +++ b/config/environments/test.rb @@ -15,7 +15,7 @@ # Configure public file server for tests with Cache-Control for performance. config.public_file_server.enabled = true config.public_file_server.headers = { - 'Cache-Control' => "public, max-age=#{1.hour.seconds.to_i}" + 'Cache-Control' => "public, max-age=#{1.hour.to_i}" } # Show full error reports and disable caching. @@ -28,6 +28,19 @@ # Disable request forgery protection in test environment. config.action_controller.allow_forgery_protection = false + # Store uploaded files on the local file system in a temporary directory + config.active_storage.service = :test + + config.action_mailer.perform_caching = false + + # Tell Action Mailer not to deliver emails to the real world. + # The :test delivery method accumulates sent emails in the + # ActionMailer::Base.deliveries array. + config.action_mailer.delivery_method = :test + # Print deprecation notices to the stderr. config.active_support.deprecation = :stderr + + # Raises error for missing translations + # config.action_view.raise_on_missing_translations = true end diff --git a/config/initializers/config.rb b/config/initializers/config.rb new file mode 100644 index 00000000..776c6b51 --- /dev/null +++ b/config/initializers/config.rb @@ -0,0 +1,50 @@ +Config.setup do |config| + # Name of the constant exposing loaded settings + config.const_name = 'Settings' + + # Ability to remove elements of the array set in earlier loaded settings file. For example value: '--'. + # + # config.knockout_prefix = nil + + # Overwrite an existing value when merging a `nil` value. + # When set to `false`, the existing value is retained after merge. + # + # config.merge_nil_values = true + + # Overwrite arrays found in previously loaded settings file. When set to `false`, arrays will be merged. + # + # config.overwrite_arrays = true + + # Load environment variables from the `ENV` object and override any settings defined in files. + # + # config.use_env = false + + # Define ENV variable prefix deciding which variables to load into config. + # + # config.env_prefix = 'Settings' + + # What string to use as level separator for settings loaded from ENV variables. Default value of '.' works well + # with Heroku, but you might want to change it for example for '__' to easy override settings from command line, where + # using dots in variable names might not be allowed (eg. Bash). + # + # config.env_separator = '.' + + # Ability to process variables names: + # * nil - no change + # * :downcase - convert to lower case + # + # config.env_converter = :downcase + + # Parse numeric values as integers instead of strings. + # + # config.env_parse_values = true + + # Validate presence and type of specific config values. Check https://github.com/dry-rb/dry-validation for details. + # + # config.schema do + # required(:name).filled + # required(:age).maybe(:int?) + # required(:email).filled(format?: EMAIL_REGEX) + # end + +end diff --git a/config/initializers/dor_workflow_service.rb b/config/initializers/dor_workflow_service.rb new file mode 100644 index 00000000..58c7264a --- /dev/null +++ b/config/initializers/dor_workflow_service.rb @@ -0,0 +1,5 @@ +require 'dor-workflow-service' +Dor::WorkflowService.configure( + Settings.workflow_services_url, + :dor_services_url => Dor::Config.dor_services.url.gsub('/v1', '') +) diff --git a/config/settings.yml b/config/settings.yml new file mode 100644 index 00000000..f6e3f046 --- /dev/null +++ b/config/settings.yml @@ -0,0 +1 @@ +workflow_services_url: 'https://workflows.example.org/workflow/' diff --git a/config/settings/development.yml b/config/settings/development.yml new file mode 100644 index 00000000..e69de29b diff --git a/config/settings/production.yml b/config/settings/production.yml new file mode 100644 index 00000000..e69de29b diff --git a/config/settings/test.yml b/config/settings/test.yml new file mode 100644 index 00000000..e69de29b From 8a85f75228189b11238eff7490dd1d8289630c4d Mon Sep 17 00:00:00 2001 From: Sarav Shah Date: Mon, 27 Aug 2018 15:32:48 -0700 Subject: [PATCH 04/10] Move specs/ into nested folders and use rails_helper remove require rails_helper from spec/ --- .rspec | 2 +- spec/{ => lib/pre_assembly}/bundle_spec.rb | 17 ++-- .../pre_assembly}/digital_object_spec.rb | 2 - .../pre_assembly}/druid_minter_spec.rb | 2 - .../pre_assembly}/object_file_spec.rb | 2 - .../remediation}/remediate_spec.rb | 4 +- .../smpl_project_specific_spec.rb | 2 - .../test_data/logging/progress_log_file.yml | 15 ++++ spec/rails_helper.rb | 3 +- spec/spec_helper.rb | 79 +++++++++++++++---- 10 files changed, 91 insertions(+), 37 deletions(-) rename spec/{ => lib/pre_assembly}/bundle_spec.rb (98%) rename spec/{ => lib/pre_assembly}/digital_object_spec.rb (99%) rename spec/{ => lib/pre_assembly}/druid_minter_spec.rb (93%) rename spec/{ => lib/pre_assembly}/object_file_spec.rb (92%) rename spec/{ => lib/pre_assembly/remediation}/remediate_spec.rb (91%) rename spec/{ => lib/pre_assembly}/smpl_project_specific_spec.rb (99%) create mode 100644 spec/lib/test_data/logging/progress_log_file.yml diff --git a/.rspec b/.rspec index 83e16f80..0f30adeb 100644 --- a/.rspec +++ b/.rspec @@ -1,2 +1,2 @@ --color ---require spec_helper +--require rails_helper diff --git a/spec/bundle_spec.rb b/spec/lib/pre_assembly/bundle_spec.rb similarity index 98% rename from spec/bundle_spec.rb rename to spec/lib/pre_assembly/bundle_spec.rb index d0f38bc7..cf647077 100644 --- a/spec/bundle_spec.rb +++ b/spec/lib/pre_assembly/bundle_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe PreAssembly::Bundle do let(:md5_regex) { /^[0-9a-f]{32}$/ } # TODO: break out tests about BundleContext into separate spec file @@ -50,10 +48,9 @@ def bundle_setup(bundle_context) end describe '#load_skippables' do - it "does nothing if resume returns false" do - allow(rumsey).to receive(:resume).and_return(false) - expect(rumsey).not_to receive(:read_progress_log) - rumsey.load_skippables + it "does nothing if @resume is false" do + rumsey.resume = false + expect(rumsey.load_skippables).to be_nil end it "returns expected hash of skippable items" do @@ -306,7 +303,7 @@ def bundle_setup(bundle_context) end it "new_object_file() should return an ObjectFile with expected path values" do - allow(revs).to receive(:exclude_from_path).and_return(false) + allow(revs).to receive(:exclude_from_content).and_return(false) tests = [ # Stageable is a file: # - immediately in bundle dir. @@ -465,8 +462,10 @@ def bundle_setup(bundle_context) describe '#manifest_rows' do it "loads the manifest CSV only once, during the validation phase, and return all three rows even if you access the manifest multiple times" do - expect(revs).not_to receive(:load_manifest_rows_from_csv) - 3.times { revs.manifest_rows.size == 3 } + expect(revs.manifest_rows.size).to eq 3 + expect(revs).not_to receive(:object_discovery) + revs.manifest_rows + end it "returns empty array for bundles that do not use a manifest" do diff --git a/spec/digital_object_spec.rb b/spec/lib/pre_assembly/digital_object_spec.rb similarity index 99% rename from spec/digital_object_spec.rb rename to spec/lib/pre_assembly/digital_object_spec.rb index f4ebf05e..071b64a8 100644 --- a/spec/digital_object_spec.rb +++ b/spec/lib/pre_assembly/digital_object_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe PreAssembly::DigitalObject do let(:dru) { 'gn330dv6119' } let(:pid) { "druid:#{dru}" } diff --git a/spec/druid_minter_spec.rb b/spec/lib/pre_assembly/druid_minter_spec.rb similarity index 93% rename from spec/druid_minter_spec.rb rename to spec/lib/pre_assembly/druid_minter_spec.rb index dfb4824f..7f6c3b05 100644 --- a/spec/druid_minter_spec.rb +++ b/spec/lib/pre_assembly/druid_minter_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe PreAssembly::DruidMinter do it "gets a sequence of druids from calls to next()" do exp = described_class.current diff --git a/spec/object_file_spec.rb b/spec/lib/pre_assembly/object_file_spec.rb similarity index 92% rename from spec/object_file_spec.rb rename to spec/lib/pre_assembly/object_file_spec.rb index 03daf588..18f990cd 100644 --- a/spec/object_file_spec.rb +++ b/spec/lib/pre_assembly/object_file_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe PreAssembly::ObjectFile do before do @f = described_class.new( diff --git a/spec/remediate_spec.rb b/spec/lib/pre_assembly/remediation/remediate_spec.rb similarity index 91% rename from spec/remediate_spec.rb rename to spec/lib/pre_assembly/remediation/remediate_spec.rb index 4daeeb6a..b0b132ca 100644 --- a/spec/remediate_spec.rb +++ b/spec/lib/pre_assembly/remediation/remediate_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe PreAssembly::Remediation::Item do let(:pid) { 'druid:cs575bk5522' } let(:item) { described_class.new(pid) } @@ -11,7 +9,7 @@ end context 'logging' do - let(:log_dir) { File.dirname(__FILE__) + "/test_data/logging" } + let(:log_dir) { File.join(File.dirname(__FILE__), "../../test_data/logging") } let(:csv_filename) { log_dir + "/csv_log.csv" } let(:progress_log_file) { log_dir + "/progress_log_file.yml" } diff --git a/spec/smpl_project_specific_spec.rb b/spec/lib/pre_assembly/smpl_project_specific_spec.rb similarity index 99% rename from spec/smpl_project_specific_spec.rb rename to spec/lib/pre_assembly/smpl_project_specific_spec.rb index ebbd9c73..8da682b0 100644 --- a/spec/smpl_project_specific_spec.rb +++ b/spec/lib/pre_assembly/smpl_project_specific_spec.rb @@ -1,5 +1,3 @@ -require 'spec_helper' - describe PreAssembly::DigitalObject do let(:bundle_dir) { File.join(PRE_ASSEMBLY_ROOT, 'spec/test_data/bundle_input_e') } diff --git a/spec/lib/test_data/logging/progress_log_file.yml b/spec/lib/test_data/logging/progress_log_file.yml new file mode 100644 index 00000000..f1246de0 --- /dev/null +++ b/spec/lib/test_data/logging/progress_log_file.yml @@ -0,0 +1,15 @@ +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-27 15:09:13.779278000 -07:00 +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-27 15:10:55.044887000 -07:00 +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-27 16:11:03.600040000 -07:00 diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 4c853b8c..7413a13c 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -4,7 +4,6 @@ require File.expand_path('../config/environment', __dir__) # Prevent database truncation if the environment is production abort("The Rails environment is running in production mode!") if Rails.env.production? - require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! @@ -22,7 +21,7 @@ # If you're not using ActiveRecord, or you'd prefer not to run each of your # examples within a transaction, remove the following line or assign false # instead of true. - config.use_transactional_fixtures = true + # config.use_transactional_fixtures = true # RSpec Rails can automatically mix in different behaviours to your tests # based on their file location, for example enabling you to call `get` and diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 86e4782a..45bd3f30 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,21 +1,72 @@ require 'tmpdir' require 'equivalent-xml/rspec_matchers' require 'byebug' -require 'simplecov' -require 'coveralls' -SimpleCov.formatter = Coveralls::SimpleCov::Formatter -SimpleCov.start do - track_files "bin/**/*" -end -ENV['RAILS_ENV'] ||= "test" -puts "running in #{ENV['RAILS_ENV']} mode" -bootfile = File.expand_path(File.dirname(__FILE__) + '/../config/boot') -require bootfile -tmp_output_dir = File.join(PRE_ASSEMBLY_ROOT, 'tmp') -FileUtils.mkdir_p tmp_output_dir +RSpec.configure do |config| + + # rspec-expectations config goes here. You can use an alternate + # assertion/expectation library such as wrong or the stdlib/minitest + # assertions if you prefer. + config.expect_with :rspec do |expectations| + # This option will default to `true` in RSpec 4. It makes the `description` + # and `failure_message` of custom matchers include text for helper methods + # defined using `chain`, e.g.: + # be_bigger_than(2).and_smaller_than(4).description + # # => "be bigger than 2 and smaller than 4" + # ...rather than: + # # => "be bigger than 2" + expectations.include_chain_clauses_in_custom_matcher_descriptions = true + end + + config.mock_with :rspec do |mocks| + # Prevents you from mocking or stubbing a method that does not exist on a real object. + # This is generally recommended, and will default to `true` in RSpec 4. + mocks.verify_partial_doubles = true + end + + # This option will default to `:apply_to_host_groups` in RSpec 4 (and will + # have no way to turn it off -- the option exists only for backwards + # compatibility in RSpec 3). It causes shared context metadata to be + # inherited by the metadata hash of host groups and examples, rather than + # triggering implicit auto-inclusion in groups with matching metadata. + config.shared_context_metadata_behavior = :apply_to_host_groups + +# The settings below are suggested to provide a good initial experience +# with RSpec, but feel free to customize to your heart's content. +=begin + # This allows you to limit a spec run to individual examples or groups + # you care about by tagging them with `:focus` metadata. When nothing + # is tagged with `:focus`, all examples get run. RSpec also provides + # aliases for `it`, `describe`, and `context` that include `:focus` + # metadata: `fit`, `fdescribe` and `fcontext`, respectively. + config.filter_run_when_matching :focus + + # Allows RSpec to persist some state between runs in order to support + # the `--only-failures` and `--next-failure` CLI options. We recommend + # you configure your source control system to ignore this file. + config.example_status_persistence_file_path = "spec/examples.txt" + + # Limits the available syntax to the non-monkey patched syntax that is + # recommended. For more details, see: + # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/ + # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/ + # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode + config.disable_monkey_patching! + + # Many RSpec users commonly either run the entire suite or an individual + # file, and it's useful to allow more verbose output when running an + # individual spec file. + if config.files_to_run.one? + # Use the documentation formatter for detailed output, + # unless a formatter has already been configured + # (e.g. via a command-line flag). + config.default_formatter = "doc" + end -def noko_doc(x) - Nokogiri.XML(x) { |conf| conf.default_xml.noblanks } + # Print the 10 slowest examples and example groups at the + # end of the spec run, to help surface which specs are running + # particularly slow. + config.profile_examples = 10 +=end end From 2a1c5f84ade8f013e6356e0d21c982e25da4c7d0 Mon Sep 17 00:00:00 2001 From: Sarav Shah Date: Mon, 27 Aug 2018 15:33:00 -0700 Subject: [PATCH 05/10] Add a schema for rails --- db/schema.rb | 15 +++++++++++++++ 1 file changed, 15 insertions(+) create mode 100644 db/schema.rb diff --git a/db/schema.rb b/db/schema.rb new file mode 100644 index 00000000..52ab025e --- /dev/null +++ b/db/schema.rb @@ -0,0 +1,15 @@ +# This file is auto-generated from the current state of the database. Instead +# of editing this file, please use the migrations feature of Active Record to +# incrementally modify your database, and then regenerate this schema definition. +# +# Note that this schema.rb definition is the authoritative source for your +# database schema. If you need to create the application database on another +# system, you should be using db:schema:load, not running all the migrations +# from scratch. The latter is a flawed and unsustainable approach (the more migrations +# you'll amass, the slower it'll run and the greater likelihood for issues). +# +# It's strongly recommended that you check this file into your version control system. + +ActiveRecord::Schema.define(version: 0) do + +end From b2c989e106b76d43d7ef2e635109aaa0a4258ab3 Mon Sep 17 00:00:00 2001 From: Sarav Shah Date: Mon, 27 Aug 2018 16:46:36 -0700 Subject: [PATCH 06/10] move lib to app/lib --- {lib => app/lib}/pre_assembly.rb | 0 {lib => app/lib}/pre_assembly/bundle.rb | 0 {lib => app/lib}/pre_assembly/digital_object.rb | 0 {lib => app/lib}/pre_assembly/druid_minter.rb | 0 {lib => app/lib}/pre_assembly/logging.rb | 0 {lib => app/lib}/pre_assembly/object_file.rb | 0 {lib => app/lib}/pre_assembly/project/README.txt | 0 {lib => app/lib}/pre_assembly/project/salt.rb | 0 {lib => app/lib}/pre_assembly/project/smpl.rb | 0 .../remediate.rb => app/lib/pre_assembly/remediation/item.rb | 0 .../lib}/pre_assembly/remediation/remediate_project_example.rb | 0 {lib => app/lib}/pre_assembly/reporting.rb | 0 {lib => app/lib}/pre_assembly/smpl_precontent_metadata.rb | 0 lib/assets/.keep | 0 lib/tasks/.keep | 0 .../pre_assembly/remediation/{remediate_spec.rb => item_spec.rb} | 0 16 files changed, 0 insertions(+), 0 deletions(-) rename {lib => app/lib}/pre_assembly.rb (100%) rename {lib => app/lib}/pre_assembly/bundle.rb (100%) rename {lib => app/lib}/pre_assembly/digital_object.rb (100%) rename {lib => app/lib}/pre_assembly/druid_minter.rb (100%) rename {lib => app/lib}/pre_assembly/logging.rb (100%) rename {lib => app/lib}/pre_assembly/object_file.rb (100%) rename {lib => app/lib}/pre_assembly/project/README.txt (100%) rename {lib => app/lib}/pre_assembly/project/salt.rb (100%) rename {lib => app/lib}/pre_assembly/project/smpl.rb (100%) rename lib/pre_assembly/remediation/remediate.rb => app/lib/pre_assembly/remediation/item.rb (100%) rename {lib => app/lib}/pre_assembly/remediation/remediate_project_example.rb (100%) rename {lib => app/lib}/pre_assembly/reporting.rb (100%) rename {lib => app/lib}/pre_assembly/smpl_precontent_metadata.rb (100%) delete mode 100644 lib/assets/.keep delete mode 100644 lib/tasks/.keep rename spec/lib/pre_assembly/remediation/{remediate_spec.rb => item_spec.rb} (100%) diff --git a/lib/pre_assembly.rb b/app/lib/pre_assembly.rb similarity index 100% rename from lib/pre_assembly.rb rename to app/lib/pre_assembly.rb diff --git a/lib/pre_assembly/bundle.rb b/app/lib/pre_assembly/bundle.rb similarity index 100% rename from lib/pre_assembly/bundle.rb rename to app/lib/pre_assembly/bundle.rb diff --git a/lib/pre_assembly/digital_object.rb b/app/lib/pre_assembly/digital_object.rb similarity index 100% rename from lib/pre_assembly/digital_object.rb rename to app/lib/pre_assembly/digital_object.rb diff --git a/lib/pre_assembly/druid_minter.rb b/app/lib/pre_assembly/druid_minter.rb similarity index 100% rename from lib/pre_assembly/druid_minter.rb rename to app/lib/pre_assembly/druid_minter.rb diff --git a/lib/pre_assembly/logging.rb b/app/lib/pre_assembly/logging.rb similarity index 100% rename from lib/pre_assembly/logging.rb rename to app/lib/pre_assembly/logging.rb diff --git a/lib/pre_assembly/object_file.rb b/app/lib/pre_assembly/object_file.rb similarity index 100% rename from lib/pre_assembly/object_file.rb rename to app/lib/pre_assembly/object_file.rb diff --git a/lib/pre_assembly/project/README.txt b/app/lib/pre_assembly/project/README.txt similarity index 100% rename from lib/pre_assembly/project/README.txt rename to app/lib/pre_assembly/project/README.txt diff --git a/lib/pre_assembly/project/salt.rb b/app/lib/pre_assembly/project/salt.rb similarity index 100% rename from lib/pre_assembly/project/salt.rb rename to app/lib/pre_assembly/project/salt.rb diff --git a/lib/pre_assembly/project/smpl.rb b/app/lib/pre_assembly/project/smpl.rb similarity index 100% rename from lib/pre_assembly/project/smpl.rb rename to app/lib/pre_assembly/project/smpl.rb diff --git a/lib/pre_assembly/remediation/remediate.rb b/app/lib/pre_assembly/remediation/item.rb similarity index 100% rename from lib/pre_assembly/remediation/remediate.rb rename to app/lib/pre_assembly/remediation/item.rb diff --git a/lib/pre_assembly/remediation/remediate_project_example.rb b/app/lib/pre_assembly/remediation/remediate_project_example.rb similarity index 100% rename from lib/pre_assembly/remediation/remediate_project_example.rb rename to app/lib/pre_assembly/remediation/remediate_project_example.rb diff --git a/lib/pre_assembly/reporting.rb b/app/lib/pre_assembly/reporting.rb similarity index 100% rename from lib/pre_assembly/reporting.rb rename to app/lib/pre_assembly/reporting.rb diff --git a/lib/pre_assembly/smpl_precontent_metadata.rb b/app/lib/pre_assembly/smpl_precontent_metadata.rb similarity index 100% rename from lib/pre_assembly/smpl_precontent_metadata.rb rename to app/lib/pre_assembly/smpl_precontent_metadata.rb diff --git a/lib/assets/.keep b/lib/assets/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/lib/tasks/.keep b/lib/tasks/.keep deleted file mode 100644 index e69de29b..00000000 diff --git a/spec/lib/pre_assembly/remediation/remediate_spec.rb b/spec/lib/pre_assembly/remediation/item_spec.rb similarity index 100% rename from spec/lib/pre_assembly/remediation/remediate_spec.rb rename to spec/lib/pre_assembly/remediation/item_spec.rb From f2d362f38b2a3d6b58581051bd0414498f140517 Mon Sep 17 00:00:00 2001 From: Sarav Shah Date: Mon, 27 Aug 2018 16:47:49 -0700 Subject: [PATCH 07/10] Further application config stuff --- app/lib/pre_assembly.rb | 19 +------------------ app/lib/pre_assembly/logging.rb | 14 ++++++-------- config/application.rb | 6 +++++- config/boot.rb | 15 --------------- config/cli_environments/test.rb | 2 ++ config/initializers/dor_workflow_service.rb | 4 ++++ 6 files changed, 18 insertions(+), 42 deletions(-) diff --git a/app/lib/pre_assembly.rb b/app/lib/pre_assembly.rb index ad8f174e..880fa91d 100644 --- a/app/lib/pre_assembly.rb +++ b/app/lib/pre_assembly.rb @@ -7,14 +7,6 @@ # auto require any project specific files Dir[File.dirname(__FILE__) + '/pre_assembly/project/*.rb'].each { |file| require "pre_assembly/project/#{File.basename(file)}" } -require 'pre_assembly/reporting' -require 'pre_assembly/druid_minter' -require 'pre_assembly/bundle' -require 'pre_assembly/digital_object' -require 'pre_assembly/object_file' -require 'pre_assembly/remediation/remediate' -require 'pre_assembly/smpl_precontent_metadata' - require 'assembly-utils' require 'assembly-image' require 'rest_client' @@ -31,13 +23,4 @@ 'Manuscript (image-only)' => :book_as_image, 'Map' => :map } - -module PreAssembly - def self.retry_handler(method_name, logger, params = {}) - Proc.new do |_exception, attempt_number, _total_delay| - logger.send " ** #{method_name} FAILED **; with params of #{params.inspect}; and trying attempt #{attempt_number} of #{Dor::Config.dor.num_attempts}; delayed #{Dor::Config.dor.total_delay} seconds" - end - end - - UnknownError = Class.new(StandardError) -end + \ No newline at end of file diff --git a/app/lib/pre_assembly/logging.rb b/app/lib/pre_assembly/logging.rb index d365d636..04e45d10 100644 --- a/app/lib/pre_assembly/logging.rb +++ b/app/lib/pre_assembly/logging.rb @@ -11,14 +11,12 @@ module Logging LOG_FORMAT = "%-6s -- %s -- %s\n" TIME_FORMAT = "%Y-%m-%d %H:%M:%S" - def self.setup(project_root, environment) - log_file = File.join(project_root, 'log', "#{environment}.log") - @@log ||= Logger.new(log_file) - @@log.level = LEVELS[:info] - - @@log.formatter = proc do |severity, datetime, _progname, msg| - LOG_FORMAT % [severity, datetime.strftime(TIME_FORMAT), msg] - end + + @@log ||= Logger.new(File.join(Rails.root, 'log', "#{Rails.env}.log")) + @@log.level = LEVELS[:info] + + @@log.formatter = proc do |severity, datetime, _progname, msg| + LOG_FORMAT % [severity, datetime.strftime(TIME_FORMAT), msg] end def log(msg, severity = :info) diff --git a/config/application.rb b/config/application.rb index 0e98a378..4b987005 100644 --- a/config/application.rb +++ b/config/application.rb @@ -1,10 +1,12 @@ require_relative 'boot' - require 'rails/all' require 'assembly-utils' + # Require the gems listed in Gemfile, including any gems # you've limited to :test, :development, or :production. Bundler.require(*Rails.groups) + + def noko_doc(x) Nokogiri.XML(x) { |conf| conf.default_xml.noblanks } end @@ -18,5 +20,7 @@ class Application < Rails::Application # Application configuration can go into files in config/initializers # -- all .rb files in that directory are automatically loaded after loading # the framework and any gems in your application. + end + UnknownError = Class.new(StandardError) end diff --git a/config/boot.rb b/config/boot.rb index 95ac963d..719172d5 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -4,26 +4,11 @@ require 'rubygems' require 'bundler/setup' -require 'logger' environment = ENV['RAILS_ENV'] || 'development' PRE_ASSEMBLY_ROOT = File.expand_path(File.dirname(__FILE__) + '/..') CERT_DIR = File.join(File.dirname(__FILE__), ".", "certs") -# General DLSS infrastructure. -require 'dor-services' - # Environment. # ENV_FILE = PRE_ASSEMBLY_ROOT + "/config/cli_environments/#{environment}.rb" require_relative "cli_environments/#{environment}.rb" -Dor::Config.dor_services.url ||= Dor::Config.dor.service_root - -# Project dir in load path. -$LOAD_PATH.unshift(PRE_ASSEMBLY_ROOT + '/lib') - -# Set up project logger. -require 'pre_assembly/logging' -PreAssembly::Logging.setup PRE_ASSEMBLY_ROOT, environment - -# Load the project and its dependencies. -require 'pre_assembly' \ No newline at end of file diff --git a/config/cli_environments/test.rb b/config/cli_environments/test.rb index ff7d397b..c0ff41a2 100644 --- a/config/cli_environments/test.rb +++ b/config/cli_environments/test.rb @@ -1,3 +1,5 @@ +require 'dor-services' + Dor::Config.configure do dor do service_root 'https://example.com/dor/v1' diff --git a/config/initializers/dor_workflow_service.rb b/config/initializers/dor_workflow_service.rb index 58c7264a..201dd85e 100644 --- a/config/initializers/dor_workflow_service.rb +++ b/config/initializers/dor_workflow_service.rb @@ -1,5 +1,9 @@ +require 'dor-services' require 'dor-workflow-service' + +Dor::Config.dor_services.url ||= Dor::Config.dor.service_root Dor::WorkflowService.configure( Settings.workflow_services_url, :dor_services_url => Dor::Config.dor_services.url.gsub('/v1', '') ) + From 29de6e42f9ad96991374efd7488e4db35ca69a71 Mon Sep 17 00:00:00 2001 From: Sarav Shah Date: Tue, 28 Aug 2018 14:08:03 -0700 Subject: [PATCH 08/10] constant refactoring, smpl_spec refactor and some namespacing issues --- Gemfile | 1 - app/lib/pre_assembly.rb | 16 +---- app/lib/pre_assembly/digital_object.rb | 17 +++++- .../{smpl_precontent_metadata.rb => smpl.rb} | 0 ..._project_specific_spec.rb => smpl_spec.rb} | 10 ++-- .../test_data/logging/progress_log_file.yml | 60 +++++++++++++++++++ 6 files changed, 81 insertions(+), 23 deletions(-) rename app/lib/pre_assembly/{smpl_precontent_metadata.rb => smpl.rb} (100%) rename spec/lib/pre_assembly/{smpl_project_specific_spec.rb => smpl_spec.rb} (94%) diff --git a/Gemfile b/Gemfile index f5604bc9..d2ba9ba4 100644 --- a/Gemfile +++ b/Gemfile @@ -51,7 +51,6 @@ group :development do end group :development, :test do - gem 'rspec-rails' gem 'byebug' gem 'rspec-rails', '~> 3.7' gem 'rubocop', '~> 0.58' diff --git a/app/lib/pre_assembly.rb b/app/lib/pre_assembly.rb index 880fa91d..3e06403a 100644 --- a/app/lib/pre_assembly.rb +++ b/app/lib/pre_assembly.rb @@ -1,8 +1,7 @@ require 'fileutils' require 'erb' -# these are the names of special datastream files that will be staged in the 'metadata' folder instead of the 'content' folder -METADATA_FILES = ['descMetadata.xml', 'contentMetadata.xml'].map(&:downcase) + # auto require any project specific files Dir[File.dirname(__FILE__) + '/pre_assembly/project/*.rb'].each { |file| require "pre_assembly/project/#{File.basename(file)}" } @@ -11,16 +10,3 @@ require 'assembly-image' require 'rest_client' require 'honeybadger' - -# map the content type tags set inside an object to content metadata creation styles supported by the assembly-objectfile gem -# format is 'tag_value' => 'gem style name' -CONTENT_TYPE_TAG_MAPPING = { - 'Image' => :simple_image, - 'File' => :file, - 'Book (flipbook, ltr)' => :simple_book, - 'Book (image-only)' => :book_as_image, - 'Manuscript (flipbook, ltr)' => :simple_book, - 'Manuscript (image-only)' => :book_as_image, - 'Map' => :map -} - \ No newline at end of file diff --git a/app/lib/pre_assembly/digital_object.rb b/app/lib/pre_assembly/digital_object.rb index 9902852f..0f5f2a66 100644 --- a/app/lib/pre_assembly/digital_object.rb +++ b/app/lib/pre_assembly/digital_object.rb @@ -76,11 +76,22 @@ def stager(source, destination) # set this object's content_md_creation_style def content_md_creation_style + # map the content type tags set inside an object to content metadata creation styles supported by the assembly-objectfile gem + # format is 'tag_value' => 'gem style name' + content_type_tag_mapping = { + 'Image' => :simple_image, + 'File' => :file, + 'Book (flipbook, ltr)' => :simple_book, + 'Book (image-only)' => :book_as_image, + 'Manuscript (flipbook, ltr)' => :simple_book, + 'Manuscript (image-only)' => :book_as_image, + 'Map' => :map + } # if this object needs to be registered or has no content type tag for a registered object, use the default set in the YAML file if !project_style[:content_tag_override] || content_type_tag.blank? default_content_md_creation_style else # if the object is already registered and there is a content type tag and we allow overrides, use it if we know what it means (else use the default) - CONTENT_TYPE_TAG_MAPPING[content_type_tag] || default_content_md_creation_style + content_type_tag_mapping[content_type_tag] || default_content_md_creation_style end end @@ -196,12 +207,14 @@ def prepare_for_reaccession # Create the druid tree within the staging directory, # and then copy-recursive all stageable items to that area. def stage_files + # these are the names of special datastream files that will be staged in the 'metadata' folder instead of the 'content' folder + metadata_files = ['descMetadata.xml', 'contentMetadata.xml'].map(&:downcase) log " - staging(druid_tree_dir = #{druid_tree_dir.inspect})" create_object_directories stageable_items.each do |si_path| log " - staging(#{si_path}, #{content_dir})", :debug # determine destination of staged file by looking to see if it is a known datastream XML file or not - destination = METADATA_FILES.include?(File.basename(si_path).downcase) ? metadata_dir : content_dir + destination = metadata_files.include?(File.basename(si_path).downcase) ? metadata_dir : content_dir stager si_path, destination end end diff --git a/app/lib/pre_assembly/smpl_precontent_metadata.rb b/app/lib/pre_assembly/smpl.rb similarity index 100% rename from app/lib/pre_assembly/smpl_precontent_metadata.rb rename to app/lib/pre_assembly/smpl.rb diff --git a/spec/lib/pre_assembly/smpl_project_specific_spec.rb b/spec/lib/pre_assembly/smpl_spec.rb similarity index 94% rename from spec/lib/pre_assembly/smpl_project_specific_spec.rb rename to spec/lib/pre_assembly/smpl_spec.rb index 8da682b0..29d037b1 100644 --- a/spec/lib/pre_assembly/smpl_project_specific_spec.rb +++ b/spec/lib/pre_assembly/smpl_spec.rb @@ -1,11 +1,11 @@ -describe PreAssembly::DigitalObject do +describe PreAssembly::Smpl do let(:bundle_dir) { File.join(PRE_ASSEMBLY_ROOT, 'spec/test_data/bundle_input_e') } describe 'SMPL content metadata generation and techMetadata generation - no thumb declaration' do let(:dobj1) { setup_dobj('aa111aa1111', smpl_manifest) } let(:dobj2) { setup_dobj('bb222bb2222', smpl_manifest) } let(:smpl_manifest) do - PreAssembly::Smpl.new(:csv_filename => 'smpl_manifest.csv', :bundle_dir => bundle_dir, :verbose => false) + described_class.new(:csv_filename => 'smpl_manifest.csv', :bundle_dir => bundle_dir, :verbose => false) end it "generates technicalMetadata for SMPL by combining all existing _techmd.xml files" do @@ -29,7 +29,7 @@ describe 'SMPL content metadata generation with thumb declaration' do it "generates content metadata from a SMPL manifest with a thumb column set to yes" do - smpl_manifest = PreAssembly::Smpl.new(:csv_filename => 'smpl_manifest_with_thumb.csv', :bundle_dir => bundle_dir, :verbose => false) + smpl_manifest = described_class.new(:csv_filename => 'smpl_manifest_with_thumb.csv', :bundle_dir => bundle_dir, :verbose => false) dobj1 = setup_dobj('aa111aa1111', smpl_manifest) dobj2 = setup_dobj('bb222bb2222', smpl_manifest) dobj1.create_content_metadata @@ -39,7 +39,7 @@ end it "generates content metadata from a SMPL manifest with a thumb column set to true" do - smpl_manifest = PreAssembly::Smpl.new(:csv_filename => 'smpl_manifest_with_thumb_true.csv', :bundle_dir => bundle_dir, :verbose => false) + smpl_manifest = described_class.new(:csv_filename => 'smpl_manifest_with_thumb_true.csv', :bundle_dir => bundle_dir, :verbose => false) dobj1 = setup_dobj('aa111aa1111', smpl_manifest) dobj2 = setup_dobj('bb222bb2222', smpl_manifest) dobj1.create_content_metadata @@ -49,7 +49,7 @@ end it "generates content metadata from a SMPL manifest with no thumbs when the thumb column is set to no" do - smpl_manifest = PreAssembly::Smpl.new(:csv_filename => 'smpl_manifest_thumb_no.csv', :bundle_dir => bundle_dir, :verbose => false) + smpl_manifest = described_class.new(:csv_filename => 'smpl_manifest_thumb_no.csv', :bundle_dir => bundle_dir, :verbose => false) dobj1 = setup_dobj('aa111aa1111', smpl_manifest) dobj2 = setup_dobj('bb222bb2222', smpl_manifest) dobj1.create_content_metadata diff --git a/spec/lib/test_data/logging/progress_log_file.yml b/spec/lib/test_data/logging/progress_log_file.yml index f1246de0..6bc13cde 100644 --- a/spec/lib/test_data/logging/progress_log_file.yml +++ b/spec/lib/test_data/logging/progress_log_file.yml @@ -13,3 +13,63 @@ :remediate_completed: :message: :timestamp: 2018-08-27 16:11:03.600040000 -07:00 +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-27 17:03:36.797315000 -07:00 +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-27 17:05:55.928477000 -07:00 +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-27 17:07:21.346747000 -07:00 +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-27 17:26:25.149300000 -07:00 +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-27 17:27:31.306870000 -07:00 +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-27 17:32:39.690777000 -07:00 +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-28 13:00:37.348480000 -07:00 +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-28 13:30:52.842153000 -07:00 +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-28 13:56:51.193539000 -07:00 +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-28 14:01:18.897071000 -07:00 +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-28 14:02:33.204399000 -07:00 +--- +:pid: druid:cs575bk5522 +:remediate_completed: +:message: +:timestamp: 2018-08-28 14:03:13.650553000 -07:00 From 9482e33e2c50b6c5fba9fcaa406fefedc4e85b7b Mon Sep 17 00:00:00 2001 From: Sarav Shah Date: Tue, 28 Aug 2018 14:28:16 -0700 Subject: [PATCH 09/10] update gemfile lock --- Gemfile.lock | 1 - 1 file changed, 1 deletion(-) diff --git a/Gemfile.lock b/Gemfile.lock index 5a69a2c4..4c78368f 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -509,7 +509,6 @@ DEPENDENCIES rest-client retries roo - rspec (~> 3.0) rspec-rails (~> 3.7) rubocop (~> 0.58) rubocop-rspec From 2ac2239b266c79d68f0e9b98f17d39c076959f71 Mon Sep 17 00:00:00 2001 From: Sarav Shah Date: Tue, 28 Aug 2018 17:04:34 -0700 Subject: [PATCH 10/10] Add coveralls back, remove unwanted autoloading in pre_assembly.rb and add file to gitignore --- .gitignore | 1 + app/lib/pre_assembly.rb | 7 -- config/boot.rb | 3 - config/cli_environments/test.rb | 1 - spec/lib/pre_assembly/bundle_spec.rb | 2 +- .../lib/pre_assembly/remediation/item_spec.rb | 12 ++- .../test_data/logging/progress_log_file.yml | 75 ------------------- spec/rails_helper.rb | 2 + spec/spec_helper.rb | 1 - 9 files changed, 13 insertions(+), 91 deletions(-) delete mode 100644 spec/lib/test_data/logging/progress_log_file.yml diff --git a/.gitignore b/.gitignore index 937de7c7..5cfbd00b 100644 --- a/.gitignore +++ b/.gitignore @@ -20,6 +20,7 @@ tags tmp /workflow_service.log* coverage +spec/lib/test_data/logging/progress_log_file.yml # Ignore master key for decrypting credentials and more. /config/master.key diff --git a/app/lib/pre_assembly.rb b/app/lib/pre_assembly.rb index 3e06403a..050e00fe 100644 --- a/app/lib/pre_assembly.rb +++ b/app/lib/pre_assembly.rb @@ -1,12 +1,5 @@ require 'fileutils' require 'erb' - - - -# auto require any project specific files -Dir[File.dirname(__FILE__) + '/pre_assembly/project/*.rb'].each { |file| require "pre_assembly/project/#{File.basename(file)}" } - -require 'assembly-utils' require 'assembly-image' require 'rest_client' require 'honeybadger' diff --git a/config/boot.rb b/config/boot.rb index 719172d5..9493f53c 100644 --- a/config/boot.rb +++ b/config/boot.rb @@ -1,14 +1,11 @@ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../Gemfile', __dir__) require 'bundler/setup' # Set up gems listed in the Gemfile. - require 'rubygems' -require 'bundler/setup' environment = ENV['RAILS_ENV'] || 'development' PRE_ASSEMBLY_ROOT = File.expand_path(File.dirname(__FILE__) + '/..') CERT_DIR = File.join(File.dirname(__FILE__), ".", "certs") # Environment. -# ENV_FILE = PRE_ASSEMBLY_ROOT + "/config/cli_environments/#{environment}.rb" require_relative "cli_environments/#{environment}.rb" diff --git a/config/cli_environments/test.rb b/config/cli_environments/test.rb index c0ff41a2..bbaba74c 100644 --- a/config/cli_environments/test.rb +++ b/config/cli_environments/test.rb @@ -1,5 +1,4 @@ require 'dor-services' - Dor::Config.configure do dor do service_root 'https://example.com/dor/v1' diff --git a/spec/lib/pre_assembly/bundle_spec.rb b/spec/lib/pre_assembly/bundle_spec.rb index cf647077..7b290df7 100644 --- a/spec/lib/pre_assembly/bundle_spec.rb +++ b/spec/lib/pre_assembly/bundle_spec.rb @@ -49,7 +49,7 @@ def bundle_setup(bundle_context) describe '#load_skippables' do it "does nothing if @resume is false" do - rumsey.resume = false + allow(rumsey).to receive(:resume).and_return(false) expect(rumsey.load_skippables).to be_nil end diff --git a/spec/lib/pre_assembly/remediation/item_spec.rb b/spec/lib/pre_assembly/remediation/item_spec.rb index b0b132ca..64b45a05 100644 --- a/spec/lib/pre_assembly/remediation/item_spec.rb +++ b/spec/lib/pre_assembly/remediation/item_spec.rb @@ -9,13 +9,19 @@ end context 'logging' do - let(:log_dir) { File.join(File.dirname(__FILE__), "../../test_data/logging") } + let(:log_dir) { File.join(Rails.root, "spec/lib/test_data/logging") } let(:csv_filename) { log_dir + "/csv_log.csv" } let(:progress_log_file) { log_dir + "/progress_log_file.yml" } - before { Dir.mkdir(log_dir) unless Dir.exist?(log_dir) } + before do + FileUtils.mkdir_p(log_dir) unless Dir.exist?(log_dir) + FileUtils.touch progress_log_file + end - after { File.delete(csv_filename) if File.exist?(csv_filename) } + after do + File.delete(csv_filename) if File.exist?(csv_filename) + FileUtils.rm_f(progress_log_file) # cleanup + end it "ensures a log file exists" do File.delete(csv_filename) if File.exist?(csv_filename) diff --git a/spec/lib/test_data/logging/progress_log_file.yml b/spec/lib/test_data/logging/progress_log_file.yml deleted file mode 100644 index 6bc13cde..00000000 --- a/spec/lib/test_data/logging/progress_log_file.yml +++ /dev/null @@ -1,75 +0,0 @@ ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-27 15:09:13.779278000 -07:00 ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-27 15:10:55.044887000 -07:00 ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-27 16:11:03.600040000 -07:00 ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-27 17:03:36.797315000 -07:00 ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-27 17:05:55.928477000 -07:00 ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-27 17:07:21.346747000 -07:00 ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-27 17:26:25.149300000 -07:00 ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-27 17:27:31.306870000 -07:00 ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-27 17:32:39.690777000 -07:00 ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-28 13:00:37.348480000 -07:00 ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-28 13:30:52.842153000 -07:00 ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-28 13:56:51.193539000 -07:00 ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-28 14:01:18.897071000 -07:00 ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-28 14:02:33.204399000 -07:00 ---- -:pid: druid:cs575bk5522 -:remediate_completed: -:message: -:timestamp: 2018-08-28 14:03:13.650553000 -07:00 diff --git a/spec/rails_helper.rb b/spec/rails_helper.rb index 7413a13c..24fe06d3 100644 --- a/spec/rails_helper.rb +++ b/spec/rails_helper.rb @@ -7,6 +7,8 @@ require 'rspec/rails' # Add additional requires below this line. Rails is not loaded until this point! +require 'coveralls' +Coveralls.wear!('rails') # auto-require all ruby files in the support directory Dir[Rails.root.join('spec', 'support', '*.rb')].each { |f| require f } diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 45bd3f30..4ca49fb0 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -2,7 +2,6 @@ require 'equivalent-xml/rspec_matchers' require 'byebug' - RSpec.configure do |config| # rspec-expectations config goes here. You can use an alternate