From 8a68b2e11528107366fec849fdcdd743f8f4f3b1 Mon Sep 17 00:00:00 2001 From: Jim Blake Date: Thu, 18 Jun 2015 17:15:49 -0400 Subject: [PATCH] Create the top-level command structure. --- .gitignore | 3 ++ README.md | 51 ++++++++++++------- cmd_capture/cmd_capture.rb | 9 ++++ cmd_compare/cmd_compare.rb | 9 ++++ cmd_compare_again/cmd_compare_again.rb | 10 ++++ cmd_display/cmd_display.rb | 10 ++++ .../cmd_prepare_self_editor_account.rb | 10 ++++ .../cmd_prepare_session_list.rb | 10 ++++ cmd_prepare_sub_list/cmd_prepare_sub_list.rb | 10 ++++ cmd_prepare_uri_list/cmd_prepare_uri_list.rb | 9 ++++ common.rb | 27 ++++++++++ vivosnap.rb | 51 +++++++++++++++++++ 12 files changed, 191 insertions(+), 18 deletions(-) create mode 100644 .gitignore create mode 100644 cmd_capture/cmd_capture.rb create mode 100644 cmd_compare/cmd_compare.rb create mode 100644 cmd_compare_again/cmd_compare_again.rb create mode 100644 cmd_display/cmd_display.rb create mode 100644 cmd_prepare_self_editor_account/cmd_prepare_self_editor_account.rb create mode 100644 cmd_prepare_session_list/cmd_prepare_session_list.rb create mode 100644 cmd_prepare_sub_list/cmd_prepare_sub_list.rb create mode 100644 cmd_prepare_uri_list/cmd_prepare_uri_list.rb create mode 100644 common.rb create mode 100755 vivosnap.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..99a416e --- /dev/null +++ b/.gitignore @@ -0,0 +1,3 @@ +.buildpath +.project +.README.md.html diff --git a/README.md b/README.md index 0c8e65f..0c2d07c 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ ## Purpose - Detect whether changes to the code have resulted in any changes to the pages that are served. -- Test a small “canary set” to detect obvious problems. When the obvious problems are fixed, enlarge the set and +- Test a small "canary set" to detect obvious problems. When the obvious problems are fixed, enlarge the set and repeat until the entire site is tested. Or simply test the entire set to begin with. ## Use cases @@ -33,33 +33,38 @@ in addition to the URL, each request may specify POST or GET, HTTP headers, and ## Commands ``` -vivosnap prepare uri-list [classlist_file] [VIVO_homepage_URL] [uri_list_file] +vivosnap.rb prepare uri-list [classlist_file] [VIVO_homepage_URL] [uri_list_file] ``` +**NOT IMPLEMENTED** Create a list of URIs. You provide a file with class URIs, and a URL for VIVO. The tool will make requests of VIVOs ListRDF API, and write the results to the URI list file. ``` -vivosnap prepare session-list [uri_list_file] [account_email] [account_password] [session_list_file] +vivosnap.rb prepare session-list [uri_list_file] [account_email] [account_password] [session_list_file] ``` +**NOT IMPLEMENTED** Create a session list. You provide a file of URIs, and the tool will generate the URLs needed to fetch the profile pages for those URIs. If you want a login on each session, provide the email address and password of the desired login account. ``` -vivosnap prepare self-editor-account [VIVO_homepage_URL] [uri_list_file] [admin_email] [admin_password] [editor_email] [editor_password] +vivosnap.rb prepare self-editor-account [VIVO_homepage_URL] [uri_list_file] [admin_email] [admin_password] [editor_email] [editor_password] ``` +**NOT IMPLEMENTED** Write triples to the user accounts model of the VIVO to create the self-editor-account (unless it exists already) and to make it a proxy editor for all of the URLs in the list. ``` -vivosnap prepare sub-list [session_list_file] [count] [sub_list_file] +vivosnap.rb prepare sub-list [session_list_file] [count] [sub_list_file] ``` +**NOT IMPLEMENTED** Create a smaller session list from an existing one. The new list will have the specified number of entries, extracted at even intervals from the existing list. ``` -vivosnap capture [VIVO_homepage_URL] [session_list_file] [responses_directory] {OVERWRITE|REPLACE} +vivosnap.rb capture [VIVO_homepage_URL] [session_list_file] [responses_directory] {OVERWRITE|REPLACE} ``` +**NOT IMPLEMENTED** Capture a snapshot. Provide the URL of the VIVO home page, and a session list, and the tool will make the requests, storing the responses in the given directory. If the responses directory does not exist, it will be created, providing its parent directory exists. @@ -68,32 +73,42 @@ If the responses directory is not empty, you must specify either OVERWRITE or RE - REPLACE deletes the contents of the directory before running. ``` -vivosnap compare [reference_responses_directory] [test_responses_directory] {expected_changes_file} [differences_directory] +vivosnap.rb compare [reference_responses_directory] [test_responses_directory] {expected_changes_file} [differences_directory] ``` +**NOT IMPLEMENTED** Compare two snapshots. The test snapshot is expected to be a subset of the reference snapshot (or equivalent), taken at a later time. The list of expected changes, if present, will be applied when comparing responses. The differences between the snapshots will be stored in the given directory. ``` -vivosnap re-compare [differences_directory] [expected_changes_file] [new_differences_directory] +vivosnap.rb compare again [differences_directory] [expected_changes_file] [new_differences_directory] ``` +**NOT IMPLEMENTED** Re-compare just the differences between two snapshots, presumably with a different list of expected changes. The original snapshot directories must still exist, because the differences directory will reference them. +``` +vivosnap.rb display [differences_directory] +``` +**NOT IMPLEMENTED** +A simple tool that allows you to view differences. You must configure your DIFF tool. Note that this +does not allow for expected changes. + + ## Data structure details ### Session list -Here is a silly pseudo-syntax. URLs are all relative to the VIVO home page. -``` -line ⇔ session -session ⇔ [login ==> ] request [ ==> request ]* -login ⇔ LOGIN email pass -request ⇔ url [method | header | parameter]* -method ⇔ GET | POST -header ⇔ key(value) -parameter ⇔ key=value -value ⇔ must be in single quotes if contains space +Here is a pseudo-syntax. URLs are all relative to the VIVO home page. +``` +line === session +session === [login ==> ] request [ ==> request ]* +login === LOGIN email pass +request === url [method | header | parameter]* +method === GET | POST +header === key(value) +parameter === key=value +value === must be in single quotes if contains space ``` #### Examples diff --git a/cmd_capture/cmd_capture.rb b/cmd_capture/cmd_capture.rb new file mode 100644 index 0000000..01f8fcd --- /dev/null +++ b/cmd_capture/cmd_capture.rb @@ -0,0 +1,9 @@ +class CmdCapture + def initialize(args) + bogus "CmdCapture.initialize NOT IMPLEMENTED" + end + + def run() + bogus "CmdCapture.run NOT IMPLEMENTED" + end +end diff --git a/cmd_compare/cmd_compare.rb b/cmd_compare/cmd_compare.rb new file mode 100644 index 0000000..cbf9849 --- /dev/null +++ b/cmd_compare/cmd_compare.rb @@ -0,0 +1,9 @@ +class CmdCompare + def initialize(args) + bogus "CmdCompare.initialize NOT IMPLEMENTED" + end + + def run() + bogus "CmdCompare.run NOT IMPLEMENTED" + end +end \ No newline at end of file diff --git a/cmd_compare_again/cmd_compare_again.rb b/cmd_compare_again/cmd_compare_again.rb new file mode 100644 index 0000000..6859f56 --- /dev/null +++ b/cmd_compare_again/cmd_compare_again.rb @@ -0,0 +1,10 @@ +class CmdCompareAgain + def initialize(args) + bogus "CmdCompareAgain.initialize NOT IMPLEMENTED" + end + + def run() + bogus "CmdCompareAgain.run NOT IMPLEMENTED" + end +end + diff --git a/cmd_display/cmd_display.rb b/cmd_display/cmd_display.rb new file mode 100644 index 0000000..7412913 --- /dev/null +++ b/cmd_display/cmd_display.rb @@ -0,0 +1,10 @@ +class CmdDisplay + def initialize(args) + bogus "CmdDisplay.initialize NOT IMPLEMENTED" + end + + def run() + bogus "CmdDisplay.run NOT IMPLEMENTED" + end +end + diff --git a/cmd_prepare_self_editor_account/cmd_prepare_self_editor_account.rb b/cmd_prepare_self_editor_account/cmd_prepare_self_editor_account.rb new file mode 100644 index 0000000..e0b7ce7 --- /dev/null +++ b/cmd_prepare_self_editor_account/cmd_prepare_self_editor_account.rb @@ -0,0 +1,10 @@ +class CmdPrepareSelfEditorAccount + def initialize(args) + bogus "CmdPrepareSelfEditorAccount.initialize NOT IMPLEMENTED" + end + + def run() + bogus "CmdPrepareSelfEditorAccount.run NOT IMPLEMENTED" + end +end + diff --git a/cmd_prepare_session_list/cmd_prepare_session_list.rb b/cmd_prepare_session_list/cmd_prepare_session_list.rb new file mode 100644 index 0000000..a1f1ce4 --- /dev/null +++ b/cmd_prepare_session_list/cmd_prepare_session_list.rb @@ -0,0 +1,10 @@ +class CmdPrepareSessionList + def initialize(args) + bogus "CmdPrepareSessionList.initialize NOT IMPLEMENTED" + end + + def run() + bogus "CmdPrepareSessionList.run NOT IMPLEMENTED" + end +end + diff --git a/cmd_prepare_sub_list/cmd_prepare_sub_list.rb b/cmd_prepare_sub_list/cmd_prepare_sub_list.rb new file mode 100644 index 0000000..247501b --- /dev/null +++ b/cmd_prepare_sub_list/cmd_prepare_sub_list.rb @@ -0,0 +1,10 @@ +class CmdPrepareSubList + def initialize(args) + bogus "CmdPrepareSubList.initialize NOT IMPLEMENTED" + end + + def run() + bogus "CmdPrepareSubList.run NOT IMPLEMENTED" + end +end + diff --git a/cmd_prepare_uri_list/cmd_prepare_uri_list.rb b/cmd_prepare_uri_list/cmd_prepare_uri_list.rb new file mode 100644 index 0000000..27a9cb9 --- /dev/null +++ b/cmd_prepare_uri_list/cmd_prepare_uri_list.rb @@ -0,0 +1,9 @@ +class CmdPrepareUriList + def initialize(args) + bogus "CmdPrepareUriList.initialize NOT IMPLEMENTED" + end + + def run() + bogus "CmdPrepareUriList.run NOT IMPLEMENTED" + end +end diff --git a/common.rb b/common.rb new file mode 100644 index 0000000..f321352 --- /dev/null +++ b/common.rb @@ -0,0 +1,27 @@ +# +# Helpful classes and utility methods. +# +class UserInputError < StandardError +end + +class SettingsError < StandardError +end + +def warning(message) + puts("WARNING: #{message}") +end + +module Kernel + def bogus(message) + puts(">>>>>>>>>>>>>BOGUS #{message}") + end +end + +require_relative 'cmd_prepare_uri_list/cmd_prepare_uri_list' +require_relative 'cmd_prepare_session_list/cmd_prepare_session_list' +require_relative 'cmd_prepare_self_editor_account/cmd_prepare_self_editor_account' +require_relative 'cmd_prepare_sub_list/cmd_prepare_sub_list' +require_relative 'cmd_capture/cmd_capture' +require_relative 'cmd_compare/cmd_compare' +require_relative 'cmd_compare_again/cmd_compare_again' +require_relative 'cmd_display/cmd_display' diff --git a/vivosnap.rb b/vivosnap.rb new file mode 100755 index 0000000..d4b602f --- /dev/null +++ b/vivosnap.rb @@ -0,0 +1,51 @@ +#! /usr/bin/env ruby + +require_relative 'common' + +class Vivosnap + COMMANDS = [ + [:CmdPrepareUriList, ['prepare', 'uri-list']], + [:CmdPrepareSessionList, ['prepare', 'session-list']], + [:CmdPrepareSelfEditorAccount, ['prepare', 'self-editor-account']], + [:CmdPrepareSubList, ['prepare', 'sub-list']], + [:CmdCapture, ['capture']], + [:CmdCompareAgain, ['compare', 'again']], + [:CmdCompare, ['compare']], + [:CmdDisplay, ['display']] + ] + + def initialize(args) + COMMANDS.each do |cmd| + cmd_args = cmd[1] + matching_args = args.take(cmd_args.size) + remaining_args = args.drop(cmd_args.size) + if cmd_args == matching_args + @cmd_instance = Object.const_get(cmd[0]).new(remaining_args) + return + end + end + raise UserInputError.new("Arguments not valid: #{args.join(' ')}\nValid choices are #{format_cmds}") + end + + def format_cmds() + "\n #{COMMANDS.map {|c| c[1].join(' ') }.join("\n ")}" + end + + def run() + @cmd_instance.run() + end +end + +# +# --------------------------------------------------------- +# MAIN ROUTINE +# --------------------------------------------------------- +# + +begin + Vivosnap.new(ARGV).run +rescue UserInputError + puts + puts $! + puts +end \ No newline at end of file