~ubuntu-branches/ubuntu/intrepid/config-manager/intrepid

« back to all changes in this revision

Viewing changes to ConfigArchSource.cc

  • Committer: Bazaar Package Importer
  • Author(s): Anand Kumria
  • Date: 2004-01-14 02:46:24 UTC
  • Revision ID: james.westby@ubuntu.com-20040114024624-x9lrmmjqcpc7fip1
Tags: upstream-0.1p53
ImportĀ upstreamĀ versionĀ 0.1p53

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (C) 2003  Robert Collins  <robertc@squid-cache.org>
 
3
 * 
 
4
 * 
 
5
 * This program is free software; you can redistribute it and/or modify
 
6
 * it under the terms of the GNU General Public License as published by
 
7
 * the Free Software Foundation; either version 2 of the License, or
 
8
 * (at your option) any later version.
 
9
 * 
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 * 
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 * 
 
19
 * DO NOT ALTER THE NEXT LINE
 
20
 * arch-tag: 21df1c64-1d6a-4476-ad3a-e451889d3da8
 
21
 * 
 
22
 */
 
23
 
 
24
#include "ConfigArchSource.h"
 
25
#include <iostream>
 
26
#include <stdexcept>
 
27
#include <fstream>
 
28
#include "Path.h"
 
29
 
 
30
using namespace std;
 
31
 
 
32
/* ConfigArchSource */
 
33
StringOption ConfigArchSource::buildOptions("",'a',"arch-build-options", "Options to pass to tla get.");
 
34
 
 
35
ConfigArchSource::ConfigArchSource() : theUrl(), location()
 
36
{
 
37
}
 
38
 
 
39
ConfigArchSource::ConfigArchSource(string const &aUrl) : theUrl(aUrl)
 
40
{
 
41
    if (theUrl.find("arch://") == 0)
 
42
        theUrl.erase(0,7);
 
43
    /* We only support @ location syntax in full archive paths */
 
44
    if (theUrl.find("@") != theUrl.rfind("@"))
 
45
      {
 
46
        string::size_type pos = theUrl.find("@", theUrl.find("@") + 1);
 
47
        location = theUrl.substr(pos + 1);
 
48
        theUrl.erase(pos);
 
49
        if (Verbose())
 
50
            cout << "Found archive " << theUrl << " location at " << location << endl;
 
51
      }
 
52
}
 
53
 
 
54
string
 
55
ConfigArchSource::url(bool const &stripScheme) const
 
56
{
 
57
    return (stripScheme ? "" : "arch://") + theUrl;
 
58
}
 
59
 
 
60
string
 
61
ConfigArchSource::archive() const
 
62
{
 
63
    return theUrl;
 
64
}
 
65
 
 
66
void
 
67
ConfigArchSource::maybeRegister() const
 
68
{
 
69
    string command = "tla whereis-archive `tla parse-package-name -a " + archive() + "` > /dev/null";
 
70
    if (run_query (command, "tla") != 0)
 
71
        run ("tla register-archive `tla parse-package-name -a " + archive() + "` " + location ,  "tla");
 
72
}
 
73
 
 
74
void
 
75
ConfigArchSource::get (string const &where) const throw(std::exception *)
 
76
{
 
77
    maybeRegister();
 
78
    string command = "tla get " + (string)buildOptions + " " + archive() + " " + where;
 
79
    run (command, "tla");
 
80
}
 
81
 
 
82
void
 
83
ConfigArchSource::update (string const &where) const throw(std::exception *)
 
84
{
 
85
    maybeRegister();
 
86
    string command = "tla update " + (string)buildOptions + " -d " + where + " " + archive();
 
87
    run (command, "tla");
 
88
}
 
89
 
 
90
int
 
91
ConfigArchSource::missing (string const &where) const throw(std::exception *)
 
92
{
 
93
    maybeRegister();
 
94
    string command = "tla missing " + (string)buildOptions + " -d " + where + " " + archive();
 
95
    return run_query (command, "tla");
 
96
}
 
97
 
 
98
int
 
99
ConfigArchSource::changes (string const &where) const throw(std::exception *)
 
100
{
 
101
    maybeRegister();
 
102
    string command = "tla changes " + (string)buildOptions + " -d " + where + " " + archive();
 
103
    return run_query (command, "tla");
 
104
}
 
105
 
 
106
string
 
107
ConfigArchSource::treeVersion(string const &where) const
 
108
{
 
109
    string command = "tla logs -f -r -d " + where + " | head -n1 > ,,config-tree";
 
110
    run(command, "tla");
 
111
 
 
112
    ifstream resultbuffer(",,config-tree");
 
113
    string result;
 
114
    resultbuffer >> result;
 
115
    resultbuffer.close();
 
116
    unlink(",,config-tree");
 
117
    return result;
 
118
}
 
119
 
 
120
void
 
121
ConfigArchSource::ignore (ConfigSource const* aSource, string const &where) const throw (std::exception *)
 
122
{
 
123
    if (dynamic_cast<ConfigArchSource const *>( aSource))
 
124
        return;
 
125
    
 
126
    ifstream projtreetest((where + "/{arch}/.arch-project-tree").c_str());
 
127
    if (projtreetest.is_open())
 
128
      {
 
129
        std::cerr << "Warning: '" << where << "' is already an arch project tree. Consider using an arch:// source in the config." << std::endl;
 
130
      }
 
131
      
 
132
    string command = "tla init-tree --nested -d " + where;
 
133
    run (command, "tla");
 
134
    ofstream taggingMethod((where + "/{arch}/=tagging-method").c_str());
 
135
    taggingMethod << dummyTaggingText;
 
136
    std::cout << "Created a dummy tagging file for " << where << "/{arch}/=tagging-method" << endl;
 
137
}
 
138
 
 
139
char const * ConfigArchSource::dummyTaggingText=
 
140
"# this is a GNU Arch configuration file. It's been placed here by\n"
 
141
"# config-manager because this directory was created as part of a\n"
 
142
"# build operation, to ensure that Arch ignores this sub-tree.\n"
 
143
"explicit\n"
 
144
"untagged-source precious\n"
 
145
"exclude ^.*$\n"
 
146
"junk ^$\n"
 
147
"precious ^.*$\n"
 
148
"backup ^$\n"
 
149
"unrecognized ^$\n"
 
150
"source ^$\n";
 
151
 
 
152
ConfigArchSource*
 
153
ConfigArchSource::Create(Path const &location) throw (std::exception *)
 
154
{
 
155
    ifstream projtreetest((location.fullName() + "/{arch}/++default-version").c_str());
 
156
    if (!projtreetest.is_open())
 
157
        return NULL;
 
158
 
 
159
    ConfigArchSource *result = new ConfigArchSource;
 
160
    result->theUrl = result->treeVersion(location.fullName());
 
161
    result->location = "";
 
162
    return result;
 
163
}