public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Brian Dolbec" <brian.dolbec@gmail.com>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/layman:master commit in: layman/, bin/
Date: Mon,  8 Oct 2012 22:38:29 +0000 (UTC)	[thread overview]
Message-ID: <1349735878.b2f4591004a0f16a4c348123e999b0912745833e.dol-sen@gentoo> (raw)

commit:     b2f4591004a0f16a4c348123e999b0912745833e
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Oct  8 22:37:58 2012 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Mon Oct  8 22:37:58 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/layman.git;a=commit;h=b2f45910

move the rename_db code to a standalone updater utility.

---
 bin/layman-updater |   24 +++++++++++++
 layman/db.py       |   30 +++--------------
 layman/updater.py  |   92 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 121 insertions(+), 25 deletions(-)

diff --git a/bin/layman-updater b/bin/layman-updater
new file mode 100755
index 0000000..ac9e841
--- /dev/null
+++ b/bin/layman-updater
@@ -0,0 +1,24 @@
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+################################################################################
+# LAYMAN - A UTILITY TO UPDATE LAYMAN DB's
+################################################################################
+# Distributed under the terms of the GNU General Public License v2
+#
+# Copyright:
+#             (c) 2011 Brian Dolbec
+#             Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+#             Brian Dolbec <brian.dolbec@gmail.com>
+#
+
+__version__ = "0.1"
+
+
+from layman.updater import Main
+
+
+main = Main()
+main()

diff --git a/layman/db.py b/layman/db.py
index 354481c..e2d740c 100644
--- a/layman/db.py
+++ b/layman/db.py
@@ -61,9 +61,6 @@ class DB(DbBase):
         else:
             ignore = 1
 
-        # check and handle the name change
-        #if not os.access(self.path, os.F_OK):
-        #    self.rename_db()
 
         DbBase.__init__(self,
                           config,
@@ -73,28 +70,11 @@ class DB(DbBase):
 
         self.output.debug('DB handler initiated', 6)
 
-
-    def rename_db(self):
-        """small upgrade function to handle the name change
-        for the installed xml file"""
-        if os.access(self.config['local_list'], os.F_OK):
-            self.output.info("Automatic db rename, old name was: %s"
-                % self.config['local_list'],2)
-            try:
-                os.rename(self.config['local_list'], self.path)
-                self.output.info("Automatic db rename, new installed db "
-                    "name is: %s" %self.path, 2)
-                self.output.notice('')
-                return
-            except OSError, err:
-                self.output.error("Automatic db rename failed:\n%s" %str(err))
-        else:
-            self.output.info("Automatic db rename, failed access to: %s"
-                % self.config['local_list'],2)
-        self.output.die("Please check that /etc/layman.cfg is up"
-                " to date\nThen try running layman again.\n"
-                "You may need to rename the old 'local_list' config setting"
-                " to\nthe new 'installed' config setting's filename.\n")
+        # check and handle the name change
+        if not os.access(self.config['installed'], os.F_OK) and \
+            os.access(self.config['local_list'], os.F_OK):
+                self.output.die("Please run layman-updater, "
+                    "then run layman again")
 
 
     # overrider

diff --git a/layman/updater.py b/layman/updater.py
new file mode 100644
index 0000000..48fad10
--- /dev/null
+++ b/layman/updater.py
@@ -0,0 +1,92 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+
+from sys import stderr
+import os
+import argparse
+
+from layman.config import OptionConfig
+from layman.api import LaymanAPI
+from layman.version import VERSION
+
+
+def rename_db(config, newname, output):
+    """small upgrade function to handle the name change
+    for the installed xml file"""
+    if os.access(config['local_list'], os.F_OK):
+        output.info("Automatic db rename, old name was..: %s"
+            % config['local_list'],2)
+        try:
+            os.rename(config['local_list'], newname)
+            output.info("Automatic db rename, new "
+                "name is...: %s" %newname, 2)
+            output.notice('')
+            return
+        except OSError, err:
+            output.error("Automatic db rename failed:\n%s" %str(err))
+    else:
+        output.info("Automatic db rename, failed access to: %s"
+            % config['local_list'],2)
+    output.die("Please check that /etc/layman.cfg is up"
+            " to date\nThen try running layman again.\n"
+            "You may need to rename the old 'local_list' config setting"
+            " to\nthe new 'installed' config setting's filename.\n")
+
+
+class Main(object):
+
+    def __init__(self):
+        self.parser = None
+        self.output = None
+        self.config = None
+        self.args = None
+
+    def args_parser(self):
+        self.parser = argparse.ArgumentParser(prog='layman-updater',
+            description="Layman's DB update script")
+        self.parser.add_argument("-c", "--config",
+            help='the path to config file')
+        self.parser.add_argument('--version', action='version',
+            version='%(prog)s ' + VERSION)
+        self.args = self.parser.parse_args()
+
+    def __call__(self):
+        self.args_parser()
+        options = None
+        if self.args.config:
+            options = {
+                'config': self.args.config,
+            }
+
+        self.config = OptionConfig(options=options)
+        self.config.read_config(self.config.get_defaults())
+
+        layman_inst = LaymanAPI(config=self.config)
+
+        self.output = layman_inst.output
+
+        self.rename_check()
+
+
+    def rename_check(self):
+        '''Checks for and renames the installed db if needed
+        '''
+        newname = self.config['installed']
+
+        # check and handle the name change
+        if not os.access(newname, os.F_OK):
+            if os.access(self.config['local_list'], os.F_OK):
+                self.output.info("Layman automatic db rename utility, "
+                    "performing update", 2)
+                rename_db(self.config, newname, self.output)
+        elif os.access(newname, os.F_OK) and \
+            os.access(self.config['local_list'], os.F_OK):
+            self.output.error("Automatic db rename failed: "
+                "Both old and new files exist")
+            self.output.error("Old file: %s still exists"
+                % self.config['local_list'])
+            self.output.error("New file: %s already exists" % newname)
+        else:
+            self.output.info("Automatic db rename "
+                "already updated: %s" % newname)
+        return


             reply	other threads:[~2012-10-08 22:38 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-10-08 22:38 Brian Dolbec [this message]
  -- strict thread matches above, loose matches on Subject: below --
2012-10-15  2:30 [gentoo-commits] proj/layman:master commit in: layman/, bin/ Brian Dolbec
2011-04-27 10:58 Brian Dolbec
2011-02-14  6:00 Brian Dolbec

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1349735878.b2f4591004a0f16a4c348123e999b0912745833e.dol-sen@gentoo \
    --to=brian.dolbec@gmail.com \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox