~ubuntu-branches/ubuntu/quantal/config-manager/quantal

« back to all changes in this revision

Viewing changes to src/ConfigSource.cc

  • Committer: Bazaar Package Importer
  • Author(s): Anand Kumria
  • Date: 2004-07-19 22:27:50 UTC
  • mto: (3.1.1 dapper)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20040719222750-sztqdj1aoj2r6frr
Tags: upstream-0.1p83
ImportĀ upstreamĀ versionĀ 0.1p83

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: fd65883c-807a-4ae7-8981-ec1e60b8e13b
 
21
 * 
 
22
 */
 
23
 
 
24
#include <iostream>
 
25
#include "ConfigSource.h"
 
26
#include "ConfigArchSource.h"
 
27
#include "ConfigCVSSource.h"
 
28
#include "ConfigSVNSource.h"
 
29
#include "ConfigWGetSource.h"
 
30
#include "FileSystemVisitor.h"
 
31
 
 
32
ConfigSource *
 
33
ConfigSource::Create(string const &url) throw(exception *)
 
34
{
 
35
    /* TODO: Registry */
 
36
 
 
37
    if (url.find(":") == string::npos) {
 
38
        return new ConfigArchSource(url);
 
39
    }
 
40
 
 
41
    if (url.find("arch://") == 0)
 
42
      return new ConfigArchSource(url.substr(7));
 
43
 
 
44
    if (url.find("pserver://") == 0)
 
45
        return new ConfigCVSSource(url);
 
46
 
 
47
    if (url.find ("ext://") == 0)
 
48
      return new ConfigCVSSource(url);
 
49
 
 
50
    if (url.find ("http://") == 0)
 
51
      return new ConfigWGetSource(url);
 
52
 
 
53
    if (url.find ("ftp://") == 0)
 
54
      return new ConfigWGetSource(url);
 
55
 
 
56
    if (url.find ("svn") == 0)
 
57
      return new ConfigSVNSource(url);
 
58
 
 
59
    throw new runtime_error("Unknown RCS URL scheme.");
 
60
}
 
61
 
 
62
/* identify the rcs system used at a specific directory.
 
63
 * basic algorithm:
 
64
 * if the dir has explicit markers for any given RCS system, use that.
 
65
 * if the dir doesn't, and there is a parent RCS source, use that.
 
66
 *
 
67
 */
 
68
ConfigSource *
 
69
ConfigSource::Create(Path const &location, ConfigSource const *parent) throw (exception *)
 
70
{
 
71
    ConfigSource *result = NULL;
 
72
    /* Try each known type */
 
73
    result = ConfigArchSource::Create(location);
 
74
    if (result)
 
75
        return result;
 
76
    result = ConfigCVSSource::Create(location, parent);
 
77
    if (result)
 
78
      {
 
79
        if (result != parent)
 
80
            return result;
 
81
        return NULL;
 
82
      }
 
83
    /* other module tests go here */
 
84
 
 
85
    return NULL;
 
86
}
 
87
 
 
88
int
 
89
ConfigSource::run_query (string const &command, string const &type) const
 
90
{
 
91
    if (Verbose())
 
92
        cout << "Executing '" << command << "'" << endl;
 
93
 
 
94
    int result = system(command.c_str());
 
95
 
 
96
    if (result == -1)
 
97
        throw new runtime_error(type + " command execution failed");
 
98
 
 
99
    return WEXITSTATUS(result);
 
100
}
 
101
 
 
102
void
 
103
ConfigSource::run (string const &command, string const &type) const
 
104
{
 
105
    if (run_query(command, type) != 0)
 
106
        throw new runtime_error("Error returned by " + type + " command");
 
107
}
 
108
 
 
109
void
 
110
ConfigSource::Verbose(bool const &aBool)
 
111
{
 
112
  Verbose_ = aBool;
 
113
}
 
114
 
 
115
bool
 
116
ConfigSource::Verbose()
 
117
{
 
118
  return Verbose_;
 
119
}
 
120
 
 
121
bool ConfigSource::Verbose_ = false;