From a0b1974579682ec3abcbae1e459a8921209586de Mon Sep 17 00:00:00 2001 From: matthieu Date: Tue, 11 Jul 2017 13:01:11 +0200 Subject: [PATCH] V : 0.12.6 --- Changelog.md | 1 + UnitTests.rb | 126 +++------------- sources/DB/Manga_data.rb | 12 ++ sources/Download/base_downloader.rb | 75 +++++----- sources/Download/mangafox.rb | 2 +- sources/api/mangas.rb | 2 +- sources/html/html.rb | 4 +- sources/html/html_manga.rb | 2 +- sources/init.rb | 16 +- sources/instructions/Instructions_exec.rb | 6 + sources/instructions/Parsers/Site_parser.rb | 10 ++ .../instructions/Parsers/exec/Data_parser.rb | 73 +++++++++ .../Parsers/exec/Instruction_parser.rb | 108 ++++++++++++++ sources/instructions/delete_diff.rb | 2 +- sources/templates/text/version.txt | 2 +- sources/unitTests/Database.rb | 0 sources/unitTests/Init.rb | 138 ++++++++++++++++++ sources/unitTests/Web.rb | 0 18 files changed, 423 insertions(+), 156 deletions(-) create mode 100644 sources/instructions/Parsers/Site_parser.rb create mode 100644 sources/instructions/Parsers/exec/Data_parser.rb create mode 100644 sources/instructions/Parsers/exec/Instruction_parser.rb create mode 100644 sources/unitTests/Database.rb create mode 100644 sources/unitTests/Init.rb create mode 100644 sources/unitTests/Web.rb diff --git a/Changelog.md b/Changelog.md index 49a861f..c871036 100644 --- a/Changelog.md +++ b/Changelog.md @@ -1,5 +1,6 @@ ### Changelog : +0.12.6 : optimisation and display : a chapter that is a todo will not be downloaded twice during an update if it is not in the traces satabase + a fex errors are now esier to read and understand
0.12.5 : stability fix : fixed a wrong path for the covers ( they were not displayed correctly on the local website ) + corrected a few errors with the todo elements and the related display
0.12.4 : stability fix : corrected an error with the instruction parsing
0.12.3 : stability fix : fixed an issue with the instrction parser + an issue where MangaScrap would download 0 pages for a chapter
diff --git a/UnitTests.rb b/UnitTests.rb index 3398572..33b7931 100755 --- a/UnitTests.rb +++ b/UnitTests.rb @@ -24,113 +24,33 @@ ################################################################################## ################################################################################## -puts 'needs to be updated' -exit 42 -verbose = false -if ARGV.size != 0 - if ARGV[0] == 'verbose' - verbose = true - else - puts 'unknown argument : "' + ARGV[0] + '"' - exit 4 +# get arguments from ARGV +verbose = true +high_verbose = false + +# used to display an error if the file could not be loaded +module Unit_tests_API + def self.require_file(file) + begin + require_relative file + rescue LoadError => e + puts 'Error while loading ' + file + '.rb' + puts 'Message is : ' + e.message + puts 'Error class is : ' + e.message + return false + end + true end end -def UnitTest_require_file(file) - begin - require_relative file - rescue LoadError => e - puts 'Error while loading ' + file + '. Message is : ' + e.message - return false - end - true -end - -def UnitTest_load_gem(gem) - begin - require gem - rescue LoadError => e - puts 'Error while loading the ' + gem + ' gem. Message is : ' + e.message - return false - end - true -end - - -puts '====> Unit tests' -puts '' - -puts '====> 1 - requiring init file' -begin - if verbose - puts 'requiring sources/init.rb' - end - require_relative 'sources/init' -rescue LoadError => e - puts 'Error while loading the init file (it should have been at : ' + Dir.pwd + '/sources/init.rb)' - puts 'aborting' +puts 'starting unit tests' if verbose +puts '' if verbose +if !Unit_tests_API::require_file('sources/unitTests/Init') || +!Unit_tests_API::require_file('sources/unitTests/Database') || +!Unit_tests_API::require_file('sources/unitTests/Web') exit 1 end -puts 'ok' -puts '' - -puts '====> 2 requiring all gems' -failure = false -Init::get_gem_list.each do |gem| - if verbose - puts 'requiring ' + gem - end - failure = !(UnitTest_load_gem gem || failure) -end -if failure - puts 'aborting' - exit 2 -end -puts 'ok' -puts '' - -puts '====> 3 requiring all MangaScrap files' -failure = false -Init::get_file_list.each do |file| - if verbose - puts 'requiring sources/' + file - end - failure = !(UnitTest_require_file('sources/' + file) || failure) -end -puts 'ok' -puts '' - -Struct.new('Arg', :name, :sub_args, :nb_args, :does_not_need_args?) -Struct.new('Sub_arg', :name, :nb_args) -Struct.new('Updated', :name, :downloaded) -Struct.new('Query_arg', :name, :arg_type, :sql_column, :sub_string) -Struct.new('HTML_data', :volume, :chapter, :date, :href, :nb_pages, :file_name) - -puts '====> 4 getting the database' -begin - params = Manga_database.instance.get_manga_list - pp params -rescue Exception => e - puts 'Error' - pp e.class.to_s - pp e.message - exit 5 -end -puts 'ok' -puts '' - -puts '====> 5 getting the params' -begin - params = Params.instance.get_params - pp params -rescue Exception => e - puts 'Error' - pp e.class.to_s - pp e.message - exit 5 -end -puts 'ok' -puts '' -puts '====> all good' +init = UT_Init.new(verbose, high_verbose) +init.run diff --git a/sources/DB/Manga_data.rb b/sources/DB/Manga_data.rb index 62c33e1..3476d14 100644 --- a/sources/DB/Manga_data.rb +++ b/sources/DB/Manga_data.rb @@ -15,6 +15,16 @@ class Manga_data attr_reader :to_complete, :link, :name, :site_dir, :id, :site, :data, :status, :in_db private + # places all of the website related information in the @sites array + def init_sites + @sites << Struct::Website.new('http://mangafox.me/', %w(http://mangafox.me mangafox.me mangafox), + 'mangafox', 'manga/', Download_Mangafox) + @sites << Struct::Website.new('http://www.mangareader.net/', %w(http://www.mangareader.net www.mangareader.net mangareader.net mangareader), + 'mangareader', '', Download_Mangareader_Pandamanga) + @sites << Struct::Website.new('http://www.mangapanda.com/', %w(http://www.mangapanda.com www.mangapanda.com mangapanda.com mangapanda), + 'pandamanga', '', Download_Mangareader_Pandamanga) + end + # ensures that the link starts with http or https def link_correction unless @link.start_with?('http://', 'https://') @@ -236,6 +246,8 @@ def initialize(id, name, site, link, data) @to_complete = '' @in_db = @status @download_class = nil + @sites = [] + init_sites if @in_db is_site_compatible?(false) # function used here to get @site_dir and @to_complete values end diff --git a/sources/Download/base_downloader.rb b/sources/Download/base_downloader.rb index 6e5a7ff..37f21fb 100644 --- a/sources/Download/base_downloader.rb +++ b/sources/Download/base_downloader.rb @@ -87,6 +87,29 @@ def get_chapter_from_link(link, prep_display, nb_pages_xpath, add_to_link) true end + # checks witch are the chapters that have not been downloaded ( they are not in the traces database ) + # the method first gets all of the links from the database and then compares with the links of the website + def missing_chapters + traces = @db.get_trace(@manga_data) + if @todo.size != 0 + @todo = @todo.reject{|e| e[:page] != -1} + end + i = 0 + all_data = [] + @links.each do |link| + all_data << Struct::Data.new(*@manga_data.extract_values_from_link(link), link) + end + Utils_misc::sort_chapter_list(all_data).each do |data| + if traces.count{|_id, _manga_name, vol_value, chap_value| vol_value == data[:volume] && chap_value == data[:chapter]} == 0 && + @todo.count{|e| e[:chapter] == data[:chapter]} == 0 + prep_display = " ( link #{i + 1} / #{@links.size} )" + chapter_link(data[:link], prep_display) + end + i += 1 + end + @aff.dump + end + public # takes the data array [volume, chapter, page] and casts it into a string def values_to_string(volume, chapter, page) @@ -95,19 +118,19 @@ def values_to_string(volume, chapter, page) page_string = '' case volume when -2 - volume_string = 'volume TBD' + volume_string = 'volume TBD ' when -3 - volume_string = 'volume NA' + volume_string = 'volume NA ' when -4 - volume_string = 'volume ANT' + volume_string = 'volume ANT ' else if volume >= 0 - volume_string = "volume #{volume}" + volume_string = "volume #{volume} " end end - chapter_string = "chapter #{chapter} " if chapter != nil || chapter == -1 + chapter_string = "chapter #{chapter}" if chapter != nil || chapter == -1 page_string = "page #{page}" if page != nil || page == -1 - volume_string + ' ' + chapter_string + ' ' + page_string + volume_string + chapter_string + ' ' + page_string end def data_to_string(data) @@ -132,10 +155,10 @@ def chapter_link(link, prep_display = '') # elem[0] = id of line in database ; elem[1] = id of manga in database # elem[2] = volume value ; elem[3] = chapter value ; elem[4] = page value def todo - todo = @db.get_todo(@manga_data) - if todo.size != 0 + @todo = @db.get_todo(@manga_data) + if @todo.size != 0 @aff.prepare_todo - Utils_misc::sort_chapter_list(todo, true).each do |elem| + Utils_misc::sort_chapter_list(@todo, true).each do |elem| if elem[:page] != -1 # if page data = [] << elem[:volume] << elem[:chapter] << elem[:page] if page_link(link_generator(elem[:volume], elem[:chapter], elem[:page]), data) @@ -152,38 +175,6 @@ def todo @downloaded_a_page end - # checks witch are the chapters that have not been downloaded ( they are not in the traces database ) - # the method first gets all of the links from the database and then compares with the links of the website - def missing_chapters -=begin - traces = @db.get_trace(@manga_data) - i = 0 - @links.each do |link| - data = @manga_data.extract_values_from_link(link) - if traces.count{|_id, _manga_name, vol_value, chap_value| vol_value == data[0] && chap_value == data[1]} == 0 - prep_display = " ( link #{i + 1} / #{@links.size} )" - chapter_link(link, prep_display) - end - i += 1 - end - @aff.dump -=end - traces = @db.get_trace(@manga_data) - i = 0 - all_data = [] - @links.each do |link| - all_data << Struct::Data.new(*@manga_data.extract_values_from_link(link), link) - end - Utils_misc::sort_chapter_list(all_data).each do |data| - if traces.count{|_id, _manga_name, vol_value, chap_value| vol_value == data[:volume] && chap_value == data[:chapter]} == 0 - prep_display = " ( link #{i + 1} / #{@links.size} )" - chapter_link(data[:link], prep_display) - end - i += 1 - end - @aff.dump - end - # the update method will first check for _todo elements to download then check for missing chapters # it only calls the data method if a page was downloaded def update @@ -211,6 +202,7 @@ def data # @db => the database instance todo : delete the variable # @aff => the attached DownloadDisplay class # @doc => the first page todo : regarder si le Manga_data ne peut pas faire ça au moment de son check_link + # @_todo => an arry containing all of the _todo elements. Used to avoid downloading the same chapter twice when updating def initialize(manga, download_data = true) @manga_data = manga @downloaded_a_page = false @@ -221,6 +213,7 @@ def initialize(manga, download_data = true) # doc is the variable that stores the raw data of the manga's page @aff = DownloadDisplay.new(manga.site_dir, manga.name) @doc = Utils_connection::get_page(manga.link, true) + @todo = [] if @doc == nil raise 'failed to get manga ' + manga.name + "'s chapter index" end diff --git a/sources/Download/mangafox.rb b/sources/Download/mangafox.rb index 90e1eb5..a3aab0d 100644 --- a/sources/Download/mangafox.rb +++ b/sources/Download/mangafox.rb @@ -52,6 +52,7 @@ def page_link(link, data) def chapter_link(link, prep_display = '') # get_chapter_from_link(link, prep_display, '//div[@class="l"]', '.html') data = @manga_data.extract_values_from_link(link) + @aff.prepare_chapter("downloading #{data_to_string(data)} of #{@manga_data.name}" + prep_display) if data[0] == -42 @aff.unmanaged_link(link) false @@ -65,7 +66,6 @@ def chapter_link(link, prep_display = '') rescue RuntimeError return link_err(data, true, 'R') end - @aff.prepare_chapter("downloading #{data_to_string(data)} of #{@manga_data.name}" + prep_display) number_of_pages = page.xpath('//div[@class="l"]').text.split.last.to_i if number_of_pages == 0 return link_err(data, true, '?') diff --git a/sources/api/mangas.rb b/sources/api/mangas.rb index 46efd3e..e31f55a 100644 --- a/sources/api/mangas.rb +++ b/sources/api/mangas.rb @@ -135,7 +135,7 @@ def self.clear(mangas) # delete_files = bool, if true, the files of the manga will also be deleted def self.delete(manga_list, delete_files = true) if Utils_user_input::require_confirmation('you are about to ' + 'delete'.red + ' the following element(s) from the database' + ((delete_files) ? - ' and '.yellow + 'all of the downloaded pages' : + ' AND '.yellow + 'all of the downloaded pages' : ' but ' + 'not'.yellow + ' the downloaded files' ), manga_list) db = Manga_database.instance path = Params.instance.download[:manga_path] diff --git a/sources/html/html.rb b/sources/html/html.rb index 232112b..b29d459 100644 --- a/sources/html/html.rb +++ b/sources/html/html.rb @@ -15,6 +15,8 @@ def html_get_data(site, updated_recently = false) end source_buffer = ' ' if @html_params[:nsfw_enabled] + ret << source_buffer + else manga_genres = manga.data[9].split(', ') if (@html_params[:nsfw_categories].split(', ') & manga_genres).empty? ret << source_buffer @@ -23,8 +25,6 @@ def html_get_data(site, updated_recently = false) # warning : sites must be managed ret << ' ' end - else - ret << source_buffer end ret << '

