aboutsummaryrefslogtreecommitdiff
path: root/paludis/environments/no_config/registration.cc
blob: 0f6f74b25ec897d7b143d1dddcbef7840e035426 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2007, 2008, 2009, 2010 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 <paludis/environments/no_config/no_config_environment.hh>
#include <paludis/environment_factory.hh>
#include <paludis/util/map.hh>
#include <paludis/util/set.hh>
#include <paludis/util/tokeniser.hh>
#include <paludis/util/destringify.hh>
#include <paludis/util/sequence.hh>
#include <paludis/util/make_named_values.hh>
#include <list>
#include "config.h"

using namespace paludis;

namespace
{
    std::shared_ptr<Environment>
    make_no_config_environment(const std::string & s)
    {
        Context context("When making NoConfigEnvironment using spec '" + s + "':");

        std::shared_ptr<Map<std::string, std::string> > extra_params(
                std::make_shared<Map<std::string, std::string>>());
        FSPath repository_dir(FSPath::cwd());
        std::shared_ptr<FSPathSequence> extra_repository_dirs(std::make_shared<FSPathSequence>());
        FSPath write_cache("/var/empty");
        std::string profile;
        std::string master_repository_name;
        bool disable_metadata_cache(false);
        bool accept_unstable(false);
        no_config_environment::RepositoryType repository_type(no_config_environment::ncer_auto);
        std::string extra_accept_keywords;

        std::list<std::string> tokens;
        tokenise<delim_kind::AnyOfTag, delim_mode::DelimiterTag>(s, ":", "", std::back_inserter(tokens));
        for (std::list<std::string>::const_iterator t(tokens.begin()), t_end(tokens.end()) ;
                t != t_end ; ++t)
        {
            std::string::size_type p(t->find('='));
            if (std::string::npos == p)
                repository_dir = FSPath(*t);
            else
            {
                std::string key(t->substr(0, p)), value(t->substr(p + 1));

                if (key == "write-cache")
                    write_cache = FSPath(value);
                else if (key == "master-repository-name")
                    master_repository_name = value;
                else if (key == "master-repository-dir")
                    throw ConfigurationError("NoConfigEnvironment key master-repository-dir is no longer "
                            "supported, use master-repository-name and extra-repository-dir");
                else if (key == "extra-repository-dir")
                    extra_repository_dirs->push_back(FSPath(value));
                else if (key == "profile")
                    profile = value;
                else if (key == "repository-dir")
                    repository_dir = FSPath(value);
                else if (key == "disable-metadata-cache")
                    disable_metadata_cache = destringify<bool>(value);
                else if (key == "accept-unstable")
                    accept_unstable = destringify<bool>(value);
                else if (key == "repository-type")
                    repository_type = destringify<no_config_environment::RepositoryType>(value);
                else if (key == "extra-accept-keywords")
                    extra_accept_keywords = value;
                else
                    extra_params->insert(key, value);
            }
        }

        return std::make_shared<NoConfigEnvironment>(
                make_named_values<no_config_environment::Params>(
                    n::accept_unstable() = accept_unstable,
                    n::disable_metadata_cache() = disable_metadata_cache,
                    n::extra_accept_keywords() = extra_accept_keywords,
                    n::extra_params() = extra_params,
                    n::extra_repository_dirs() = extra_repository_dirs,
                    n::master_repository_name() = master_repository_name,
                    n::profiles_if_not_auto() = profile,
                    n::repository_dir() = repository_dir,
                    n::repository_type() = repository_type,
                    n::write_cache() = write_cache
                    ));
    }
}

namespace paludis
{
    namespace environment_groups
    {
        ENVIRONMENT_GROUPS_DECLS;
    }

    template <>
    void register_environment<environment_groups::no_config>(const environment_groups::no_config * const,
            EnvironmentFactory * const factory)
    {
        std::shared_ptr<Set<std::string> > no_config_formats(std::make_shared<Set<std::string>>());
        no_config_formats->insert("no_config");
        no_config_formats->insert("no-config");
        factory->add_environment_format(no_config_formats, &make_no_config_environment);
    }
}