/* vim: set sw=4 sts=4 et foldmethod=syntax : *//* * Copyright (c) 2010, 2011 Ciaran McCreesh * * This file is part of the Paludis package manager. Paludis is free software; * you can redistribute it and/or modify it under the terms of the GNU General * Public License version 2, as published by the Free Software Foundation. * * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more * details. * * You should have received a copy of the GNU General Public License along with * this program; if not, write to the Free Software Foundation, Inc., 59 Temple * Place, Suite 330, Boston, MA 02111-1307 USA */#include"cmd_digest.hh"#include"exceptions.hh"#include<paludis/args/args.hh>#include<paludis/args/do_help.hh>#include<paludis/util/set.hh>#include<paludis/util/wrapped_forward_iterator.hh>#include<paludis/util/indirect_iterator-impl.hh>#include<paludis/util/visitor_cast.hh>#include<paludis/util/iterator_funcs.hh>#include<paludis/util/map.hh>#include<paludis/util/make_named_values.hh>#include<paludis/util/make_null_shared_ptr.hh>#include<paludis/name.hh>#include<paludis/environment.hh>#include<paludis/package_database.hh>#include<paludis/repository.hh>#include<paludis/generator.hh>#include<paludis/filtered_generator.hh>#include<paludis/filter.hh>#include<paludis/filter_handler.hh>#include<paludis/selection.hh>#include<paludis/user_dep_spec.hh>#include<paludis/package_id.hh>#include<paludis/mask.hh>#include<paludis/metadata_key.hh>#include<paludis/standard_output_manager.hh>#include<paludis/action.hh>#include<paludis/partially_made_package_dep_spec.hh>#include<cstdlib>#include<iostream>#include<algorithm>#include"command_command_line.hh"usingnamespacepaludis;usingnamespacecave;usingstd::cout;usingstd::endl;namespace{structDigestCommandLine:CaveCommandCommandLine{virtualstd::stringapp_name()const{return"cave digest";}virtualstd::stringapp_synopsis()const{return"Generates a digest file for a particular package in a particular repository.";}virtualstd::stringapp_description()const{return"Generates a digest file for a particular package in a particular repository.";}DigestCommandLine(){add_usage_line("cat/pkg repository");}};std::shared_ptr<OutputManager>make_standard_output_manager(constAction&){returnstd::make_shared<StandardOutputManager>();}WantPhasewant_all_phases(conststd::string&){returnwp_yes;}}intDigestCommand::run(conststd::shared_ptr<Environment>&env,conststd::shared_ptr<constSequence<std::string>>&args){DigestCommandLinecmdline;cmdline.run(args,"CAVE","CAVE_DIGEST_OPTIONS","CAVE_DIGEST_CMDLINE");if(cmdline.a_help.specified()){cout<<cmdline;returnEXIT_SUCCESS;}if(2!=std::distance(cmdline.begin_parameters(),cmdline.end_parameters()))throwargs::DoHelp("digest takes exactly two parameters");RepositoryNamerepo(*next(cmdline.begin_parameters()));Filterrepo_filter(filter::Matches(make_package_dep_spec({}).in_repository(repo),make_null_shared_ptr(),{}));QualifiedPackageNamepkg(std::string::npos==cmdline.begin_parameters()->find('/')?env->package_database()->fetch_unique_qualified_package_name(PackageNamePart(*cmdline.begin_parameters()),repo_filter):QualifiedPackageName(*cmdline.begin_parameters()));autoids((*env)[selection::AllVersionsSorted(generator::Package(pkg)&generator::InRepository(repo))]);if(ids->empty())nothing_matching_error(env.get(),*cmdline.begin_parameters(),repo_filter);for(PackageIDSequence::ConstIteratori(ids->begin()),i_end(ids->end());i!=i_end;++i){Contexti_context("When fetching ID '"+stringify(**i)+"':");FetchActiona(make_named_values<FetchActionOptions>(n::errors()=std::make_shared<Sequence<FetchActionFailure>>(),n::exclude_unmirrorable()=false,n::fetch_parts()=FetchParts()+fp_regulars+fp_extras+fp_unneeded,n::ignore_not_in_manifest()=true,n::ignore_unfetched()=false,n::make_output_manager()=&make_standard_output_manager,n::safe_resume()=true,n::want_phase()=&want_all_phases));if((*i)->supports_action(SupportsActionTest<FetchAction>())){cout<<"Fetching "<<**i<<"..."<<endl;(*i)->perform_action(a);}elsecout<<"No fetching supported for "<<**i<<endl;cout<<endl;}autor(env->package_database()->fetch_repository(repo));if(r->manifest_interface()){cout<<"Making manifest..."<<endl;r->manifest_interface()->make_manifest(pkg);}else{cout<<"Cannot make manifests for "<<repo<<endl;returnEXIT_FAILURE;}returnEXIT_SUCCESS;}std::shared_ptr<args::ArgsHandler>DigestCommand::make_doc_cmdline(){returnstd::make_shared<DigestCommandLine>();}