' + Utils_file::description_manipulation(manga.name.gsub('_', ' '), 25, 3).gsub('\n', '
') + '

' ret << ' ' diff --git a/sources/html/html_manga.rb b/sources/html/html_manga.rb index bd34352..8155702 100644 --- a/sources/html/html_manga.rb +++ b/sources/html/html_manga.rb @@ -94,7 +94,7 @@ def html_generate_chapters(manga_data) def chapter_list_to_a_list(template) ret = '' buff = '' - @traces = Utils_misc::sort_chapter_list(@traces) + @traces = Utils_misc::sort_chapter_list(@traces).reverse @traces.each do |chapter| # pp chapter # exit 42 diff --git a/sources/init.rb b/sources/init.rb index 5b4761a..b53566d 100644 --- a/sources/init.rb +++ b/sources/init.rb @@ -36,10 +36,11 @@ def self.get_file_list Download/mangafox Download/mangareader_mangapanda DownloadDisplay - instructions/Parsers/Instruction_parser - instructions/Parsers/Data_parser + instructions/Parsers/exec/Instruction_parser + instructions/Parsers/exec/Data_parser instructions/Parsers/Query_Parser instructions/Parsers/File_parser + instructions/Parsers/Site_parser instructions/query instructions/Instructions_exec instructions/Manga_data_filter @@ -82,9 +83,7 @@ def self.load_relative_files end end - def self.initialize_mangascrap - load_all_gems - load_relative_files + def self.init_structures Struct.new('Arg', :name, :sub_args, :nb_args, :does_not_need_args?) Struct.new('Sub_arg', :name, :nb_args) Struct.new('Updated', :name, :downloaded) @@ -93,6 +92,13 @@ def self.initialize_mangascrap Struct.new('Data', :volume, :chapter, :page, :link) Struct.new('Todo_value', :id, :manga_id, :volume, :chapter, :page, :date) Struct.new('Param_value', :string, :id, :type, :value, :class, :min_value, :max_value) + Struct.new('Website', :link, :aliases, :dir, :to_complete, :class) + end + + def self.initialize_mangascrap + load_all_gems + load_relative_files + init_structures begin Utils_file::dir_create(Dir.home + '/.MangaScrap/db') rescue StandardError => error diff --git a/sources/instructions/Instructions_exec.rb b/sources/instructions/Instructions_exec.rb index 133e745..b8ec372 100644 --- a/sources/instructions/Instructions_exec.rb +++ b/sources/instructions/Instructions_exec.rb @@ -193,6 +193,12 @@ def get_data_parser(instruction) puts 'ignoring file instruction'.yellow end end + parser.on('site', 1) do |args| + e = Site_parser.new(args[0], @data_to_prepare) + unless e.good + puts 'ignoring site instruction'.yellow + end + end parser.on('query', 1) do |args| # <======================================================== currently a placeholder puts 'query is currently a placeholder' # query = Query_Manager.new diff --git a/sources/instructions/Parsers/Site_parser.rb b/sources/instructions/Parsers/Site_parser.rb new file mode 100644 index 0000000..68e18e7 --- /dev/null +++ b/sources/instructions/Parsers/Site_parser.rb @@ -0,0 +1,10 @@ +class Site_parser + public + def good + return true + end + + def initialize(site, data_to_prepare) + + end +end diff --git a/sources/instructions/Parsers/exec/Data_parser.rb b/sources/instructions/Parsers/exec/Data_parser.rb new file mode 100644 index 0000000..c003571 --- /dev/null +++ b/sources/instructions/Parsers/exec/Data_parser.rb @@ -0,0 +1,73 @@ +# this class is used to cut the arguments given to MangaScrap and allow +class Data_parser + private + # executes the previously parsed arguments + def run + @to_exec.each do |args| + @instructions[args[0]][1].call args[1] + end + end + + # function used to exit whenever there is not enought arguments for a data + def nb_arguments_exit(arg, qt, count) + puts 'Error :'.red + ' for instruction "' + @command.yellow + ' ' + @instruction.yellow + '"' + puts arg.yellow + ' was given ' + count.to_s.yellow + ' argument(s), ' + qt.to_s.yellow + ' are required' + puts '' + exit 4 + end + + def bad_argument_exit(error) + puts 'Error :'.red + ' for instruction "' + @command.yellow + ' ' + @instruction.yellow + '"' + unless error == nil + puts 'unrecognised argument or instruction "' + error.yellow + '"' + end + puts '' + exit 4 + end + + # the arguments are cut with the @instructions + def args_extract(arg, qt) + ret = [] # extracted arguments + count = 0 + while @args.size != 0 && count < qt + ret << @args[0] + @args.shift + count += 1 + end + if count != qt + nb_arguments_exit(arg, qt, count) + end + ret + end + + public + # gets an array of arguments and cuts it into more readable arrays witch are then used by run + def parse(args) + @args = args + @instruction = args.join(' ') + until @args.empty? + arg = @args[0] + if @instructions.key? arg + @args.shift + buff = args_extract(arg, @instructions[arg][0]) + @to_exec << [arg, buff] + else + bad_argument_exit(arg) + end + end + run + end + + # adds instruction with a block + def on(instruction, arguments, &bloc) + @instructions[instruction] = [arguments, bloc] + end + + def initialize(command) + @to_exec = [] + @instructions = {} + @args = '' + @command = command + @instruction = '' + end +end diff --git a/sources/instructions/Parsers/exec/Instruction_parser.rb b/sources/instructions/Parsers/exec/Instruction_parser.rb new file mode 100644 index 0000000..50da0d0 --- /dev/null +++ b/sources/instructions/Parsers/exec/Instruction_parser.rb @@ -0,0 +1,108 @@ +# this class is used to cut the arguments given to MangaScrap and allow +class Instruction_parser + private + # function used to exit whenever there is not enough argument for a 'jump' + # jump : number of arguments required + # prev : the argument + # parent : the instruction + def jump_error_exit(data_argument, jump, parent) + puts 'Error : '.red + data_argument.yellow + ' requires ' + jump.to_s.yellow + ' more argument(s)' + puts 'in : [' + parent + ']' + case prev + when 'id' + puts 'id '.yellow + 'requires a ' + 'name'.blue + ' ( first argument ) and a ' + 'site'.blue + ' ( second argument )' + else + # other instructions + end + exit 4 + end + + # executes the previously parsed arguments + def run + lock = true + @to_exec.each do |args| + buff = args + if lock + lock = false + puts '' + else + puts '', '', '', '', '' + end + display = 'executing : ' + buff[0].green + ' ' + buff[1].join(' ') + ' ' + @jump.each do |e| + display = display.gsub(' ' + e[0] + ' ', ' ' + e[0].yellow + ' ') # todo improve this to avoid colorizing arguments + end + puts display + puts '' + @instructions[args[0]].call args[1] + end + end + + # the arguments are cut with the @instructions + # the @jump variables are used to allow arguments ( such as a file name ) to have + # values as instructions + def args_extract(arg) + ret = [] + until @args.empty? + if @instructions.key?(@args[0]) + return ret + end + to_jump = @jump.select{|e| e[0] == @args[0]}[0] + ret << @args[0] + @args.shift + if to_jump != nil + i = 0 + while i < to_jump[1] + if @args.size == 0 + jump_error_exit(ret[0], to_jump, arg.green + ' ' + ret) + end + ret << @args[0] + @args.shift + i += 1 + end + end + end + ret + end + + public + # gets an array of arguments and cuts it into more readable arrays witch are then used by run + def parse(args) + @args = args + until @args.empty? + arg = @args[0] + if @instructions.key? arg + @args.shift + @to_exec << [arg, args_extract(arg)] + else + puts 'Error : '.red + 'unrecognised instruction "' + arg.yellow + '"' + exit 4 + end + end + run + end + + # adds instruction + def on(*args, &test) + args.each do |arg| + @instructions[arg] = test + end + end + + # this option allows for file names / site names / ... that are recognised as instructions + # ex : file update + def jump_when(data, values) + unless data != nil && data != '' && values <= 0 + @jump << [data, values] + end + end + + def initialize(nb_args = nil) + @to_exec = [] + @jump = [] + @instructions = {} + @on_array = nil + @args = '' + @nb_args = nb_args + end +end diff --git a/sources/instructions/delete_diff.rb b/sources/instructions/delete_diff.rb index f146314..0866778 100644 --- a/sources/instructions/delete_diff.rb +++ b/sources/instructions/delete_diff.rb @@ -27,7 +27,7 @@ def self.delete_diff(chap_list, manga_data) pb = trace.select{|elem| !chap_list.include?(elem)} deleted = false pb.each do |chap| - puts ('deleting volume ' + Utils_file::volume_int_to_string(chap[0]) + ' chapter ' + chap[1].to_s).yellow + puts ('deleting ' + Utils_file::volume_int_to_string(chap[0], false) + ' chapter ' + chap[1].to_s).yellow Dir.glob(Utils_file::file_name(dir, chap[0], chap[1], nil, true)).sort.each do |file| puts 'deleting file : '.yellow + file File.delete(file) diff --git a/sources/templates/text/version.txt b/sources/templates/text/version.txt index 43c2417..dabff2f 100644 --- a/sources/templates/text/version.txt +++ b/sources/templates/text/version.txt @@ -1 +1 @@ -0.12.5 +0.12.6 diff --git a/sources/unitTests/Database.rb b/sources/unitTests/Database.rb new file mode 100644 index 0000000..e69de29 diff --git a/sources/unitTests/Init.rb b/sources/unitTests/Init.rb new file mode 100644 index 0000000..cb79629 --- /dev/null +++ b/sources/unitTests/Init.rb @@ -0,0 +1,138 @@ +# this class is used by the unit tests to ensure that all of the files load correctly +class UT_Init + private + # used to display an error if the gem could not be loaded + def load_gem(gem) + begin + require gem + rescue LoadError => e + puts 'Error while loading the ' + gem + ' gem. Message is : ' + e.message + return false + end + true + end + + def load_init_file + puts '======================> 1 - requiring init file' if @verbose + begin + puts 'requiring sources/init.rb'if @verbose && @high_verbose + require_relative '../init' + rescue LoadError => e + puts 'Error while loading the init file (it should have been at : ' + Dir.pwd + '/sources/init.rb)' + puts 'aborting' + exit 1 + end + puts 'ok' if @verbose + puts '' if @verbose + end + + def require_all_gems + puts '======================> 2 requiring all gems' if @verbose + failure = false + Init::get_gem_list.each do |gem| + puts 'requiring ' + gem if @verbose && @high_verbose + failure = !(load_gem(gem) || failure) + end + if failure + puts 'aborting' + exit 2 + end + puts 'ok' if @verbose + puts '' if @verbose + end + + def require_all_mangascrap_files + puts '======================> 3 requiring all MangaScrap files' if @verbose + failure = false + Init::get_file_list.each do |file| + puts 'requiring sources/' + file if @verbose && @high_verbose + failure = !(Unit_tests_API::require_file('sources/' + file) || failure) + end + puts 'ok' if @verbose + puts '' if @verbose + end + + def get_structures + puts '======================> 4 getting the structures' if @verbose + begin + Init::init_structures + rescue Exception => e + puts 'Error' + pp e.class.to_s + pp e.message + exit 5 + end + puts 'ok' if @verbose + puts '' if @verbose + end + + def get_content_of_database + puts '======================> 5 getting the content of the database ( all of it )' if @verbose + begin + list = Manga_database.instance.get_manga_list + traces_chapters_qt = 0 + traces_pages_qt = 0 + todo_chapters_qt = 0 + todo_pages_qt = 0 + need_correction = 0 + list.each do |manga| + Manga_database.instance.get_trace(manga).each do |trace| + trace[5] == nil ? need_correction += 1 : traces_pages_qt += trace[5] + traces_chapters_qt += 1 + end + Manga_database.instance.get_todo(manga).each do |todo| + todo[4] == -1 ? todo_chapters_qt += 1 : todo_pages_qt += 1 + end + end + if @verbose + puts "found a total of #{list.size} elements in the database" + puts "there are #{traces_chapters_qt} chapters and #{traces_pages_qt} pages downloaded" + puts "#{todo_chapters_qt} chapters and #{todo_pages_qt} still need to be downloaded" + if need_correction != 0 + puts "Warning ! #{need_correction} chapters need a check ( the amount of downloaded pages is not available )" + end + end + rescue Exception => e + puts 'Error' + pp e.class.to_s + pp e.message + exit 5 + end + puts 'ok' if @verbose + puts '' if @verbose + end + + def get_params + puts '======================> 6 getting the params' if @verbose + begin + # get param class + # get sub params classes + # check params of sub params classes values + rescue Exception => e + puts 'Error' + pp e.class.to_s + pp e.message + exit 5 + end + puts 'ok' if @verbose + puts '' if @verbose + end + + public + def run + puts '####################### Basic tests' + puts '' + load_init_file + require_all_gems + require_all_mangascrap_files + get_structures + get_content_of_database + get_params + puts '####################### all good' + end + + def initialize(verbose = true, high_verbose = true) + @verbose = verbose + @high_verbose = high_verbose + end +end diff --git a/sources/unitTests/Web.rb b/sources/unitTests/Web.rb new file mode 100644 index 0000000..e69de29