~ubuntu-branches/ubuntu/jaunty/synaptic/jaunty

« back to all changes in this revision

Viewing changes to common/rpackagestatus.cc

  • Committer: Bazaar Package Importer
  • Author(s): Michael Vogt
  • Date: 2008-08-22 12:40:10 UTC
  • Revision ID: james.westby@ubuntu.com-20080822124010-5z3kuzjp2jozl13a
Tags: 0.62.1ubuntu8
* common/rpackageview.cc:
  - add new "Missing Recommends" default filter
* common/rpackage.cc:
  - fix code to get candidate origin
  - support getting the candidate release file name
* common/rpackagestatus.cc:
  - support maintenanceEndTime() (if the distro supports that)
* 10_ubuntu_maintenance_gui.dpatch:
  - add support for displaying when the maintaince ends

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* rpackagestatus.cc - wrapper for accessing packagestatus information
 
2
 * 
 
3
 * Copyright (c) 2000-2003 Conectiva S/A 
 
4
 *               2002-2008 Michael Vogt <mvo@debian.org>
 
5
 * 
 
6
 * Author: Alfredo K. Kojima <kojima@conectiva.com.br>
 
7
 *         Michael Vogt <mvo@debian.org>
 
8
 * 
 
9
 * Portions Taken from Gnome APT
 
10
 *   Copyright (C) 1998 Havoc Pennington <hp@pobox.com>
 
11
 * 
 
12
 *
 
13
 * This program is free software; you can redistribute it and/or 
 
14
 * modify it under the terms of the GNU General Public License as 
 
15
 * published by the Free Software Foundation; either version 2 of the
 
16
 * License, or (at your option) any later version.
 
17
 *
 
18
 * This program is distributed in the hope that it will be useful,
 
19
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
20
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
21
 * GNU General Public License for more details.
 
22
 *
 
23
 * You should have received a copy of the GNU General Public License
 
24
 * along with this program; if not, write to the Free Software
 
25
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
 
26
 * USA
 
27
 */
 
28
 
 
29
#include <apt-pkg/tagfile.h>
 
30
#include <apt-pkg/strutl.h>
 
31
#include "rpackagestatus.h"
 
32
 
 
33
// class that finds out what do display to get user
 
34
void RPackageStatus::init()
 
35
{
 
36
   const char *status_short[N_STATUS_COUNT] = {
 
37
      "install", "reinstall", "upgrade", "downgrade", "remove",
 
38
      "purge", "available", "available-locked",
 
39
      "installed-updated", "installed-outdated", "installed-locked",
 
40
      "broken", "new"
 
41
   };
 
42
   memcpy(PackageStatusShortString, status_short, sizeof(status_short));
 
43
 
 
44
   const char *status_long[N_STATUS_COUNT] = {
 
45
      _("Marked for installation"),
 
46
      _("Marked for re-installation"),
 
47
      _("Marked for upgrade"),
 
48
      _("Marked for downgrade"),
 
49
      _("Marked for removal"),
 
50
      _("Marked for complete removal"),
 
51
      _("Not installed"),
 
52
      _("Not installed (locked)"),
 
53
      _("Installed"),
 
54
      _("Installed (upgradable)"),
 
55
      _("Installed (locked to the current version)"),
 
56
      _("Broken"),
 
57
      _("Not installed (new in repository)")
 
58
   };
 
59
   memcpy(PackageStatusLongString, status_long, sizeof(status_long));
 
60
 
 
61
 
 
62
   // check for unsupported stuff
 
63
   if(_config->FindB("Synaptic::mark-unsupported",true)) {
 
64
      string s, labels, components;
 
65
      markUnsupported = true;
 
66
 
 
67
      // read supported labels
 
68
      labels = _config->Find("Synaptic::supported-label", "Debian Debian-Security");
 
69
      stringstream sst1(labels);
 
70
      while(!sst1.eof()) {
 
71
         sst1 >> s;
 
72
         supportedLabels.push_back(s);
 
73
      }
 
74
      
 
75
      // read supported components
 
76
      components = _config->Find("Synaptic::supported-components", "main updates/main");
 
77
      stringstream sst2(components);
 
78
      while(!sst2.eof()) {
 
79
         sst2 >> s;
 
80
         supportedComponents.push_back(s);
 
81
      }
 
82
   } 
 
83
 
 
84
}
 
