
14 changed files with 193 additions and 27 deletions
@ -0,0 +1,59 @@ |
|||
|
|||
#include <apt-pkg/hashes.h> |
|||
#include <apti18n.h> |
|||
|
|||
#include "private-output.h" |
|||
#include "private-sources.h" |
|||
#include "private-utils.h" |
|||
|
|||
/* Interface discussion with donkult (for the future):
|
|||
apt [add-{archive,release,component}|edit|change-release|disable]-sources |
|||
and be clever and work out stuff from the Release file |
|||
*/ |
|||
|
|||
// EditSource - EditSourcesList /*{{{*/
|
|||
// ---------------------------------------------------------------------
|
|||
bool EditSources(CommandLine &CmdL) |
|||
{ |
|||
bool res; |
|||
pkgSourceList sl; |
|||
std::string outs; |
|||
|
|||
std::string sourceslist; |
|||
if (CmdL.FileList[1] != NULL) |
|||
{ |
|||
sourceslist = _config->FindDir("Dir::Etc::sourceparts") + CmdL.FileList[1]; |
|||
if (!APT::String::Endswith(sourceslist, ".list")) |
|||
sourceslist += ".list"; |
|||
} else { |
|||
sourceslist = _config->FindFile("Dir::Etc::sourcelist"); |
|||
} |
|||
HashString before; |
|||
if (FileExists(sourceslist)) |
|||
before.FromFile(sourceslist); |
|||
|
|||
do { |
|||
EditFileInSensibleEditor(sourceslist); |
|||
_error->PushToStack(); |
|||
res = sl.Read(sourceslist); |
|||
if (!res) { |
|||
_error->DumpErrors(); |
|||
strprintf(outs, _("Failed to parse %s. Edit again? "), |
|||
sourceslist.c_str()); |
|||
std::cout << outs; |
|||
// FIXME: should we add a "restore previous" option here?
|
|||
res = !YnPrompt(true); |
|||
} |
|||
_error->RevertToStack(); |
|||
} while (res == false); |
|||
|
|||
if (FileExists(sourceslist) && !before.VerifyFile(sourceslist)) { |
|||
strprintf( |
|||
outs, _("Your '%s' file changed, please run 'apt-get update'."), |
|||
sourceslist.c_str()); |
|||
std::cout << outs << std::endl; |
|||
} |
|||
|
|||
return true; |
|||
} |
|||
/*}}}*/ |
@ -0,0 +1,3 @@ |
|||
#include <apt-pkg/cmndline.h> |
|||
|
|||
bool EditSources(CommandLine &CmdL); |
@ -0,0 +1,50 @@ |
|||
#include <cstdlib> |
|||
|
|||
#include <apt-pkg/configuration.h> |
|||
#include <apt-pkg/fileutl.h> |
|||
#include "private-utils.h" |
|||
|
|||
|
|||
// DisplayFileInPager - Display File with pager /*{{{*/
|
|||
void DisplayFileInPager(std::string filename) |
|||
{ |
|||
std::string pager = _config->Find("Dir::Bin::Pager", |
|||
"/usr/bin/sensible-pager"); |
|||
|
|||
pid_t Process = ExecFork(); |
|||
if (Process == 0) |
|||
{ |
|||
const char *Args[3]; |
|||
Args[0] = pager.c_str(); |
|||
Args[1] = filename.c_str(); |
|||
Args[2] = 0; |
|||
execvp(Args[0],(char **)Args); |
|||
exit(100); |
|||
} |
|||
|
|||
// Wait for the subprocess
|
|||
ExecWait(Process, "sensible-pager", false); |
|||
} |
|||
/*}}}*/ |
|||
|
|||
// EditFileInSensibleEditor - Edit File with editor /*{{{*/
|
|||
void EditFileInSensibleEditor(std::string filename) |
|||
{ |
|||
std::string editor = _config->Find("Dir::Bin::Editor", |
|||
"/usr/bin/sensible-editor"); |
|||
|
|||
pid_t Process = ExecFork(); |
|||
if (Process == 0) |
|||
{ |
|||
const char *Args[3]; |
|||
Args[0] = editor.c_str(); |
|||
Args[1] = filename.c_str(); |
|||
Args[2] = 0; |
|||
execvp(Args[0],(char **)Args); |
|||
exit(100); |
|||
} |
|||
|
|||
// Wait for the subprocess
|
|||
ExecWait(Process, "sensible-editor", false); |
|||
} |
|||
/*}}}*/ |
@ -0,0 +1,11 @@ |
|||
#ifndef APT_PRIVATE_UTILS_H |
|||
#define APT_PRIVATE_UTILS_H |
|||
|
|||
#include<string> |
|||
|
|||
void DisplayFileInPager(std::string filename); |
|||
void EditFileInSensibleEditor(std::string filename); |
|||
|
|||
|
|||
|
|||
#endif |
Loading…
Reference in new issue