]> git.saurik.com Git - apt.git/commitdiff
add basic "edit-sources" command
authorMichael Vogt <mvo@debian.org>
Mon, 25 Nov 2013 07:36:57 +0000 (08:36 +0100)
committerMichael Vogt <mvo@debian.org>
Mon, 25 Nov 2013 07:36:57 +0000 (08:36 +0100)
apt-private/makefile
apt-private/private-utils.cc [new file with mode: 0644]
apt-private/private-utils.h [new file with mode: 0644]
cmdline/apt-get.cc
cmdline/apt.cc

index 1d179f0b2026a31ca20960291d528bf496e0cac9..b3d764097d57bfa2e5e4e2921eb34fc3afb8dd10 100644 (file)
@@ -17,7 +17,7 @@ MAJOR=0.0
 MINOR=0
 SLIBS=$(PTHREADLIB) -lapt-pkg
 
-PRIVATES=list install download output cachefile cacheset update upgrade cmndline moo search show main
+PRIVATES=list install download output cachefile cacheset update upgrade cmndline moo search show main utils
 SOURCE += $(foreach private, $(PRIVATES), private-$(private).cc)
 HEADERS += $(foreach private, $(PRIVATES), private-$(private).h)
 
diff --git a/apt-private/private-utils.cc b/apt-private/private-utils.cc
new file mode 100644 (file)
index 0000000..813f193
--- /dev/null
@@ -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);
+}
+                                                                       /*}}}*/
diff --git a/apt-private/private-utils.h b/apt-private/private-utils.h
new file mode 100644 (file)
index 0000000..258dd06
--- /dev/null
@@ -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
index 15373b0504791531123e3a480686a08051a9ab0a..912b2d6099f2a434bc0ffcecc23efdf41aeb6d51 100644 (file)
@@ -59,6 +59,7 @@
 #include <apt-private/private-update.h>
 #include <apt-private/private-cmndline.h>
 #include <apt-private/private-moo.h>
+#include <apt-private/private-utils.h>
 
 #include <apt-private/acqprogress.h>
 
@@ -1378,24 +1379,6 @@ bool DownloadChangelog(CacheFile &CacheFile, pkgAcquire &Fetcher,
    return _error->Error("changelog download failed");
 }
                                                                        /*}}}*/
-// DisplayFileInPager - Display File with pager                                /*{{{*/
-void DisplayFileInPager(string filename)
-{
-   pid_t Process = ExecFork();
-   if (Process == 0)
-   {
-      const char *Args[3];
-      Args[0] = "/usr/bin/sensible-pager";
-      Args[1] = filename.c_str();
-      Args[2] = 0;
-      execvp(Args[0],(char **)Args);
-      exit(100);
-   }
-         
-   // Wait for the subprocess
-   ExecWait(Process, "sensible-pager", false);
-}
-                                                                       /*}}}*/
 // DoChangelog - Get changelog from the command line                   /*{{{*/
 // ---------------------------------------------------------------------
 bool DoChangelog(CommandLine &CmdL)
index e30967ec216be1770d07f4ec74c998d28824bbce..ef31d002934f162b65a30e47fe7c5c2eb2362028 100644 (file)
 #include <apt-private/private-upgrade.h>
 #include <apt-private/private-show.h>
 #include <apt-private/private-main.h>
+#include <apt-private/private-utils.h>
                                                                        /*}}}*/
 
+// EditSource - EditSourcesList                                        /*{{{*/
+// ---------------------------------------------------------------------
+bool EditSources(CommandLine &CmdL)
+{
+   // FIXME: suport CmdL.FileList to specify sources.list.d files
+
+   std::string sourceslist = _config->FindFile("Dir::Etc::sourcelist");
+
+   // FIXME: take hash before, 
+   //        when changed display message to apt update
+   //        do syntax check after save (like visudo)
+
+   EditFileInSensibleEditor(sourceslist);
+
+   return true;
+}
+                                                                       /*}}}*/
+
+
 bool ShowHelp(CommandLine &CmdL)
 {
    ioprintf(c1out,_("%s %s for %s compiled on %s %s\n"),PACKAGE,PACKAGE_VERSION,
@@ -74,6 +94,8 @@ bool ShowHelp(CommandLine &CmdL)
       " update - update list of available packages\n"
       " install - install packages\n"
       " upgrade - upgrade the systems packages\n"
+      "\n"
+      " edit-sources - edit the source information file\n"
        );
    
    return true;
@@ -89,6 +111,8 @@ int main(int argc, const char *argv[])                                       /*{{{*/
                                    {"remove", &DoInstall},
                                    {"update",&DoUpdate},
                                    {"upgrade",&DoUpgradeWithAllowNewPackages},
+                                   // misc
+                                   {"edit-sources",&EditSources},
                                    // helper
                                    {"moo",&DoMoo},
                                    {"help",&ShowHelp},