85
 
 
86
bool RPackageStatus::isSupported(RPackage *pkg) 
 
87
{
 
88
   bool res = true;
 
89
 
 
90
   if(markUnsupported) {
 
91
      bool sc, sl;
 
92
 
 
93
      sc=sl=false;
 
94
 
 
95
      string component = pkg->component();
 
96
      string label = pkg->label();
 
97
 
 
98
      for(unsigned int i=0;i<supportedComponents.size();i++) {
 
99
         if(supportedComponents[i] == component) {
 
100
            sc = true;
 
101
            break;
 
102
         }
 
103
      }
 
104
      for(unsigned int i=0;i<supportedLabels.size();i++) {
 
105
         if(supportedLabels[i] == label) {
 
106
            sl = true;
 
107
            break;
 
108
         }
 
109
      }
 
110
      res = (sc & sl & pkg->isTrusted());
 
111
   }
 
112
 
 
113
   return res;
 
114
}
 
115
 
 
116
int RPackageStatus::getStatus(RPackage *pkg)
 
117
{
 
118
   int flags = pkg->getFlags();
 
119
   int ret = NotInstalled;
 
120
 
 
121
   if (pkg->wouldBreak()) {
 
122
      ret = IsBroken;
 
123
   } else if (flags & RPackage::FNewInstall) {
 
124
      ret = ToInstall;
 
125
   } else if (flags & RPackage::FUpgrade) {
 
126
      ret = ToUpgrade;
 
127
   } else if (flags & RPackage::FReInstall) {
 
128
      ret = ToReInstall;
 
129
   } else if (flags & RPackage::FDowngrade) {
 
130
      ret = ToDowngrade;
 
131
   } else if (flags & RPackage::FPurge) {
 
132
      ret = ToPurge;
 
133
   } else if (flags & RPackage::FRemove) {
 
134
      ret = ToRemove;
 
135
   } else if (flags & RPackage::FInstalled) {
 
136
      if (flags & RPackage::FPinned)
 
137
         ret = InstalledLocked;
 
138
      else if (flags & RPackage::FOutdated)
 
139
         ret = InstalledOutdated;
 
140
      else
 
141
         ret = InstalledUpdated;
 
142
   } else {
 
143
      if (flags & RPackage::FPinned)
 
144
         ret = NotInstalledLocked;
 
145
      else if (flags & RPackage::FNew)
 
146
         ret = IsNew;
 
147
      else
 
148
         ret = NotInstalled;
 
149
   }
 
150
 
 
151
   return ret;
 
152
}
 
153
 
 
154
bool RPackageStatus::maintenanceEndTime(RPackage *pkg, struct tm *res) 
 
155
{
 
156
   pkgTagSection sec;
 
157
   time_t release_date = -1;
 
158
 
 
159
   string releaseFile = pkg->getCandidateReleaseFile();
 
160
   if(!FileExists(releaseFile)) {
 
161
      cerr << "mainenanceEndTime(): can not find " << releaseFile << endl;
 
162
      return false;
 
163
   }
 
164
   
 
165
   // read the relase file
 
166
   FileFd fd(releaseFile, FileFd::ReadOnly);
 
167
   pkgTagFile t(&fd);
 
168
   t.Step(sec);
 
169
 
 
170
 
 
171
   // get the time_t form the string
 
172
   if(!StrToTime(sec.FindS("Date"), release_date))
 
173
      return false;
 
174
 
 
175
   // if its not a supported package, return 0 
 
176
   if(!isSupported(pkg))
 
177
      return false;
 
178
 
 
179
   // now calculate the time until there is support
 
180
   gmtime_r(&release_date, res);
 
181
   
 
182
   const int support_time =_config->FindI("Synaptic::supported-month", 0);
 
183
   if (support_time <= 0)
 
184
      return false;
 
185
 
 
186
   res->tm_year += (support_time / 12) + ((res->tm_mon + support_time % 12) / 12);
 
187
   res->tm_mon = (res->tm_mon + support_time) % 12;
 
188
 
 
189
   return true;
 
190
}