[gentoo-commits] proj/layman:master commit in: layman/

2020-04-24 Thread Brian Dolbec
commit: e4de947fd48a95b078e7d6a35099e200e6f19a02
Author: Brian Dolbec  gentoo  org>
AuthorDate: Fri Apr 24 12:36:33 2020 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Fri Apr 24 13:56:34 2020 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=e4de947f

layman/config.py: Fix py3.7, py3.8 ConfigParser error

Newer pythons require string defaults only.
The final config instance variable is either a NoneType or list

Signed-off-by: Brian Dolbec  gentoo.org>

 layman/config.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/config.py b/layman/config.py
index 853e22f..bc3172b 100644
--- a/layman/config.py
+++ b/layman/config.py
@@ -96,7 +96,7 @@ class BareConfig(object):
 'cache' : '%(storage)s/cache',
 'local_list': '%(storage)s/overlays.xml',
 'installed': '%(storage)s/installed.xml',
-'protocol_filter': [],
+'protocol_filter': '',
 'auto_sync': 'No',
 'check_official': 'Yes',
 'conf_type': 'repos.conf',



[gentoo-commits] proj/layman:master commit in: layman/tests/

2020-04-24 Thread Brian Dolbec
commit: c381b3ff58236f4243bfec6eb206cbee968d8779
Author: Brian Dolbec  gentoo  org>
AuthorDate: Fri Apr 24 12:33:00 2020 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Fri Apr 24 13:54:16 2020 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=c381b3ff

test/external.py: Remove __future__ imports

Remove unused resetwarnings() call since unittest.main() does a sys.exit()

Signed-off-by: Brian Dolbec  gentoo.org>

 layman/tests/external.py | 6 +-
 1 file changed, 1 insertion(+), 5 deletions(-)

diff --git a/layman/tests/external.py b/layman/tests/external.py
index f2b18cd..e6f408d 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -14,9 +14,6 @@
 # Sebastian Pipping 
 #
 
-from __future__ import print_function
-from __future__ import unicode_literals
-
 '''Runs external (non-doctest) test cases.'''
 
 import os
@@ -452,7 +449,7 @@ class FetchRemoteList(unittest.TestCase):
 available = api.get_available()
 self.assertEqual(available, ['wrobel', 'wrobel-stable'])
 
-
+
 # Test the info of an overlay.
 info = api.get_info_str(['wrobel'], verbose=True, local=False)
 test_info = 'wrobel\n~~\nSource  : https://overlays.gentoo.org'\
@@ -769,4 +766,3 @@ class RemoteDBCache(unittest.TestCase):
 if __name__ == '__main__':
 filterwarnings('ignore')
 unittest.main()
-resetwarnings()



[gentoo-commits] proj/layman:master commit in: layman/

2020-04-24 Thread Brian Dolbec
commit: 8c4e2883180ad126d8b334d82898622dad9d0b47
Author: Brian Dolbec  gentoo  org>
AuthorDate: Fri Apr 24 13:03:33 2020 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Fri Apr 24 13:57:26 2020 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=8c4e2883

Update version for a release

Signed-off-by: Brian Dolbec  gentoo.org>

 layman/version.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/version.py b/layman/version.py
index 402a339..966582c 100644
--- a/layman/version.py
+++ b/layman/version.py
@@ -24,7 +24,7 @@ from __future__ import unicode_literals
 __version__ = "$Id: version.py 309 2007-04-09 16:23:38Z wrobel $"
 
 
-VERSION = '2.4.2'
+VERSION = '2.4.3'
 
 if __name__ == '__main__':
 print(VERSION)



[gentoo-commits] proj/layman:master commit in: layman/overlays/, layman/

2020-04-24 Thread Brian Dolbec
commit: ae11c78123120e8c0a399e806dad224504aad574
Author: Brian Dolbec  gentoo  org>
AuthorDate: Fri Apr 24 12:35:38 2020 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Fri Apr 24 13:56:12 2020 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=ae11c781

Add additional debug statements to trace a py3.7, py3.8 error

Signed-off-by: Brian Dolbec  gentoo.org>

 layman/db.py   |  1 +
 layman/overlays/overlay.py | 19 ++-
 layman/remotedb.py |  5 -
 3 files changed, 19 insertions(+), 6 deletions(-)

diff --git a/layman/db.py b/layman/db.py
index d67ea87..9b32952 100644
--- a/layman/db.py
+++ b/layman/db.py
@@ -111,6 +111,7 @@ class DB(DbBase):
 if overlay.name not in self.overlays.keys():
 if not self._check_official(overlay):
 return False
+self.output.debug('RemoteDB.__init__(), DB.add overlay.add() 
call', 4)
 result = overlay.add(self.config['storage'])
 if result == 0:
 if 'priority' in self.config.keys():

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 9cbeb99..03829a8 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -95,8 +95,9 @@ class Overlay(object):
 def add(self, base):
 res = 1
 first_s = True
-
+self.output.debug('Overlay.add()', 5)
 self.sources = self.filter_protocols(self.sources)
+self.output.debug('Overlay.add(), filtered protocols, sources:' + 
str(self.sources), 5)
 if not self.sources:
 msg = 'Overlay.add() error: overlay "%(name)s" does not support '\
   ' the given\nprotocol(s) %(protocol)s and cannot be '\
@@ -110,10 +111,12 @@ class Overlay(object):
 if not first_s:
 self.output.info('\nTrying next source of listed sources...', 
4)
 try:
+self.output.debug('Overlay.add(), s.add(base)', 5)
 res = s.add(base)
 if res == 0:
 # Worked, throw other sources away
 self.sources = [s]
+self.output.debug('Overlay.add(), back from s.add(base)', 
5)
 break
 except Exception as error:
 self.output.warn(str(error), 4)
@@ -132,11 +135,17 @@ class Overlay(object):
 from the overlay's sources.
 '''
 _sources = []
-if not self.config['protocol_filter']:
+self.output.debug('Overlay.filter_protocols()', 5)
+self.output.debug('Overlay.filter_protocols() filters:' + 
str(type(self.config['protocol_filter'])), 5)
+if not self.config['protocol_filter'] and not 
self.config['protocol_filter'] == []:
+self.output.debug('Overlay.filter_protocols() no protocol_filter, 
returning', 5)
 return sources
-
+self.output.debug('Overlay.filter_protocols() sources:' + 
str(sources), 5)
 for source in sources:
+self.output.debug('Overlay.filter_protocols() source:' + 
str(type(source)), 5)
+self.output.debug('Overlay.filter_protocols() filters:' + 
str(self.config['protocol_filter']), 5)
 for protocol in self.config['protocol_filter']:
+self.output.debug('Overlay.filter_protocols() protocol: ' + 
protocol + ' ' + str(type(protocol)), 5)
 protocol = protocol.lower()
 #re.search considers "\+" as the literal "+".
 if protocol == 'git+ssh':
@@ -144,7 +153,7 @@ class Overlay(object):
 protocol += '://'
 if re.search('^' + protocol, source.src):
 _sources.append(source)
-
+self.output.debug('Overlay.filter_protocols(), returning sources' + 
str(_sources), 5)
 return _sources
 
 
@@ -792,7 +801,7 @@ class Overlay(object):
 try:
 res = self.sources[0].update(base, src)
 if res == 0:
-# Updating it worked, no need to bother 
+# Updating it worked, no need to bother
 # checking other sources.
 self.sources[0].src = src
 result = True

diff --git a/layman/remotedb.py b/layman/remotedb.py
index 2df0c63..6e75bec 100644
--- a/layman/remotedb.py
+++ b/layman/remotedb.py
@@ -83,15 +83,18 @@ class RemoteDB(DbBase):
 self.output.debug('RemoteDB.__init__(), paths to load = %s' 
%str(paths),
 2)
 if config['nocheck']:
+self.output.debug('RemoteDB.__init__(), ignore = 2', 5)
 ignore = 2
 else:
+self.output.debug('RemoteDB.__init__(), ignore = 0', 5)
 ignore = 0
 
 #quiet = int(config['quietness']) < 3
-
+self.output.debug('RemoteDB.__init__(), DbBase.__init__() call', 5)
 DbBase.__init__(self, config, paths=paths, 

[gentoo-commits] proj/layman:master commit in: /, layman/

2017-03-22 Thread Brian Dolbec
commit: e5cfa68f40bc05a771511c2d799d714d86fbdef0
Author: Brian Dolbec  gentoo  org>
AuthorDate: Wed Mar 22 06:35:21 2017 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Wed Mar 22 06:35:21 2017 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=e5cfa68f

Add a .gitignore, remove ols .svn.ignore

 .svn.ignore   | 2 --
 layman/.gitignore | 7 +++
 2 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/.svn.ignore b/.svn.ignore
deleted file mode 100644
index eaea68a..000
--- a/.svn.ignore
+++ /dev/null
@@ -1,2 +0,0 @@
-MANIFEST
-dist

diff --git a/layman/.gitignore b/layman/.gitignore
new file mode 100644
index 000..675ba59
--- /dev/null
+++ b/layman/.gitignore
@@ -0,0 +1,7 @@
+*.py[co]
+__pycache__/
+*.class
+*.so
+/build
+/tags
+setup.cfg



[gentoo-commits] proj/layman:master commit in: layman/

2017-03-22 Thread Brian Dolbec
commit: e5a21d0da92e258e375d49c6a606ad740933f0ff
Author: Brian Dolbec  gentoo  org>
AuthorDate: Wed Mar 22 06:28:25 2017 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Wed Mar 22 06:28:25 2017 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=e5a21d0d

api.py: Fix typo in string substitution dictionary

 layman/api.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/api.py b/layman/api.py
index 73fb72a..574e25a 100755
--- a/layman/api.py
+++ b/layman/api.py
@@ -399,7 +399,7 @@ class LaymanAPI(object):
 #self._error(str(error))
 fatals.append((ovl,
 'Failed to select overlay "%(repo)s".\nError was: 
%(error)s'
- % {'repo': ovl, 'err': error}))
+ % {'repo': ovl, 'error': error}))
 self.output.debug("API.sync(); UnknownOverlayException "
 "selecting %(repo)s.   continuing to next ovl..."
 % {'repo': ovl}, 5)



[gentoo-commits] proj/layman:master commit in: layman/

2017-02-02 Thread Brian Dolbec
commit: e90bacf006e4ae4842f8dc49fb763513898f37e0
Author: Brian Dolbec  gentoo  org>
AuthorDate: Thu Feb  2 17:00:30 2017 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Thu Feb  2 17:06:49 2017 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=e90bacf0

layman/cli.py: Typo fix

 layman/cli.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/cli.py b/layman/cli.py
index 86d6e70..870255f 100644
--- a/layman/cli.py
+++ b/layman/cli.py
@@ -164,7 +164,7 @@ class Main(object):
 
 # Make fetching the overlay list a default action
 if not 'nofetch' in self.config.keys():
-# Actions that implicitely call the fetch operation before
+# Actions that implicitly call the fetch operation before
 fetch_actions = ['sync', 'sync_all', 'list']
 for i in fetch_actions:
 if i in self.config.keys():



[gentoo-commits] proj/layman:master commit in: layman/, /

2017-02-02 Thread Brian Dolbec
commit: 9c427606dccfb88c4e4c4de3d14f30418f174e2e
Author: Brian Dolbec  gentoo  org>
AuthorDate: Thu Feb  2 17:02:14 2017 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Thu Feb  2 17:06:44 2017 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=9c427606

Update for a release

 CHANGES   | 6 ++
 layman/version.py | 2 +-
 2 files changed, 7 insertions(+), 1 deletion(-)

diff --git a/CHANGES b/CHANGES
index c64007b..14bf02c 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,6 +1,12 @@
 CHANGES
 ---
 
+Version 2.4.2 - Release 2017-02-01
+==
+ - Bug 587474 Fix a missed eprefix placeholder for repos_conf setting.
+ - Bug 539336 Adds exception handling
+ - Fix commit 63808ef00f94 mis-applied 'sourcefile' attribute changes
+
 Version 2.4.1 - Release 2016-05-06
 ==
  - adds sourcefile to plug-in modules, fixes bug #582154

diff --git a/layman/version.py b/layman/version.py
index c6d20cd..402a339 100644
--- a/layman/version.py
+++ b/layman/version.py
@@ -24,7 +24,7 @@ from __future__ import unicode_literals
 __version__ = "$Id: version.py 309 2007-04-09 16:23:38Z wrobel $"
 
 
-VERSION = '2.4.1'
+VERSION = '2.4.2'
 
 if __name__ == '__main__':
 print(VERSION)



[gentoo-commits] proj/layman:master commit in: layman/

2017-02-01 Thread Devan Franchini
commit: fc23ec8246c2700111cbf8f4a4eb55ac4a5eb000
Author: Devan Franchini  gentoo  org>
AuthorDate: Thu Feb  2 00:47:27 2017 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Thu Feb  2 00:47:33 2017 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=fc23ec82

argparser.py: Fixed typo in --help output

Thank you dewey for pointing this out.

 layman/argsparser.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/argsparser.py b/layman/argsparser.py
index f3cc8fa..272ac47 100644
--- a/layman/argsparser.py
+++ b/layman/argsparser.py
@@ -193,7 +193,7 @@ class ArgsParser(BareConfig):
action = 'store',
default = self.defaults['overlay_defs'],
# Force interpolation (to prevent argparse 
tracebacks)
-   help = 'Path to aditional overlay.xml files 
[default: '
+   help = 'Path to additional overlay.xml files 
[default: '
'%s].' % (self.defaults['overlay_defs'] 
%self.defaults))
 
 path_opts.add_argument('-z',



[gentoo-commits] proj/layman:master commit in: layman/

2016-11-09 Thread Devan Franchini
commit: 7d1a6df6514991adeaa6deeb5d710354967bcc8c
Author: Devan Franchini  gentoo  org>
AuthorDate: Thu Nov 10 02:49:06 2016 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Thu Nov 10 02:49:35 2016 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=7d1a6df6

utils.py: Removes catching KeyboardInterrupt

As per bug 539336 it's near impossible to kill a stampeding layman
process. This was due to the run_command() function which caught
the KeyboardInterrupt exception.

 layman/utils.py | 3 ---
 1 file changed, 3 deletions(-)

diff --git a/layman/utils.py b/layman/utils.py
index 9530701..c008530 100644
--- a/layman/utils.py
+++ b/layman/utils.py
@@ -270,9 +270,6 @@ def run_command(config, command, args, **kwargs):
 
 try:
 result = proc.wait()
-except KeyboardInterrupt:
-output.info('Interrupted manually', 2)
-result = 1
 except Exception as err:
 output.error(
 'Unknown exception running command: %s' % command_repr)



[gentoo-commits] proj/layman:master commit in: layman/

2016-05-10 Thread Brian Dolbec
commit: 90fe6724d0a8d1ebfe6443dee118432e20432b8b
Author: Brian Dolbec  gentoo  org>
AuthorDate: Tue May 10 22:12:02 2016 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Tue May 10 22:12:02 2016 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=90fe6724

layman/module.py: Fix commit 63808ef00f94 mis-applied 'sourcefile' attribute 
changes

It was not looking for the 'sourcefile' attribute first, then falling back to 
the kidname for
backward compatibility.
It was incorrectly looking for an ImportError, instead of a 'sourcefile' 
KeyError.
The filepath of the affected file for the error message had an extra leading 
'_'.
Add the module name to the warning message.

 layman/module.py | 11 ++-
 1 file changed, 6 insertions(+), 5 deletions(-)

diff --git a/layman/module.py b/layman/module.py
index 08bcbc2..092418f 100644
--- a/layman/module.py
+++ b/layman/module.py
@@ -49,13 +49,14 @@ class Module(object):
 kid = self.module_spec['provides'][submodule]
 kidname = kid['name']
 try:
+kid['module_name'] = '.'.join([mod_name, kid['sourcefile']])
+except KeyError:
 kid['module_name'] = '.'.join([mod_name, kidname])
-except ImportError:
-kid['module_name'] = '.'.join([mod_name, self.name])
-f = self.__module.__file__
-msg = 'Module.__initialize(); module spec is old, missing '\
+f = self._module.__file__
+msg = 'Module.__initialize(); %(module)s module spec is old, 
missing '\
   'attribute: \'sourcefile\'.\nBackward compatibility '\
-  'may be removed in the future.\nFile: %(f)s' % {'f': f}
+  'may be removed in the future.\nFile: %(f)s' % {
+  'module': self.name, 'f': f}
 self.output.warn(msg)
 kid['is_imported'] = False
 self.kids[kidname] = kid



[gentoo-commits] proj/layman:master commit in: /, layman/

2016-05-09 Thread Devan Franchini
commit: 0b06cf1ccea9f9d56f9631eea1987a86abfb99a7
Author: Devan Franchini  gentoo  org>
AuthorDate: Tue May 10 00:02:31 2016 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Tue May 10 00:02:31 2016 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=0b06cf1c

Bumps version number to 2.4.1

 CHANGES   | 6 +-
 README| 2 +-
 layman/version.py | 2 +-
 3 files changed, 7 insertions(+), 3 deletions(-)

diff --git a/CHANGES b/CHANGES
index 15aaee8..c64007b 100644
--- a/CHANGES
+++ b/CHANGES
@@ -1,7 +1,11 @@
 CHANGES
 ---
 
-Version 2.4.0 - Release 2016-??-??
+Version 2.4.1 - Release 2016-05-06
+==
+ - adds sourcefile to plug-in modules, fixes bug #582154
+
+Version 2.4.0 - Release 2016-05-03
 ==
  - adds support for different overlay database types
  - adds json database support

diff --git a/README b/README
index f5763de..3e8e941 100644
--- a/README
+++ b/README
@@ -3,7 +3,7 @@ README
 ==
 
 :Last update:   Date: 2016-04-30
-:Revision:  2.4.0
+:Revision:  2.4.1
 :Contact:   Brian Dolbec 
 
 

diff --git a/layman/version.py b/layman/version.py
index 1e1427f..c6d20cd 100644
--- a/layman/version.py
+++ b/layman/version.py
@@ -24,7 +24,7 @@ from __future__ import unicode_literals
 __version__ = "$Id: version.py 309 2007-04-09 16:23:38Z wrobel $"
 
 
-VERSION = '2.4.0'
+VERSION = '2.4.1'
 
 if __name__ == '__main__':
 print(VERSION)



[gentoo-commits] proj/layman:master commit in: layman/db_modules/json_db/, layman/overlays/modules/tar/, ...

2016-05-09 Thread Devan Franchini
commit: 63808ef00f94ad31d4291ebf5048da9348caa659
Author: Devan Franchini  gentoo  org>
AuthorDate: Mon May  9 23:14:34 2016 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Mon May  9 23:28:46 2016 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=63808ef0

Adds sourcefile var to inits for plug-in modules

X-Gentoo-Bug: 582154
X-Gentoo-Bug-URL: https://bugs.gentoo.org/582154

 layman/config_modules/makeconf/__init__.py|  1 +
 layman/config_modules/reposconf/__init__.py   |  1 +
 layman/db_modules/json_db/__init__.py |  1 +
 layman/db_modules/sqlite_db/__init__.py   |  1 +
 layman/db_modules/xml_db/__init__.py  |  1 +
 layman/module.py  | 10 +-
 layman/overlays/modules/bzr/__init__.py   |  1 +
 layman/overlays/modules/cvs/__init__.py   |  1 +
 layman/overlays/modules/darcs/__init__.py |  1 +
 layman/overlays/modules/g_sorcery/__init__.py |  1 +
 layman/overlays/modules/git/__init__.py   |  1 +
 layman/overlays/modules/mercurial/__init__.py |  1 +
 layman/overlays/modules/rsync/__init__.py |  1 +
 layman/overlays/modules/squashfs/__init__.py  |  1 +
 layman/overlays/modules/stub/__init__.py  |  1 +
 layman/overlays/modules/svn/__init__.py   |  1 +
 layman/overlays/modules/tar/__init__.py   |  1 +
 17 files changed, 25 insertions(+), 1 deletion(-)

diff --git a/layman/config_modules/makeconf/__init__.py 
b/layman/config_modules/makeconf/__init__.py
index c385960..bec0661 100644
--- a/layman/config_modules/makeconf/__init__.py
+++ b/layman/config_modules/makeconf/__init__.py
@@ -12,6 +12,7 @@ module_spec = {
 'makeconf-module': {
 'name': 'makeconf',
 'class': 'ConfigHandler',
+'sourcefile': 'makeconf',
 'description': __doc__,
 'functions': ['add', 'delete', 'disable', 'enable', 'read',
   'update', 'write'],

diff --git a/layman/config_modules/reposconf/__init__.py 
b/layman/config_modules/reposconf/__init__.py
index f8f69bc..8528627 100644
--- a/layman/config_modules/reposconf/__init__.py
+++ b/layman/config_modules/reposconf/__init__.py
@@ -12,6 +12,7 @@ module_spec = {
 'reposconf-module': {
 'name': 'reposconf',
 'class': 'ConfigHandler',
+'sourcefile': 'reposconf',
 'description': __doc__,
 'functions': ['add', 'delete', 'disable', 'enable', 'read',
   'update', 'write'],

diff --git a/layman/db_modules/json_db/__init__.py 
b/layman/db_modules/json_db/__init__.py
index ac4daa7..5b91e58 100644
--- a/layman/db_modules/json_db/__init__.py
+++ b/layman/db_modules/json_db/__init__.py
@@ -12,6 +12,7 @@ module_spec = {
 'json-module': {
 'name': 'json_db',
 'class': 'DBHandler',
+'sourcefile': 'json_db',
 'description': __doc__,
 'functions': ['add_new', 'read_db', 'remove', 'write'],
 'func_desc': {

diff --git a/layman/db_modules/sqlite_db/__init__.py 
b/layman/db_modules/sqlite_db/__init__.py
index 536fc2d..a3678dc 100644
--- a/layman/db_modules/sqlite_db/__init__.py
+++ b/layman/db_modules/sqlite_db/__init__.py
@@ -12,6 +12,7 @@ module_spec = {
 'sqlite-module': {
 'name': 'sqlite_db',
 'class': 'DBHandler',
+'sourcefile': 'sqlite_db',
 'description': __doc__,
 'functions': ['add_new', 'read_db', 'remove', 'write'],
 'func_desc': {

diff --git a/layman/db_modules/xml_db/__init__.py 
b/layman/db_modules/xml_db/__init__.py
index c8a5bf9..f4bd13c 100644
--- a/layman/db_modules/xml_db/__init__.py
+++ b/layman/db_modules/xml_db/__init__.py
@@ -12,6 +12,7 @@ module_spec = {
 'xml-module': {
 'name': 'xml_db',
 'class': 'DBHandler',
+'sourcefile': 'xml_db',
 'description': __doc__,
 'functions': ['add_new', 'read_db', 'remove', 'write'],
 'func_desc': {

diff --git a/layman/module.py b/layman/module.py
index 99d243b..08bcbc2 100644
--- a/layman/module.py
+++ b/layman/module.py
@@ -48,7 +48,15 @@ class Module(object):
 for submodule in self.module_spec['provides']:
 kid = self.module_spec['provides'][submodule]
 kidname = kid['name']
-kid['module_name'] = '.'.join([mod_name, kidname])
+try:
+kid['module_name'] = '.'.join([mod_name, kidname])
+except ImportError:
+kid['module_name'] = '.'.join([mod_name, self.name])
+f = self.__module.__file__
+msg = 'Module.__initialize(); module spec is old, missing '\
+  'attribute: \'sourcefile\'.\nBackward compatibility '\
+  'may be removed in the future.\nFile: %(f)s' % {'f': f}
+self.output.warn(msg)
 kid['is_imported'] = False

[gentoo-commits] proj/layman:master commit in: layman/

2016-05-01 Thread Devan Franchini
commit: ec141d305949dac2d7ea3aab9f4c42d73f690777
Author: Devan Franchini  gentoo  org>
AuthorDate: Sun May  1 01:06:09 2016 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Sun May  1 01:06:09 2016 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=ec141d30

version.py: Changes version to reflect update

 layman/version.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/version.py b/layman/version.py
index e6d19ff..1e1427f 100644
--- a/layman/version.py
+++ b/layman/version.py
@@ -24,7 +24,7 @@ from __future__ import unicode_literals
 __version__ = "$Id: version.py 309 2007-04-09 16:23:38Z wrobel $"
 
 
-VERSION = '2.4.0-git'
+VERSION = '2.4.0'
 
 if __name__ == '__main__':
 print(VERSION)



[gentoo-commits] proj/layman:master commit in: layman/, layman/config_modules/reposconf/

2016-04-30 Thread Devan Franchini
commit: 6f4d6dc0552b1bad10f8953de786cf0e78d975ee
Author: Devan Franchini  gentoo  org>
AuthorDate: Sat Apr 30 22:08:12 2016 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Sat Apr 30 22:18:41 2016 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=6f4d6dc0

Repairs layman-updater rebuild functionality

reposconf.py: Adds rebuild __init__ parameter to fix rebuild
functionality
updater.py: Sets rebuild parameter for repos.conf ConfigHandler class

 layman/config_modules/reposconf/reposconf.py | 9 +
 layman/updater.py| 2 +-
 2 files changed, 6 insertions(+), 5 deletions(-)

diff --git a/layman/config_modules/reposconf/reposconf.py 
b/layman/config_modules/reposconf/reposconf.py
index 1f0fd04..79991c9 100644
--- a/layman/config_modules/reposconf/reposconf.py
+++ b/layman/config_modules/reposconf/reposconf.py
@@ -53,7 +53,7 @@ def check_conf_path(conf_path):
 
 class ConfigHandler:
 
-def __init__(self, config, overlays):
+def __init__(self, config, overlays, rebuild=False):
 
 self.config = config
 self.output = config['output']
@@ -61,7 +61,7 @@ class ConfigHandler:
 self.path = check_conf_path(config['repos_conf'])
 self.storage = config['storage']
 self.repo_config = None
-self.rebuild = False
+self.rebuild = rebuild
 
 self.read()
 
@@ -193,14 +193,15 @@ class ConfigHandler:
 if self.rebuild:
 # start over with a fresh instance
 self.repo_conf = ConfigParser.ConfigParser()
-if not self.repo_conf.sections():
+for i in sorted(self.overlays):
+self.add(self.overlays[i], no_write=True)
+if not self.repo_conf.sections() and not self.rebuild:
 if ('disable' in self.config.keys() and not
 self.config['disable'][0].lower() == 'all'):
 for i in sorted(self.overlays):
 if not i == delete:
 self.add(self.overlays[i], no_write=True)
 self.repo_conf.write(laymanconf)
-self.rebuild = False
 return True
 except IOError as error:
 self.output.error('ReposConf: ConfigHandler.write(); Failed to 
write "'\

diff --git a/layman/updater.py b/layman/updater.py
index 6384429..2bfc241 100644
--- a/layman/updater.py
+++ b/layman/updater.py
@@ -273,7 +273,7 @@ class Main(object):
 # can write the overlays to it.
 open(self.config['repos_conf'], 'w').close()
 from layman.config_modules.reposconf.reposconf import ConfigHandler
-repos_conf = ConfigHandler(self.config, overlays)
+repos_conf = ConfigHandler(self.config, overlays, rebuild=True)
 repos_conf.write()
 
 



[gentoo-commits] proj/layman:master commit in: layman/

2016-03-09 Thread Devan Franchini
commit: b15d33d547a8fa99f6919036991e2a7e539fe04c
Author: Devan Franchini  gentoo  org>
AuthorDate: Wed Mar  9 23:59:13 2016 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Wed Mar  9 23:59:18 2016 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=b15d33d5

remotedb.py: Removes climit param for internel _fetch_file() params

As _fetch_file() is for fetching internal files and does not use ssl-fetch
it should not have climit as a parameter.

 layman/remotedb.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/layman/remotedb.py b/layman/remotedb.py
index acade02..2df0c63 100644
--- a/layman/remotedb.py
+++ b/layman/remotedb.py
@@ -145,7 +145,7 @@ class RemoteDB(DbBase):
 filepath, mpath, tpath, sig = self._paths(url)
 if 'file://' in url:
 success, olist, timestamp = self._fetch_file(
-url, mpath, tpath, climit=60)
+url, mpath, tpath)
 elif sig:
 success, olist, timestamp = fetcher.fetch_content(
 url[0], tpath, climit=60)
@@ -222,7 +222,7 @@ class RemoteDB(DbBase):
 
 return base + '_' + hashlib.md5(url_encoded).hexdigest()
 
-def _fetch_file(self, url, mpath, tpath=None, climit=60):
+def _fetch_file(self, url, mpath, tpath=None):
 self.output.debug('RemoteDB._fetch_file() url = %s' % url, 2)
 # check when the cache was last updated
 # and don't re-fetch it unless it has changed



[gentoo-commits] proj/layman:master commit in: layman/

2016-03-09 Thread Devan Franchini
commit: 5f5e2626e0f4a5c3acca62083ce479828597462f
Author: Devan Franchini  gentoo  org>
AuthorDate: Wed Mar  9 23:37:13 2016 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Wed Mar  9 23:37:15 2016 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=5f5e2626

remotedb.py: Adds climit param to _fetch_file() definition

Following up on the updating of ssl-fetch's API update in commit
5ffbc7ae to make use of climit parameter.

 layman/remotedb.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/remotedb.py b/layman/remotedb.py
index 75f6739..acade02 100644
--- a/layman/remotedb.py
+++ b/layman/remotedb.py
@@ -222,7 +222,7 @@ class RemoteDB(DbBase):
 
 return base + '_' + hashlib.md5(url_encoded).hexdigest()
 
-def _fetch_file(self, url, mpath, tpath=None):
+def _fetch_file(self, url, mpath, tpath=None, climit=60):
 self.output.debug('RemoteDB._fetch_file() url = %s' % url, 2)
 # check when the cache was last updated
 # and don't re-fetch it unless it has changed



[gentoo-commits] proj/layman:master commit in: layman/

2016-02-28 Thread Devan Franchini
commit: c8170ca79751fa8785527683b8627317d61bde2b
Author: Devan Franchini  gentoo  org>
AuthorDate: Mon Feb 29 06:22:25 2016 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Mon Feb 29 06:22:25 2016 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=c8170ca7

dbbase.py: adds return value for read_db()

 layman/dbbase.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/dbbase.py b/layman/dbbase.py
index 8b25fcd..9a8ba3f 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -219,7 +219,7 @@ class DbBase(object):
 db_type = 'xml_db'
 
 db_ctl = self._get_dbctl(db_type)
-db_ctl.read_db(path, text=text)
+return db_ctl.read_db(path, text=text)
 
 
 def write(self, path, remove=False, migrate_type=None):



[gentoo-commits] proj/layman:master commit in: layman/db_modules/xml_db/, layman/db_modules/sqlite_db/, layman/, ...

2016-02-28 Thread Devan Franchini
commit: f8eb545aa0b268cfd08644b0996a6681359dc0bc
Author: Devan Franchini  gentoo  org>
AuthorDate: Mon Feb 29 06:09:27 2016 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Mon Feb 29 06:09:29 2016 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=f8eb545a

Adds error reporting for db read failures

If the database back-end fails to be read then layman will properly
report it and exit without causing an ugly traceback.

 layman/db_modules/json_db/json_db.py |   7 +-
 layman/db_modules/sqlite_db/sqlite_db.py | 121 +--
 layman/db_modules/xml_db/xml_db.py   |  21 --
 layman/dbbase.py |  12 ++-
 4 files changed, 95 insertions(+), 66 deletions(-)

diff --git a/layman/db_modules/json_db/json_db.py 
b/layman/db_modules/json_db/json_db.py
index 70e41d5..bf88593 100644
--- a/layman/db_modules/json_db/json_db.py
+++ b/layman/db_modules/json_db/json_db.py
@@ -75,6 +75,10 @@ class DBHandler(object):
 try:
 with fileopen(path, 'r') as df:
 document = df.read()
+except ValueError as error:
+msg = 'JSON DBHanlder - ValueError: %(err)s' % {'err': error}
+self.output.error(msg)
+return False
 except Exception as error:
 if not self.ignore_init_read_errors:
 msg = 'JSON DBHandler - Failed to read the overlay list 
at'\
@@ -82,7 +86,8 @@ class DBHandler(object):
 self.output.error(msg)
 raise error
 
-self.add_new(document, origin=path)
+success = self.add_new(document, origin=path)
+return success
 
 
 def add_new(self, document=None, origin=None):

diff --git a/layman/db_modules/sqlite_db/sqlite_db.py 
b/layman/db_modules/sqlite_db/sqlite_db.py
index a3305a7..3585c4a 100644
--- a/layman/db_modules/sqlite_db/sqlite_db.py
+++ b/layman/db_modules/sqlite_db/sqlite_db.py
@@ -136,6 +136,8 @@ class DBHandler(object):
 CONFLICT IGNORE )''')
 
 connection.commit()
+except sqlite3.DatabaseError as err:
+raise err
 except Exception as err:
 msg = 'SQLite DBHandler error; failed to create database.\n'\
   'Error was: %(msg)s' % {'msg': err}
@@ -152,64 +154,71 @@ class DBHandler(object):
 overlay_id = None
 overlay = {}
 
-with self.__connect__(path) as connection:
-cursor = connection.cursor()
-cursor.execute('''SELECT Overlay_ID, Name, Priority, Status, 
-Quality, Homepage, IRC, License FROM Overlay''')
-overlays_info = cursor.fetchall()
-connection.commit()
+try:
+connection = self.__connect__(path)
+except sqlite3.DatabaseError as err:
+msg = 'SQLite DBHandler DatabaseError: %(err)s' % {'err': err}
+self.output.error(msg)
+return False
 
-for overlay_info in overlays_info:
-overlay = {}
-overlay_id = overlay_info[0]
-overlay['name'] = overlay_info[1]
-
-cursor.execute('''SELECT URL, Type, Branch FROM Overlay_Source 
-JOIN Overlay USING (Overlay_ID) JOIN Source USING (Source_ID) 
-WHERE Overlay_ID = ?''', (overlay_id,))
-overlay['source'] = cursor.fetchall()
-
-cursor.execute('''SELECT Owner_Email, Owner_Name FROM 
-Overlay_Owner JOIN Overlay USING (Overlay_ID) JOIN Owner USING 
-(Owner_ID) WHERE Overlay_ID = ?''', (overlay_id,))
-owner_info = cursor.fetchall()
-overlay['owner'] = []
-
-for _owner in owner_info:
-owner = {}
-if _owner[0]:
-owner['email'] = _owner[0]
+cursor = connection.cursor()
+cursor.execute('''SELECT Overlay_ID, Name, Priority, Status,
+Quality, Homepage, IRC, License FROM Overlay''')
+overlays_info = cursor.fetchall()
+connection.commit()
+
+for overlay_info in overlays_info:
+overlay = {}
+overlay_id = overlay_info[0]
+overlay['name'] = overlay_info[1]
+
+cursor.execute('''SELECT URL, Type, Branch FROM Overlay_Source
+JOIN Overlay USING (Overlay_ID) JOIN Source USING (Source_ID)
+WHERE Overlay_ID = ?''', (overlay_id,))
+overlay['source'] = cursor.fetchall()
+
+cursor.execute('''SELECT Owner_Email, Owner_Name FROM Overlay_Owner
+JOIN Overlay USING (Overlay_ID) JOIN Owner USING (Owner_ID)
+WHERE Overlay_ID = ?''', (overlay_id,))
+owner_info = cursor.fetchall()
+overlay['owner'] = []
+for _owner in owner_info:
+owner = {}
+if _owner[0]:

[gentoo-commits] proj/layman:master commit in: layman/

2016-01-29 Thread Brian Dolbec
commit: 032c1c60eb2a33f1cd52a0023dcd2e6d0de54f01
Author: Brian Dolbec  gentoo  org>
AuthorDate: Fri Jan 29 10:18:34 2016 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Fri Jan 29 10:20:10 2016 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=032c1c60

remotedb.py: Update for latest ssl-fetch API

 layman/remotedb.py | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/layman/remotedb.py b/layman/remotedb.py
index 5a66a3f..75f6739 100644
--- a/layman/remotedb.py
+++ b/layman/remotedb.py
@@ -119,9 +119,15 @@ class RemoteDB(DbBase):
 'info':  self.output.info,
 'debug': self.output.debug,
 'error': self.output.error,
+'exception': self.output.error,
+# we want any warnings to be printed to the terminal
+# so assign it to output.info with a lower noise level
+'warning': self.output.info,
+'kwargs-exception': {'level': None},
 'kwargs-info': {'level': 5},
 'kwargs-debug': {'level': 2},
 'kwargs-error':{'level': None},
+'kwargs-warning': {'level': 2},
 }
 fetcher = Connector(connector_output, self.proxies, USERAGENT)
 



[gentoo-commits] proj/layman:master commit in: layman/

2015-12-30 Thread Devan Franchini
commit: 40b99fb93f0cbc80083a72e23e93da4bafb365fb
Author: Devan Franchini  gentoo  org>
AuthorDate: Thu Dec 31 01:02:44 2015 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Thu Dec 31 01:02:47 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=40b99fb9

module.py: fixes bug where the module_spec module name was not used

This only showed up when the module's target name (filename) was not the
same as the modules initialization name.

 layman/module.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/module.py b/layman/module.py
index 6d7a40b..99d243b 100644
--- a/layman/module.py
+++ b/layman/module.py
@@ -48,7 +48,7 @@ class Module(object):
 for submodule in self.module_spec['provides']:
 kid = self.module_spec['provides'][submodule]
 kidname = kid['name']
-kid['module_name'] = '.'.join([mod_name, self.name])
+kid['module_name'] = '.'.join([mod_name, kidname])
 kid['is_imported'] = False
 self.kids[kidname] = kid
 self.kids_names.append(kidname)



[gentoo-commits] proj/layman:master commit in: layman/

2015-12-26 Thread Brian Dolbec
commit: 5ffbc7aef1251366173a4b01cb4453a585d9e064
Author: Brian Dolbec  gentoo  org>
AuthorDate: Sat Dec 26 23:23:34 2015 +
Commit: Brian Dolbec  gentoo  org>
CommitDate: Sat Dec 26 23:23:34 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=5ffbc7ae

remotedb.py: Add climit due to sslfetch API change

 layman/remotedb.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/layman/remotedb.py b/layman/remotedb.py
index b9c4ae0..5a66a3f 100644
--- a/layman/remotedb.py
+++ b/layman/remotedb.py
@@ -139,13 +139,13 @@ class RemoteDB(DbBase):
 filepath, mpath, tpath, sig = self._paths(url)
 if 'file://' in url:
 success, olist, timestamp = self._fetch_file(
-url, mpath, tpath)
+url, mpath, tpath, climit=60)
 elif sig:
 success, olist, timestamp = fetcher.fetch_content(
-url[0], tpath)
+url[0], tpath, climit=60)
 else:
 success, olist, timestamp = fetcher.fetch_content(
-url, tpath)
+url, tpath, climit=60)
 if not success:
 #succeeded = False
 continue



[gentoo-commits] proj/layman:master commit in: layman/

2015-11-28 Thread Devan Franchini
commit: c8f2cda02daf9752e0c169db2051ee33a4e1f9d7
Author: Devan Franchini  gentoo  org>
AuthorDate: Sun Nov 29 03:11:59 2015 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Sun Nov 29 03:12:02 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=c8f2cda0

updater.py: Adds expected "." to database migration check to ensure proper 
backup naming

 layman/updater.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/updater.py b/layman/updater.py
index 5cef2b0..6cd98c4 100644
--- a/layman/updater.py
+++ b/layman/updater.py
@@ -124,7 +124,7 @@ class Main(object):
 installed = self.config['installed']
 old_ext = os.path.splitext(installed)[1]
 backup_name = installed + '.' + self.config['db_type']
-if old_ext == self.config['db_type']:
+if old_ext == "." + self.config['db_type']:
 backup_name = installed + '.bak'
 new_name = installed.replace(old_ext, '.db')
 



[gentoo-commits] proj/layman:master commit in: layman/

2015-11-28 Thread Devan Franchini
commit: 491baec51fabb75160170dbea9b55887b1083773
Author: Devan Franchini  gentoo  org>
AuthorDate: Sun Nov 29 03:25:15 2015 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Sun Nov 29 03:25:17 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=491baec5

updater.py: Sets set_db_type installed var to new_name

Previously the set_db_type function would be passed the old installed
database name instead of the new one. This would lead to setting
the "installed" variable in the layman config to an incorrect one.

 layman/updater.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/updater.py b/layman/updater.py
index 6cd98c4..6384429 100644
--- a/layman/updater.py
+++ b/layman/updater.py
@@ -164,7 +164,7 @@ class Main(object):
'to_type': migrate_type}
 self.output.info(msg)
 
-self.set_db_type(migrate_type, os.path.basename(installed))
+self.set_db_type(migrate_type, os.path.basename(new_name))
 
 msg = '  Warning: Please be sure to update your config file via '\
   'the\n  `dispatch-conf` command or you *will* lose database '\



[gentoo-commits] proj/layman:master commit in: layman/

2015-10-16 Thread Devan Franchini
commit: d1c17e2c30f47ef5ac8450f269824976605b58a0
Author: Devan Franchini  gentoo  org>
AuthorDate: Fri Oct 16 18:19:27 2015 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Fri Oct 16 18:19:31 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=d1c17e2c

dbbase.py: Creates internal function to get database module controller

This internal function centralizes the functionality of getting the
database module controller while also adding in checks to gracefully
handle invalid module names.

 layman/dbbase.py | 43 ---
 1 file changed, 24 insertions(+), 19 deletions(-)

diff --git a/layman/dbbase.py b/layman/dbbase.py
index dc089d8..ebcd7a4 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -36,7 +36,7 @@ import os
 import os.path
 import sys
 
-from   layman.module import Modules
+from   layman.module import Modules, InvalidModuleName
 from   layman.overlays.overlay   import Overlay
 
 
@@ -155,6 +155,26 @@ class DbBase(object):
 raise NotImplementedError(msg)
 
 
+def _get_dbctl(self, db_type):
+'''
+Returns database module controller for class or dies trying.
+'''
+try:
+db_ctl = self.mod_ctl.get_class(db_type)(self.config,
+self.overlays,
+self.paths,
+self.ignore,
+self.ignore_init_read_errors)
+except InvalidModuleName:
+msg = 'DbBase._get_dbctl() error:\nDatabase module name '\
+  '"%(name)s" is invalid or not found.\nPlease set db_type '\
+  'variable to proper value to continue.'\
+  % {'name': db_type.replace('_db', '')}
+self.output.die(msg)
+
+return db_ctl
+
+
 def add_new(self, xml=None, origin=None, from_dict=None):
 '''
 Reads xml text and dictionary definitions and adds
@@ -188,12 +208,7 @@ class DbBase(object):
 if 'cache' in path and '.xml' in path:
 db_type = 'xml_db'
 
-db_ctl = self.mod_ctl.get_class(db_type)(self.config,
- self.overlays,
- self.paths,
- self.ignore,
- self.ignore_init_read_errors)
-
+db_ctl = self._get_dbctl(db_type)
 db_ctl.read_db(path, text=text)
 
 
@@ -206,12 +221,7 @@ class DbBase(object):
 if migrate_type:
 db_type = migrate_type + '_db'
 
-db_ctl = self.mod_ctl.get_class(db_type)(self.config,
- self.overlays,
- self.paths,
- self.ignore,
- self.ignore_init_read_errors)
-
+db_ctl = self._get_dbctl(db_type)
 db_ctl.write(path, remove=remove)
 
 
@@ -219,12 +229,7 @@ class DbBase(object):
 '''
 Remove an overlay from the database.
 '''
-db_ctl = self.mod_ctl.get_class(self.db_type)(self.config,
- self.overlays,
- self.paths,
- self.ignore,
- self.ignore_init_read_errors)
-
+db_ctl = self._get_dbctl(db_type)
 db_ctl.remove(overlay, path)
 
 



[gentoo-commits] proj/layman:master commit in: layman/

2015-10-16 Thread Devan Franchini
commit: 909afd209034ec26bca6f8c5d646852b2bd62c3e
Author: Devan Franchini  gentoo  org>
AuthorDate: Sat Oct 17 03:19:25 2015 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Sat Oct 17 03:19:28 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=909afd20

dbbase.py: Whitespace cleanup

Shamelessly hiding the fact that I'm also ammending the lack of
self.db_type use in the remove() function.

 layman/dbbase.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/layman/dbbase.py b/layman/dbbase.py
index ebcd7a4..c2b25b8 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -173,8 +173,8 @@ class DbBase(object):
 self.output.die(msg)
 
 return db_ctl
-
-
+
+
 def add_new(self, xml=None, origin=None, from_dict=None):
 '''
 Reads xml text and dictionary definitions and adds
@@ -229,7 +229,7 @@ class DbBase(object):
 '''
 Remove an overlay from the database.
 '''
-db_ctl = self._get_dbctl(db_type)
+db_ctl = self._get_dbctl(self.db_type)
 db_ctl.remove(overlay, path)
 
 



[gentoo-commits] proj/layman:master commit in: layman/

2015-10-16 Thread Devan Franchini
commit: a4ee3c8a29db32aad6e5b5404fbc1714185f7ab8
Author: Devan Franchini  gentoo  org>
AuthorDate: Fri Oct 16 18:47:06 2015 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Fri Oct 16 18:47:06 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=a4ee3c8a

updater.py: Alters the way migrate_database handles an invalid db_type

Instead of showing the user the error and raising an exception, an
alternative method of dying after hitting the error has been
implemented.

 layman/updater.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/layman/updater.py b/layman/updater.py
index 25abf72..5cef2b0 100644
--- a/layman/updater.py
+++ b/layman/updater.py
@@ -118,8 +118,7 @@ class Main(object):
 if migrate_type not in DB_TYPES:
 msg = 'migrate_database() error; invalid migration type: '\
   '"%(db_type)s"' % {'db_type': migrate_type}
-self.output.error('  ' + msg)
-raise Exception(msg)
+self.output.die(msg)
 
 db = DB(self.config)
 installed = self.config['installed']



[gentoo-commits] proj/layman:master commit in: layman/

2015-09-23 Thread Devan Franchini
commit: dd07c3c8ff231ca440a19ad288603573be1a02bb
Author: Pastafarianist  gmail  com>
AuthorDate: Tue Sep 22 15:35:54 2015 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Wed Sep 23 15:24:00 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=dd07c3c8

Improved grammar

Signed-off-by: Devan Franchini  gentoo.org>

 layman/db.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/db.py b/layman/db.py
index a7ed1ce..d67ea87 100644
--- a/layman/db.py
+++ b/layman/db.py
@@ -87,7 +87,7 @@ class DB(DbBase):
 @rtype bool: reflect the user's decision to install overlay.
 '''
 if self.config['check_official'] and not overlay.status == 'official':
-msg = 'Overlay "%(repo)s" is not an official. Continue install?'\
+msg = 'Overlay "%(repo)s" is not official. Continue installing?'\
   ' [y/n]: ' % {'repo': overlay.name}
 if not get_ans(msg, color='green'):
 msg = 'layman will not add "%(repo)s", due to user\'s'\



[gentoo-commits] proj/layman:master commit in: layman/

2015-09-05 Thread Devan Franchini
commit: 3ed3bc4d73658acc7f9541d34c7e9d1190211a41
Author: Devan Franchini  gentoo  org>
AuthorDate: Sat Sep  5 06:03:32 2015 +
Commit: Devan Franchini  gentoo  org>
CommitDate: Sat Sep  5 06:03:35 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=3ed3bc4d

api.py: Corrects typo in enable/disable_repo functions()

References git issue #30.

 layman/api.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/layman/api.py b/layman/api.py
index 20fe402..2c46bb7 100755
--- a/layman/api.py
+++ b/layman/api.py
@@ -193,7 +193,7 @@ class LaymanAPI(object):
 for ovl in repos:
 if not self.is_repo(ovl):
 self.output.error(UnknownOverlayMessage(ovl))
-result.append(False)
+results.append(False)
 continue
 success = False
 try:
@@ -218,7 +218,7 @@ class LaymanAPI(object):
 for ovl in repos:
 if not self.is_repo(ovl):
 self.output.error(UnknownOverlayMessage(ovl))
-result.append(False)
+results.append(False)
 continue
 success = False
 try:



[gentoo-commits] proj/layman:master commit in: layman/

2015-08-27 Thread Devan Franchini
commit: d5ca0ce0d10220401176b981882349c9f25294c4
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Aug 28 01:45:45 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Aug 28 01:47:15 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=d5ca0ce0

maker.py: Modifies query prompts

These modifications remove a lot of duplicated prompts that were created
when trying to prompt the user for an item that could be of more than
one value.

 layman/maker.py | 70 ++---
 1 file changed, 27 insertions(+), 43 deletions(-)

diff --git a/layman/maker.py b/layman/maker.py
index 06d624b..c184f6b 100644
--- a/layman/maker.py
+++ b/layman/maker.py
@@ -295,11 +295,11 @@ class Interactive(object):
 feeds = []
 
 for i in range(1, feed_amount + 1):
+extra = ''
 if feed_amount  1:
-msg = 'Define overlay feed[%(i)s]: ' % ({'i': str(i)})
-feeds.append(get_input(msg))
-else:
-feeds.append(get_input('Define overlay feed: '))
+extra = '[%(i)s]' % {'i': str(i)}
+feeds.append(get_input('Define overlay%(extra)s feed: '\
+ % {'extra': extra}))
 
 self.overlay['feed'] = feeds
 self.output.notice('')
@@ -344,48 +344,32 @@ class Interactive(object):
 for i in range(1, source_amount + 1):
 sources = []
 correct = False
+extra = ''
 if source_amount  1:
-msg = 'Define source[%(i)s]\'s URL: ' % ({'i': str(i)})
-sources.append(get_input(msg))
+extra = '[%(i)s]\'s' % {'i': str(i)}
 
-ovl_type = self.guess_overlay_type(sources[0])
-if ovl_type:
-msg = 'Is %(type)s the correct overlay type?: '\
-% ({'type': ovl_type})
-correct = get_ans(msg)
-while not ovl_type or not correct:
-msg = 'Please provide overlay type: '
-ovl_type = self.check_overlay_type(\
-get_input(msg, color='yellow'))
-correct = True
-
-sources.append(ovl_type)
-if 'branch' in self.required:
-msg = 'Define source[%(i)s]\'s branch (if applicable): '\
-  % ({'i': str(i)})
-sources.append(get_input(msg))
-else:
-sources.append('')
+msg = 'Define source%(extra)s URL: ' % {'extra': extra}
+sources.append(get_input(msg))
+
+ovl_type = self.guess_overlay_type(sources[0])
+if ovl_type:
+msg = 'Is %(type)s the correct overlay type?: '\
+% ({'type': ovl_type})
+correct = get_ans(msg)
+while not ovl_type or not correct:
+msg = 'Please provide overlay type: '
+ovl_type = self.check_overlay_type(\
+get_input(msg, color='yellow'))
+correct = True
+
+sources.append(ovl_type)
+if 'branch' in self.required:
+msg = 'Define source%(extra)s branch (if applicable): '\
+  % {'extra': extra}
+sources.append(get_input(msg))
 else:
-sources.append(get_input('Define source URL: '))
-
-ovl_type = self.guess_overlay_type(sources[0])
-if ovl_type:
-msg = 'Is %(type)s the correct overlay type?: '\
-   % ({'type': ovl_type})
-correct = get_ans(msg)
-while not ovl_type or not correct:
-msg = 'Please provide overlay type: '
-ovl_type = self.check_overlay_type(\
-   get_input(msg, color='yellow'))
-correct = True
-
-sources.append(ovl_type)
-if 'branch' in self.required:
-msg = 'Define source branch (if applicable): '
-sources.append(get_input(msg))
-else:
-sources.append('')
+sources.append('')
+
 if self.auto_complete:
 sources = self._set_additional_info(sources)
 for source in sources:



[gentoo-commits] proj/layman:master commit in: layman/

2015-08-27 Thread Devan Franchini
commit: a84d2c42eda377be883b889fbe3d094ecc48221e
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Aug 28 01:33:19 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Aug 28 01:47:11 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=a84d2c42

maker.py: Adds multiple owner user query

 layman/maker.py | 20 ++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/layman/maker.py b/layman/maker.py
index caf5655..06d624b 100644
--- a/layman/maker.py
+++ b/layman/maker.py
@@ -401,9 +401,25 @@ class Interactive(object):
 then appends the values to the overlay
 being created.
 '''
+self.overlay['owner'] = []
 self.output.notice('')
-self.overlay['owner_name'] = get_input('Define owner name: ')
-self.overlay['owner_email'] = get_input('Define owner email: ')
+
+msg = 'How many people own this overlay?: '
+owner_amount = int(get_input(msg))
+
+for i in range(1, owner_amount + 1):
+owner = {}
+extra = ''
+
+if owner_amount  1:
+extra = '[%(i)s]\'s' % {'i': str(i)}
+
+owner['name'] = get_input('Define owner%(extra)s name: '\
+% {'extra': extra})
+owner['email'] = get_input('Define owner%(extra)s email: '\
+ % {'extra': extra})
+self.overlay['owner'].append(owner)
+
 self.output.notice('')
 
 



[gentoo-commits] proj/layman:master commit in: layman/

2015-08-27 Thread Devan Franchini
commit: b5239542b305a6b2638b5dc8cfe19ddb3fe09ef4
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Aug 28 00:52:16 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Aug 28 00:52:18 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=b5239542

utils.py: Gives create_overlay_dict a well needed updating

As this function exists with the API consumer in mind the function
was well overdue for getting it the result keys updated to reflect
all the ongoing changes in layman's API.

 layman/utils.py | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/layman/utils.py b/layman/utils.py
index b8e1e2a..9530701 100644
--- a/layman/utils.py
+++ b/layman/utils.py
@@ -331,13 +331,12 @@ def create_overlay_dict(**kwargs):
 
 result = {
 'name': '',
-'owner_name': '',
-'owner_email': '',
+'owner': [],
 'homepage': '',
 'irc': '',
-'description': '',
-'feeds': [],
-'sources': [('','','')],
+'description': [],
+'feed': [],
+'source': [('','','')],
 'priority': 50,
 'quality': 'experimental',
 'status': '',



[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-08-27 Thread Devan Franchini
commit: 4c8a81001eb813a4ec25584cacdd97c87f176c84
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Aug 28 03:47:35 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Aug 28 03:47:38 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=4c8a8100

overlay.py: Fixes method of assigning owner info if contact attrib is found

Prior to this commit the overlay would not set the owner info if the
contact attribute was found, breaking backwards compatibility. To allow
for this backwards compatibility while maintaining multiple owner
support layman will be defaulting to the contact attribute if it is
present in any XML overlays.

 layman/overlays/overlay.py | 49 --
 1 file changed, 26 insertions(+), 23 deletions(-)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 8052d4c..9cbeb99 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -454,32 +454,35 @@ class Overlay(object):
 _owners = xml.findall('owner')
 self.owners = []
 
-for _owner in _owners:
-owner = {}
+# For backwards compatibility with older Overlay XML formats
+# default to this.
+if 'contact' in xml.attrib:
+owner = {'email': encode(xml.attrib['contact']),
+ 'name': None}
+self.owners.append(owner)
+else:
+for _owner in _owners:
+owner = {}
 
-_email = _owner.find('email')
-_name = _owner.find('name')
+_email = _owner.find('email')
+_name = _owner.find('name')
 
-if _name != None:
-owner['name'] = encode(strip_text(_name))
-else:
-owner['name'] = None
-if _email != None:
-owner['email'] = encode(strip_text(_email))
-else:
-owner['email'] = None
-msg = 'Overlay from_xml(), %(name)s is missing an '\
-  'owner.email entry!' % {'name': self.name}
-if not ignore:
-raise Exception(msg)
-elif ignore == 1:
-self.output.warn(msg, 4)
+if _name != None:
+owner['name'] = encode(strip_text(_name))
+else:
+owner['name'] = None
+if _email != None:
+owner['email'] = encode(strip_text(_email))
+else:
+owner['email'] = None
+msg = 'Overlay from_xml(), %(name)s is missing an '\
+  'owner.email entry!' % {'name': self.name}
+if not ignore:
+raise Exception(msg)
+elif ignore == 1:
+self.output.warn(msg, 4)
 
-# For backwards compatibility with older Overlay XML formats.
-if not _email and not _name and 'contact' in xml.attrib:
-owner['email'] = encode(xml.attrib['contact'])
-owner['name'] = None
-self.owners.append(owner)
+self.owners.append(owner)
 
 _desc = xml.findall('description')
 if _desc != None:



[gentoo-commits] proj/layman:master commit in: layman/tests/, layman/tests/testfiles/, layman/

2015-08-27 Thread Devan Franchini
commit: 794f56f5ae531a5b24200ad3c0d6cf7112305da8
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Aug 28 03:37:32 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Aug 28 03:40:15 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=794f56f5

Deprecates get_all_info() function

The api function get_all_info() is being deprecated as it was much
slower than the get_info_str() function and was no longer used in
layman's code. The only instance found making use of it was older test
code which has been changed to also use the get_info_str() function.

external.py: Deprecates the get_all_info() function and adds multiple
owner testing compatibility.
api.py: Removes the get_all_info() function.
cli.py: Removes commented out use of get_all_info() function.
global-overlays.json: Changes structure of 'owner' attribute to reflect
changes for multiple owner support.

 layman/api.py   | 69 -
 layman/cli.py   |  6 ---
 layman/tests/external.py| 40 ++---
 layman/tests/testfiles/global-overlays.json | 12 +++--
 4 files changed, 22 insertions(+), 105 deletions(-)

diff --git a/layman/api.py b/layman/api.py
index 0718dce..20fe402 100755
--- a/layman/api.py
+++ b/layman/api.py
@@ -237,75 +237,6 @@ class LaymanAPI(object):
 return True
 
 
-def get_all_info(self, repos, local=False):
-retrieves the recorded information about the repo(s)
-specified by repo-id
-
-@type repos: list of strings or string
-@param repos: ['repo-id1', ...] or 'repo-id'
-@rtype list of tuples [(str, bool, bool),...]
-@return: dictionary of dictionaries
-{'ovl1':
-{'name': str,
-'owner_name': str,
-'owner_email': str,
-' homepage': str,
-'description': str,
-'src_uris': list of str ['uri1',...]
-'src_type': str,
-'priority': int,
-'quality': str
-'status':,
-'official': bool,
-'supported': bool,
-},
-'ovl2': {...}
-}
-
-
-repos = self._check_repo_type(repos, get_info)
-result = {}
-
-if local:
-db = self._get_installed_db()
-else:
-db = self._get_remote_db()
-
-for ovl in repos:
-if not self.is_repo(ovl):
-self.output.error(UnknownOverlayMessage(ovl))
-result[ovl] = ('', False, False)
-continue
-try:
-overlay = db.select(ovl)
-except UnknownOverlayException as error:
-self._error(error)
-result[ovl] = ('', False, False)
-else:
-result[ovl] = {
-'name': overlay.name,
-'owner_name': overlay.owner_name,
-'owner_email': overlay.owner_email,
-'homepage': overlay.homepage,
-'irc': overlay.irc,
-'description': [e for e in overlay.descriptions],
-'feeds': overlay.feeds,
-'sources': [(e.src, e.type, e.branch) \
-for e in overlay.sources],
-#'src_uris': [e.src for e in overlay.sources],
-'src_uris': overlay.source_uris(),
-'src_types': overlay.source_types(),
-#'src_types': [e.type for e in overlay.sources],
-'priority': overlay.priority,
-'quality': overlay.quality,
-'status': overlay.status,
-'official': overlay.is_official(),
-'supported': overlay.is_supported(),
-}
-
-return result
-
-
 def get_info_str(self, repos, local=True, verbose=False, width=0):
 retrieves the string representation of the recorded information
 about the repo(s) specified by ovl

diff --git a/layman/cli.py b/layman/cli.py
index bb9ea6f..86d6e70 100644
--- a/layman/cli.py
+++ b/layman/cli.py
@@ -381,17 +381,11 @@ class Main(object):
 self.output.debug('Printing installed overlays.', 6)
 list_printer = ListPrinter(self.config)
 
-#
-# fast way
 info = self.api.get_info_list(verbose=self.config['verbose'],
   width=list_printer.width)
 #self.output.debug('CLI: ListLocal() info = %s' % len(info), 4)
 #self.output.debug('\n'.join([ str(x) for x in info]), 4)
 list_printer.print_shortlist(info, complain=True)
-#
-# slow way
-#info = self.api.get_all_info(self.api.get_installed(), local=True)
-#list_printer.print_fulldict(info, complain=_complain)
 
 # blank newline  -- no  *
 

[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-08-27 Thread Devan Franchini
commit: 8363c11894f9fc724f1c5d46d115c3d5919cbc37
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Aug 28 02:54:22 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Aug 28 02:54:26 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=8363c118

overlay.py: Modifies __eq__ attribute requirements

The previous method still made use of owner_name and owner_email to see
if the two were equal while it should've been checking for the owners
overlay attribute.

 layman/overlays/overlay.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 11536d4..8052d4c 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -76,8 +76,8 @@ class Overlay(object):
 
 
 def __eq__(self, other):
-for i in ('descriptions', 'homepage', 'name', 'owner_email',
-'owner_name', 'priority', 'status'):
+for i in ('descriptions', 'homepage', 'name', 'owners', 'priority',
+  'status'):
 if getattr(self, i) != getattr(other, i):
 return False
 for i in self.sources + other.sources:



[gentoo-commits] proj/layman:master commit in: layman/overlays/, layman/db_modules/sqlite_db/

2015-08-27 Thread Devan Franchini
commit: 03f39c1a46149d472797e4adb6654705579c412c
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Aug 28 00:36:37 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Aug 28 00:36:40 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=03f39c1a

Adds multiple owner support to layman overlays

 layman/db_modules/sqlite_db/sqlite_db.py |  69 -
 layman/overlays/overlay.py   | 164 ++-
 2 files changed, 137 insertions(+), 96 deletions(-)

diff --git a/layman/db_modules/sqlite_db/sqlite_db.py 
b/layman/db_modules/sqlite_db/sqlite_db.py
index 22ae5f3..a3305a7 100644
--- a/layman/db_modules/sqlite_db/sqlite_db.py
+++ b/layman/db_modules/sqlite_db/sqlite_db.py
@@ -172,12 +172,21 @@ class DBHandler(object):
 cursor.execute('''SELECT Owner_Email, Owner_Name FROM 
 Overlay_Owner JOIN Overlay USING (Overlay_ID) JOIN Owner USING 
 (Owner_ID) WHERE Overlay_ID = ?''', (overlay_id,))
-owner_info = cursor.fetchall()[0]
-
-overlay['owner_email'] = owner_info[0]
-
-if len(owner_info)  1:
-overlay['owner_name'] = owner_info[1]
+owner_info = cursor.fetchall()
+overlay['owner'] = []
+
+for _owner in owner_info:
+owner = {}
+if _owner[0]:
+owner['email'] = _owner[0]
+else:
+owner['email'] = None
+if len(_owner)  1:
+if _owner[1]:
+owner['name'] = _owner[1]
+else:
+owner['name'] = None
+overlay['owner'].append(owner)
 
 cursor.execute('''SELECT Description FROM Description JOIN 
 Overlay USING (Overlay_ID) WHERE Overlay_ID = ?''',
@@ -225,7 +234,7 @@ class DBHandler(object):
 '''
 overlay_id = None
 owner_id = None
-source_ids = []
+source_id = None
 cursor = None
 
 cursor = connection.cursor()
@@ -239,22 +248,37 @@ class DBHandler(object):
 (overlay.name,))
 overlay_id = cursor.fetchone()[0]
 
-cursor.execute('''INSERT INTO Owner ( Owner_Name, Owner_Email ) 
-VALUES ( ?, ? )''', (overlay.owner_name, overlay.owner_email,))
-connection.commit()
+for owner in overlay.owners:
+_name = owner['name']
+_email = owner['email']
+
+cursor.execute('''INSERT INTO Owner ( Owner_Name, Owner_Email ) 
+VALUES ( ?, ? )''', (owner['name'], owner['email'],))
+connection.commit()
+
+if _name != None:
+cursor.execute('''SELECT Owner_ID from Owner WHERE 
+Owner_Email = ? AND Owner_Name = ?''', (_email, _name,))
+else:
+cursor.execute('''SELECT Owner_ID from Owner WHERE 
+Owner_Email = ?''', (_email,))
+owner_id = cursor.fetchone()[0]
 
-cursor.execute('''SELECT Owner_ID from Owner WHERE Owner_Email = ?;''',
-(overlay.owner_email,))
-owner_id = cursor.fetchone()[0]
+cursor.execute('''INSERT INTO Overlay_Owner ( Overlay_ID, 
+Owner_ID ) VALUES ( ?, ? )''', (overlay_id, owner_id,))
 
 for source in overlay.sources:
 cursor.execute('''INSERT INTO Source ( Type, Branch, URL )
 VALUES ( ?, ?, ? )''', (source.type_key, source.branch,
 source.src,))
 connection.commit()
+
 cursor.execute('''SELECT Source_ID FROM Source WHERE URL = ?;''',
 (source.src,))
-source_ids.append(cursor.fetchone()[0])
+source_id = cursor.fetchone()[0]
+
+cursor.execute('''INSERT INTO Overlay_Source ( Overlay_ID, 
+Source_ID ) VALUES ( ?, ? )''', (overlay_id, source_id, ))
 
 for description in overlay.descriptions:
 cursor.execute('''INSERT INTO Description ( Overlay_ID, 
@@ -264,13 +288,6 @@ class DBHandler(object):
 cursor.execute('''INSERT INTO Feed ( Overlay_ID, Feed ) VALUES ( ?,
  ? )''', (overlay_id, feed,))
 
-cursor.execute('''INSERT INTO Overlay_Owner ( Overlay_ID, Owner_ID ) 
-VALUES ( ?, ? )''', (overlay_id, owner_id,))
-
-for source_id in source_ids:
-cursor.execute('''INSERT INTO Overlay_Source ( Overlay_ID, 
-Source_ID ) VALUES ( ?, ? )''', (overlay_id, source_id,))
-
 connection.commit()
 
 
@@ -280,7 +297,7 @@ class DBHandler(object):
 '''
 cursor = None
 overlay_id = 0
-owner_id = 0
+owner_ids = []
 source_ids = []
 
 if overlay.name in self.overlays:
@@ -295,7 +312,7 @@ class DBHandler(object):
 
 

[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-08-27 Thread Devan Franchini
commit: bd5d65f3a1c6030fa63f6f3972a67f688d015cbc
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Thu Aug 27 17:36:22 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Thu Aug 27 17:36:22 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=bd5d65f3

overlay.py: Improves to_json() setting of descriptions

 layman/overlays/overlay.py | 4 +---
 1 file changed, 1 insertion(+), 3 deletions(-)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 31fe400..defa4e3 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -661,9 +661,7 @@ class Overlay(object):
 if self.license != None:
 repo['@license'] = self.license
 repo['name'] = self.name
-repo['description'] = []
-for i in self.descriptions:
-repo['description'].append(i)
+repo['description'] = [i for i in self.descriptions]
 if self.homepage != None:
 repo['homepage'] = self.homepage
 if self.irc != None:



[gentoo-commits] proj/layman:master commit in: layman/db_modules/sqlite_db/, layman/db_modules/json_db/, layman/, ...

2015-08-15 Thread Devan Franchini
commit: a7a267a46660e168bc1d46c4b39c4e89bed20767
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Sat Aug 15 08:00:35 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Sat Aug 15 08:00:37 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=a7a267a4

Adds remove parameter to database write() function

This parameter has been added in order to obtain proper
parallelization support for layman sqlite databases. With this
additional parameter it prompts the sqlite db module's write function to
simply return when removing an overlay, preventing it from re-adding any
database entires and causing oddness, run-time errors, or other unwanted
badness.

 layman/db.py |  2 +-
 layman/db_modules/json_db/json_db.py |  2 +-
 layman/db_modules/sqlite_db/sqlite_db.py | 11 +++
 layman/db_modules/xml_db/xml_db.py   |  2 +-
 layman/dbbase.py |  4 ++--
 5 files changed, 12 insertions(+), 9 deletions(-)

diff --git a/layman/db.py b/layman/db.py
index 673e6bf..a7ed1ce 100644
--- a/layman/db.py
+++ b/layman/db.py
@@ -149,7 +149,7 @@ class DB(DbBase):
 overlay.delete(self.config['storage'])
 repo_ok = self.repo_conf.delete(overlay)
 self.remove(overlay, self.path)
-self.write(self.path)
+self.write(self.path, remove=True)
 else:
 self.output.error('No local overlay named ' + overlay.name + '!')
 return False

diff --git a/layman/db_modules/json_db/json_db.py 
b/layman/db_modules/json_db/json_db.py
index d466385..70e41d5 100644
--- a/layman/db_modules/json_db/json_db.py
+++ b/layman/db_modules/json_db/json_db.py
@@ -112,7 +112,7 @@ class DBHandler(object):
 del self.overlays[overlay.name]
 
 
-def write(self, path):
+def write(self, path, remove=False):
 '''
 Write the list of overlays to a file.
 '''

diff --git a/layman/db_modules/sqlite_db/sqlite_db.py 
b/layman/db_modules/sqlite_db/sqlite_db.py
index 6619699..22ae5f3 100644
--- a/layman/db_modules/sqlite_db/sqlite_db.py
+++ b/layman/db_modules/sqlite_db/sqlite_db.py
@@ -283,6 +283,9 @@ class DBHandler(object):
 owner_id = 0
 source_ids = []
 
+if overlay.name in self.overlays:
+del self.overlays[overlay.name]
+
 with self.__connect__(path) as connection:
 cursor = connection.cursor()
 
@@ -318,14 +321,14 @@ class DBHandler(object):
 
 connection.commit()
 
-if overlay.name in self.overlays:
-del self.overlays[overlay.name]
-
 
-def write(self, path):
+def write(self, path, remove=False):
 '''
 Write the list of overlays to the database.
 '''
+if remove:
+return
+
 try:
 with self.__connect__(path) as connection:
 for overlay in self.overlays:

diff --git a/layman/db_modules/xml_db/xml_db.py 
b/layman/db_modules/xml_db/xml_db.py
index 316d8f9..fbd7a6a 100644
--- a/layman/db_modules/xml_db/xml_db.py
+++ b/layman/db_modules/xml_db/xml_db.py
@@ -157,7 +157,7 @@ class DBHandler(object):
 del self.overlays[overlay.name]
 
 
-def write(self, path):
+def write(self, path, remove=False):
 '''
 Write the list of overlays to a file.
 '''

diff --git a/layman/dbbase.py b/layman/dbbase.py
index cecbf5c..dc089d8 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -197,7 +197,7 @@ class DbBase(object):
 db_ctl.read_db(path, text=text)
 
 
-def write(self, path, migrate_type=None):
+def write(self, path, remove=False, migrate_type=None):
 '''
 Write the list of overlays to a file.
 '''
@@ -212,7 +212,7 @@ class DbBase(object):
  self.ignore,
  self.ignore_init_read_errors)
 
-db_ctl.write(path)
+db_ctl.write(path, remove=remove)
 
 
 def remove(self, overlay, path):



[gentoo-commits] proj/layman:master commit in: layman/db_modules/sqlite_db/

2015-08-13 Thread Devan Franchini
commit: 3e582a86a5389c5013fd0b8c5a6cc964d3252a2c
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Thu Aug 13 07:04:40 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Thu Aug 13 07:04:44 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=3e582a86

sqlite_db.py: Modifies owner information gathering method

Due to the fact that including the owner name isn't necessary layman
needed to modify the way it gathered owner information to prevent
run-time errors.

 layman/db_modules/sqlite_db/sqlite_db.py | 23 +--
 1 file changed, 9 insertions(+), 14 deletions(-)

diff --git a/layman/db_modules/sqlite_db/sqlite_db.py 
b/layman/db_modules/sqlite_db/sqlite_db.py
index 14bfa25..6619699 100644
--- a/layman/db_modules/sqlite_db/sqlite_db.py
+++ b/layman/db_modules/sqlite_db/sqlite_db.py
@@ -169,15 +169,15 @@ class DBHandler(object):
 WHERE Overlay_ID = ?''', (overlay_id,))
 overlay['source'] = cursor.fetchall()
 
-cursor.execute('''SELECT Owner_Name, Owner_Email FROM 
+cursor.execute('''SELECT Owner_Email, Owner_Name FROM 
 Overlay_Owner JOIN Overlay USING (Overlay_ID) JOIN Owner USING 
 (Owner_ID) WHERE Overlay_ID = ?''', (overlay_id,))
-owner_info = cursor.fetchall()
+owner_info = cursor.fetchall()[0]
 
-if len(owner_info):
-owner_info = owner_info[0]
-overlay['owner_name'] = owner_info[0]
-overlay['owner_email'] = owner_info[1]
+overlay['owner_email'] = owner_info[0]
+
+if len(owner_info)  1:
+overlay['owner_name'] = owner_info[1]
 
 cursor.execute('''SELECT Description FROM Description JOIN 
 Overlay USING (Overlay_ID) WHERE Overlay_ID = ?''',
@@ -187,12 +187,7 @@ class DBHandler(object):
 overlay['status'] = overlay_info[3]
 overlay['quality'] = overlay_info[4]
 overlay['priority'] = overlay_info[2]
-
-if overlay_info[7]:
-overlay['license'] = overlay_info[7]
-else:
-overlay['license'] = None
-
+overlay['license'] = overlay_info[7]
 overlay['homepage'] = overlay_info[5]
 overlay['IRC'] = overlay_info[6]
 
@@ -248,8 +243,8 @@ class DBHandler(object):
 VALUES ( ?, ? )''', (overlay.owner_name, overlay.owner_email,))
 connection.commit()
 
-cursor.execute('''SELECT Owner_ID from Owner WHERE Owner_Name = ?;''',
-(overlay.owner_name,))
+cursor.execute('''SELECT Owner_ID from Owner WHERE Owner_Email = ?;''',
+(overlay.owner_email,))
 owner_id = cursor.fetchone()[0]
 
 for source in overlay.sources:



[gentoo-commits] proj/layman:master commit in: layman/db_modules/xml_db/, layman/db_modules/sqlite_db/, layman/, ...

2015-08-05 Thread Devan Franchini
commit: daafd7d31457b018797407d97188a4829839172e
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Wed Aug  5 05:55:16 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Wed Aug  5 05:58:59 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=daafd7d3

Adds remove function for overlay removal from databases

sqlite_db.py: Also changes the way in which feeds are gathered in
read_db(), this shows the nature of feeds being an unrequired attribute
of the overlay.

 layman/db.py |  2 +-
 layman/db_modules/json_db/__init__.py|  3 ++-
 layman/db_modules/json_db/json_db.py |  8 
 layman/db_modules/sqlite_db/__init__.py  |  5 +++--
 layman/db_modules/sqlite_db/sqlite_db.py | 23 ---
 layman/db_modules/xml_db/__init__.py |  3 ++-
 layman/db_modules/xml_db/xml_db.py   |  8 
 layman/dbbase.py | 13 +
 8 files changed, 53 insertions(+), 12 deletions(-)

diff --git a/layman/db.py b/layman/db.py
index ba7399c..673e6bf 100644
--- a/layman/db.py
+++ b/layman/db.py
@@ -148,7 +148,7 @@ class DB(DbBase):
 if overlay.name in self.overlays.keys():
 overlay.delete(self.config['storage'])
 repo_ok = self.repo_conf.delete(overlay)
-del self.overlays[overlay.name]
+self.remove(overlay, self.path)
 self.write(self.path)
 else:
 self.output.error('No local overlay named ' + overlay.name + '!')

diff --git a/layman/db_modules/json_db/__init__.py 
b/layman/db_modules/json_db/__init__.py
index 1502b9d..ac4daa7 100644
--- a/layman/db_modules/json_db/__init__.py
+++ b/layman/db_modules/json_db/__init__.py
@@ -13,10 +13,11 @@ module_spec = {
 'name': 'json_db',
 'class': 'DBHandler',
 'description': __doc__,
-'functions': ['add_new', 'read_db', 'write'],
+'functions': ['add_new', 'read_db', 'remove', 'write'],
 'func_desc': {
 'add_new': 'Adds overlay(s) from provided database text',
 'read_db': 'Reads the list of overlays from database file',
+'remove' : 'Removes overlay from installed overlays list',
 'write'  : 'Writes the list of overlays to database file',
 },
 }

diff --git a/layman/db_modules/json_db/json_db.py 
b/layman/db_modules/json_db/json_db.py
index 47413c6..d466385 100644
--- a/layman/db_modules/json_db/json_db.py
+++ b/layman/db_modules/json_db/json_db.py
@@ -104,6 +104,14 @@ class DBHandler(object):
 return True
 
 
+def remove(self, overlay, path):
+'''
+Removes an overlay from installed overlays list.
+'''
+if overlay.name in self.overlays:
+del self.overlays[overlay.name]
+
+
 def write(self, path):
 '''
 Write the list of overlays to a file.

diff --git a/layman/db_modules/sqlite_db/__init__.py 
b/layman/db_modules/sqlite_db/__init__.py
index 7d2fba4..536fc2d 100644
--- a/layman/db_modules/sqlite_db/__init__.py
+++ b/layman/db_modules/sqlite_db/__init__.py
@@ -13,10 +13,11 @@ module_spec = {
 'name': 'sqlite_db',
 'class': 'DBHandler',
 'description': __doc__,
-'functions': ['add_new', 'read_db', 'write'],
+'functions': ['add_new', 'read_db', 'remove', 'write'],
 'func_desc': {
-'add_new': 'Adds overlay(s) from provided database text',
+'add_new': 'Adds overlay(s) from provided database file',
 'read_db': 'Reads the list of overlays from database file',
+'remove' : 'Removes overlay from provided database file',
 'write'  : 'Writes the list of overlays to database file',
 },
 }

diff --git a/layman/db_modules/sqlite_db/sqlite_db.py 
b/layman/db_modules/sqlite_db/sqlite_db.py
index 1d079a3..aef9661 100644
--- a/layman/db_modules/sqlite_db/sqlite_db.py
+++ b/layman/db_modules/sqlite_db/sqlite_db.py
@@ -103,8 +103,8 @@ class DBHandler(object):
 cursor.execute('''CREATE TABLE IF NOT EXISTS Overlay
 ( Overlay_ID INTEGER PRIMARY KEY AUTOINCREMENT, Name TEXT, 
 Priority TEXT, Status TEXT, Quality TEXT, Homepage 
-TEXT, IRC TEXT, License TEXT, UNIQUE (Name, Homepage, License) 
-ON CONFLICT IGNORE )''')
+TEXT, IRC TEXT, License TEXT, UNIQUE (Name) ON CONFLICT IGNORE 
)
+''')
 cursor.execute('''CREATE TABLE IF NOT EXISTS Owner ( Owner_ID
 INTEGER PRIMARY KEY AUTOINCREMENT, Owner_Name TEXT, 
 Owner_Email TEXT, UNIQUE (Owner_Name, Owner_Email) ON 
@@ -180,15 +180,17 @@ class DBHandler(object):
 
 cursor.execute('''SELECT Description FROM Description JOIN Overlay 
 USING (Overlay_ID) 

[gentoo-commits] proj/layman:master commit in: layman/db_modules/sqlite_db/

2015-08-05 Thread Devan Franchini
commit: 59ce97acb46ddef1b564ab4032c145ed70c92427
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Wed Aug  5 06:22:24 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Wed Aug  5 06:22:31 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=59ce97ac

sqlite_db.py: read_db() connects to database with with command

 layman/db_modules/sqlite_db/sqlite_db.py | 107 ---
 1 file changed, 54 insertions(+), 53 deletions(-)

diff --git a/layman/db_modules/sqlite_db/sqlite_db.py 
b/layman/db_modules/sqlite_db/sqlite_db.py
index aef9661..14bfa25 100644
--- a/layman/db_modules/sqlite_db/sqlite_db.py
+++ b/layman/db_modules/sqlite_db/sqlite_db.py
@@ -148,63 +148,64 @@ class DBHandler(object):
 '''
 Read the overlay definitions from the database and generate overlays.
 '''
-connection = self.__connect__(path)
-cursor = connection.cursor()
+cursor = None
 overlay_id = None
 overlay = {}
 
-cursor.execute('''SELECT Overlay_ID, Name, Priority, Status, Quality, 
-Homepage, IRC, License FROM Overlay''')
-overlays_info = cursor.fetchall()
-connection.commit()
+with self.__connect__(path) as connection:
+cursor = connection.cursor()
+cursor.execute('''SELECT Overlay_ID, Name, Priority, Status, 
+Quality, Homepage, IRC, License FROM Overlay''')
+overlays_info = cursor.fetchall()
+connection.commit()
 
-for overlay_info in overlays_info:
-overlay = {}
-overlay_id = overlay_info[0]
-overlay['name'] = overlay_info[1]
-
-cursor.execute('''SELECT URL, Type, Branch FROM Overlay_Source 
-JOIN Overlay USING (Overlay_ID) JOIN Source USING (Source_ID) 
-WHERE Overlay_ID = ?''', (overlay_id,))
-overlay['source'] = cursor.fetchall()
-
-cursor.execute('''SELECT Owner_Name, Owner_Email FROM 
-Overlay_Owner JOIN Overlay USING (Overlay_ID) JOIN Owner USING 
-(Owner_ID) WHERE Overlay_ID = ?''', (overlay_id,))
-owner_info = cursor.fetchall()
-
-if len(owner_info):
-owner_info = owner_info[0]
-overlay['owner_name'] = owner_info[0]
-overlay['owner_email'] = owner_info[1]
-
-cursor.execute('''SELECT Description FROM Description JOIN Overlay 
-USING (Overlay_ID) WHERE Overlay_ID = ?''', (overlay_id,))
-overlay['description'] = cursor.fetchall()[0]
-
-overlay['status'] = overlay_info[3]
-overlay['quality'] = overlay_info[4]
-overlay['priority'] = overlay_info[2]
-
-if overlay_info[7]:
-overlay['license'] = overlay_info[7]
-else:
-overlay['license'] = None
-
-overlay['homepage'] = overlay_info[5]
-overlay['IRC'] = overlay_info[6]
-
-cursor.execute('''SELECT Feed FROM Feed JOIN Overlay USING 
-(Overlay_ID) WHERE Overlay_ID = ?''', (overlay_id,))
-overlay['feed'] = cursor.fetchall()
-
-if len(overlay['feed']):
-overlay['feed'] = overlay['feed'][0]
-
-self.overlays[overlay_info[1]] = Overlay(self.config,
- ovl_dict=overlay,
- ignore=self.ignore)
-connection.close()
+for overlay_info in overlays_info:
+overlay = {}
+overlay_id = overlay_info[0]
+overlay['name'] = overlay_info[1]
+
+cursor.execute('''SELECT URL, Type, Branch FROM Overlay_Source 
+JOIN Overlay USING (Overlay_ID) JOIN Source USING (Source_ID) 
+WHERE Overlay_ID = ?''', (overlay_id,))
+overlay['source'] = cursor.fetchall()
+
+cursor.execute('''SELECT Owner_Name, Owner_Email FROM 
+Overlay_Owner JOIN Overlay USING (Overlay_ID) JOIN Owner USING 
+(Owner_ID) WHERE Overlay_ID = ?''', (overlay_id,))
+owner_info = cursor.fetchall()
+
+if len(owner_info):
+owner_info = owner_info[0]
+overlay['owner_name'] = owner_info[0]
+overlay['owner_email'] = owner_info[1]
+
+cursor.execute('''SELECT Description FROM Description JOIN 
+Overlay USING (Overlay_ID) WHERE Overlay_ID = ?''',
+(overlay_id,))
+overlay['description'] = cursor.fetchall()[0]
+
+overlay['status'] = overlay_info[3]
+overlay['quality'] = overlay_info[4]
+overlay['priority'] = overlay_info[2]
+
+if overlay_info[7]:
+overlay['license'] = 

[gentoo-commits] proj/layman:master commit in: layman/, /, layman/db_modules/sqlite_db/

2015-08-03 Thread Devan Franchini
commit: b8963040c8da23570823075399ec807c2787f484
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Tue Aug  4 00:19:39 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Tue Aug  4 00:19:42 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=b8963040

Adds SQLite databasing module support

constants.py: Adds sqlite to list of supported database modules.
setup.py: Adds db_modules.sqlite_db.sqlite_db to list of installable
modules.

 layman/constants.py  |   2 +-
 layman/db_modules/sqlite_db/__init__.py  |  24 +++
 layman/db_modules/sqlite_db/sqlite_db.py | 332 +++
 setup.py |   4 +-
 4 files changed, 359 insertions(+), 3 deletions(-)

diff --git a/layman/constants.py b/layman/constants.py
index f8292f7..a83ce07 100644
--- a/layman/constants.py
+++ b/layman/constants.py
@@ -91,4 +91,4 @@ MOUNT_TYPES = ['Squashfs']
 ## Supported database types
 ##
 

-DB_TYPES = ['json', 'xml']
+DB_TYPES = ['json', 'sqlite', 'xml']

diff --git a/layman/db_modules/sqlite_db/__init__.py 
b/layman/db_modules/sqlite_db/__init__.py
new file mode 100644
index 000..7d2fba4
--- /dev/null
+++ b/layman/db_modules/sqlite_db/__init__.py
@@ -0,0 +1,24 @@
+# Copyright 2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+'''
+SQLite database plug-in module for layman.
+'''
+
+module_spec = {
+'name': 'sqlite_db',
+'description': __doc__,
+'provides':{
+'sqlite-module': {
+'name': 'sqlite_db',
+'class': 'DBHandler',
+'description': __doc__,
+'functions': ['add_new', 'read_db', 'write'],
+'func_desc': {
+'add_new': 'Adds overlay(s) from provided database text',
+'read_db': 'Reads the list of overlays from database file',
+'write'  : 'Writes the list of overlays to database file',
+},
+}
+}
+}

diff --git a/layman/db_modules/sqlite_db/sqlite_db.py 
b/layman/db_modules/sqlite_db/sqlite_db.py
new file mode 100644
index 000..1d079a3
--- /dev/null
+++ b/layman/db_modules/sqlite_db/sqlite_db.py
@@ -0,0 +1,332 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# LAYMAN SQLite DB
+#
+# File:   sqlite_db.py
+#
+# Access SQLite overlay database(s).
+#
+# Copyright:
+# (c) 2015Devan Franchini
+# Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+# Devan Franchini twitch...@gentoo.org
+#
+'''Handler for sqlite overlay databases.'''
+
+from __future__ import unicode_literals
+
+__version__ = $Id: sqlite_db.py 273 2015-08-03 20:17:30Z twitch153 $
+
+#===
+#
+# Dependencies
+#
+#---
+
+import os
+import sys
+import sqlite3
+
+from   layman.overlays.overlay   import Overlay
+
+#py3.2+
+if sys.hexversion = 0x30200f0:
+_UNICODE = 'unicode'
+else:
+_UNICODE = 'UTF-8'
+
+
+#===
+#
+# Class DBHandler
+#
+#---
+
+class DBHandler(object):
+'''
+Handle a SQLite overlay database.
+'''
+
+def __init__(self, config, overlays, paths=None, ignore=0,
+ ignore_init_read_errors=False):
+
+self.config = config
+self.ignore = ignore
+self.overlays = overlays
+self.paths = paths
+self.output = config['output']
+self.ignore_init_read_errors = ignore_init_read_errors
+
+self.output.debug('Initializing SQLite overlay list handler', 8)
+
+
+def __connect__(self, path):
+'''
+Establish connection with the SQLite database.
+'''
+if not os.path.exists(path):
+if not self.ignore_init_read_errors:
+msg = 'SQLite DBHandler warning; database previously '\
+  'non-existent.\nCreating database now...'
+self.output.warn(msg, 2)
+
+if not os.access(os.path.dirname(path), os.W_OK):
+msg = 'SQLite DBHandler error; cannot create database.\n'
+errmsg = 'Write permissions are not given in dir: %(dir)s'\
+  % {'dir': os.path.dirname(path)}
+self.output.error(msg + errmsg)
+
+raise Exception(errmsg)
+
+if os.path.exists(path) and not os.access(path, os.R_OK):
+msg = 'SQLite DBHandler error; database 

[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-08-03 Thread Devan Franchini
commit: 16752532c5f7e3dd74745f4ca093278f8c71a90f
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Aug  3 20:26:41 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Aug  3 20:26:41 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=16752532

overlay.py: Reorganizes imports and cleans up init params

 layman/overlays/overlay.py | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 8f31a76..31fe400 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -32,9 +32,12 @@ __version__ = 0.2
 #
 
#---
 
-import sys, re, os, os.path
 import codecs
 import locale
+import os
+import os.path
+import re
+import sys
 import xml.etree.ElementTree as ET # Python 2.5
 
 from  layman.compatibility import encode
@@ -56,8 +59,7 @@ WHITESPACE_REGEX = re.compile('\s+')
 class Overlay(object):
 ''' Derive the real implementations from this.'''
 
-def __init__(self, config, json=None, ovl_dict=None, xml=None,
-ignore = 0):
+def __init__(self, config, json=None, ovl_dict=None, xml=None, ignore=0):
 self.config = config
 self.output = config['output']
 self.module_controller = Modules(path=MOD_PATH,



[gentoo-commits] proj/layman:master commit in: layman/

2015-08-03 Thread Devan Franchini
commit: d95ae901856d94b2f7693b58aaa5618582c17280
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Tue Aug  4 01:02:38 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Tue Aug  4 01:02:38 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=d95ae901

update.py: Adds functionality to ensure proper sqlite migration

 layman/updater.py | 5 -
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/layman/updater.py b/layman/updater.py
index 746373d..25abf72 100644
--- a/layman/updater.py
+++ b/layman/updater.py
@@ -140,7 +140,10 @@ class Main(object):
 self.output.info(msg)
 
 try:
-shutil.copy(installed, backup_name)
+if migrate_type in ('json', 'xml'):
+shutil.copy(installed, backup_name)
+else:
+shutil.move(installed, backup_name)
 except IOError as err:
 msg = '  migrate_database() error; failed to back up old database 
'\
   'file.\n  Error was: %(err)s' % {'err': err}



[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-07-21 Thread Devan Franchini
commit: 8133bd98d60e3e1ed38fa75662ae9b070a156336
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Tue Jul 21 16:37:53 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Tue Jul 21 16:37:53 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=8133bd98

overlay.py: Adds optional license attribute to overlay object

 layman/overlays/overlay.py | 19 +++
 1 file changed, 19 insertions(+)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index c6a0cee..8f31a76 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -237,6 +237,11 @@ class Overlay(object):
 else:
 self.priority = 50
 
+if 'license' in overlay:
+self.license = encode(overlay['license'])
+else:
+self.license = None
+
 if 'homepage' in overlay:
 self.homepage = encode(overlay['homepage'])
 else:
@@ -352,6 +357,11 @@ class Overlay(object):
 else:
 self.priority = 50
 
+if '@license' in json:
+self.license = encode(json['@license'])
+else:
+self.license = None
+
 if 'homepage' in json:
 self.homepage = encode(json['homepage'])
 else:
@@ -486,6 +496,11 @@ class Overlay(object):
 else:
 self.priority = 50
 
+if 'license' in xml.attrib:
+self.license = encode(xml.attrib['license'])
+else:
+self.license = None
+
 h = xml.find('homepage')
 l = xml.find('link')
 
@@ -641,6 +656,8 @@ class Overlay(object):
 repo['@quality'] = self.quality
 if self.status != None:
 repo['@status'] = self.status
+if self.license != None:
+repo['@license'] = self.license
 repo['name'] = self.name
 repo['description'] = []
 for i in self.descriptions:
@@ -677,6 +694,8 @@ class Overlay(object):
 repo.attrib['status'] = self.status
 repo.attrib['quality'] = self.quality
 repo.attrib['priority'] = str(self.priority)
+if self.license != None:
+repo.attrib['license'] = self.license
 name = ET.Element('name')
 name.text = self.name
 repo.append(name)



[gentoo-commits] proj/layman:master commit in: layman/tests/testfiles/, layman/, layman/tests/

2015-07-20 Thread Devan Franchini
commit: e8160e953d4c1c9792c8640fd3edbe6ac1d39e9e
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 20 13:57:09 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 20 13:57:11 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=e8160e95

external.py: Adds json DB testing

updater.py: Adds proper line spacing for database migration output

 layman/tests/external.py| 28 ++
 layman/tests/testfiles/global-overlays.json | 44 +
 layman/updater.py   |  2 +-
 3 files changed, 73 insertions(+), 1 deletion(-)

diff --git a/layman/tests/external.py b/layman/tests/external.py
index e9f419a..f61d4b6 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -673,6 +673,7 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 
 def read_db(self):
 output = Message()
+# First test if XML databasing works.
 config = {'output': output,
   'db_type': 'xml',}
 db = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
@@ -682,6 +683,15 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 url = ['rsync://gunnarwrobel.de/wrobel-stable']
 self.assertEqual(list(db.overlays['wrobel-stable'].source_uris()), url)
 
+# Test JSON databasing after.
+config['db_type'] = 'json'
+db = DbBase(config, [HERE + '/testfiles/global-overlays.json', ])
+keys = sorted(db.overlays)
+self.assertEqual(keys, ['twitch153', 'wrobel-stable'])
+
+url = ['git://github.com/twitch153/ebuilds.git']
+self.assertEqual(list(db.overlays['twitch153'].source_uris()), url)
+
 
 def select_db(self):
 output = Message()
@@ -691,10 +701,16 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 url = ['rsync://gunnarwrobel.de/wrobel-stable']
 self.assertEqual(list(db.select('wrobel-stable').source_uris()), url)
 
+config['db_type'] = 'json'
+db = DbBase(config, [HERE + '/testfiles/global-overlays.json', ])
+url = ['git://github.com/twitch153/ebuilds.git']
+self.assertEqual(list(db.select('twitch153').source_uris()), url)
+
 
 def write_db(self):
 tmpdir = tempfile.mkdtemp(prefix='laymantmp_')
 test_xml = os.path.join(tmpdir, 'test.xml')
+test_json = os.path.join(tmpdir, 'test.json')
 config = BareConfig()
 
 a = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
@@ -707,8 +723,20 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 keys = sorted(c.overlays)
 self.assertEqual(keys, ['wrobel-stable'])
 
+config.set_option('db_type', 'json')
+a = DbBase(config, [HERE + '/testfiles/global-overlays.json', ])
+b = DbBase({'output': Message(), 'db_type': 'json'}, [test_json,])
+
+b.overlays['twitch153'] = a.overlays['twitch153']
+b.write(test_json)
+
+c = DbBase({'output': Message(), 'db_type': 'json'}, [test_json,])
+keys = sorted(c.overlays)
+self.assertEqual(keys, ['twitch153'])
+
 # Clean up:
 os.unlink(test_xml)
+os.unlink(test_json)
 shutil.rmtree(tmpdir)
 
 

diff --git a/layman/tests/testfiles/global-overlays.json 
b/layman/tests/testfiles/global-overlays.json
new file mode 100644
index 000..53267cf
--- /dev/null
+++ b/layman/tests/testfiles/global-overlays.json
@@ -0,0 +1,44 @@
+{
+  @encoding: unicode,
+  @version: 1.0,
+  repo: [
+{
+  @priority: 40,
+  @quality: experimental,
+  @status: unofficial,
+  description: [
+Twitch test
+  ],
+  feed: [
+https://github.com/twitch153/ebuilds/commits/master.atom;
+  ],
+  homepage: https://github.com/twitch153/ebuilds;,
+  name: twitch153,
+  owner: {
+email: twitch...@gentoo.org,
+name: Devan Franchini
+  },
+  source: [
+{
+  #text: git://github.com/twitch153/ebuilds.git,
+  @type: git
+}
+  ]
+},
+{
+  description: [
+A collection of ebuilds from Gunnar Wrobel [wro...@gentoo.org].
+  ],
+  name: wrobel-stable,
+  owner: {
+email: nob...@gentoo.org
+  },
+  source: [
+{
+  #text: rsync://gunnarwrobel.de/wrobel-stable,
+  @type: rsync
+}
+  ]
+}
+  ]
+}

diff --git a/layman/updater.py b/layman/updater.py
index 9d7b176..746373d 100644
--- a/layman/updater.py
+++ b/layman/updater.py
@@ -158,7 +158,7 @@ class Main(object):
 raise err
 
 msg = '  Successfully migrated database from %(from_type)s to '\
-  '%(to_type)s\n' % {'from_type': self.config['db_type'],
+  ' %(to_type)s\n' % {'from_type': self.config['db_type'],
'to_type': migrate_type}
 self.output.info(msg)
 



[gentoo-commits] proj/layman:master commit in: layman/

2015-07-18 Thread Devan Franchini
commit: 4adf2984147062b8cadc5e769aa49c48abab2e93
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Sun Jul 19 03:50:25 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Sun Jul 19 03:52:15 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=4adf2984

updater.py: Modifies the db_type setting method

In order to preserve the config file set up of the layman config
file the set_db_type() function has been modified to not use
configparser as it doesn't preserve comments. Changes have also
been made in case the database file ends with the old extension,
so the backup name will end in .bak as opposed to the database's
file type.

 layman/updater.py | 36 +---
 1 file changed, 25 insertions(+), 11 deletions(-)

diff --git a/layman/updater.py b/layman/updater.py
index f727632..9d7b176 100644
--- a/layman/updater.py
+++ b/layman/updater.py
@@ -7,6 +7,7 @@ import argparse
 import os
 import shutil
 import sys
+import re
 
 from layman.api   import LaymanAPI
 from layman.compatibility import fileopen
@@ -122,8 +123,10 @@ class Main(object):
 
 db = DB(self.config)
 installed = self.config['installed']
-backup_name = installed + '.' + self.config['db_type']
 old_ext = os.path.splitext(installed)[1]
+backup_name = installed + '.' + self.config['db_type']
+if old_ext == self.config['db_type']:
+backup_name = installed + '.bak'
 new_name = installed.replace(old_ext, '.db')
 
 if not os.path.isfile(installed):
@@ -271,17 +274,15 @@ class Main(object):
 repos_conf = ConfigHandler(self.config, overlays)
 repos_conf.write()
 
-def set_db_type(self, migrate_type, installed):
-if sys.hexversion = 0x30200f0:
-import configparser as ConfigParser
-else:
-import ConfigParser
 
-config = ConfigParser.ConfigParser()
+def set_db_type(self, migrate_type, installed):
 config_path = self.config['config']\
   % {'configdir': self.config['configdir']}
+db_type_found = False
+installed_found = False
 new_conf = os.path.dirname(config_path) + '/' + '._cfg_' +\
os.path.basename(config_path)
+new_lines = []
 
 try:
 shutil.copy(config_path, new_conf)
@@ -300,15 +301,28 @@ class Main(object):
 raise Exception(msg)
 
 try:
-config.read(new_conf)
+with fileopen(new_conf, 'r') as laymanconf:
+lines = laymanconf.readlines()
 except Exception as err:
 msg = '  set_db_type() error; failed to read config at 
%(path)s.'\
   '\n  Error was: %(err)s' % {'path': new_conf, 'err': err}
 self.output.error(msg)
 raise err
 
-config.set('MAIN', 'db_type', migrate_type)
-config.set('MAIN', 'installed', '%(storage)s/'+installed)
+for line in lines:
+if re.search('^#*\s*db_type\s*:', line):
+db_type_found = True
+line = 'db_type : ' + migrate_type + '\n'
+if re.search('^#*\s*installed\s*:', line):
+installed_found = True
+line = 'installed : %(storage)s/' + installed + '\n'
+new_lines.append(line)
+
+if not db_type_found:
+new_lines.append('db_type : ' + migrate_type + '\n')
+if not installed_found:
+new_lines.append('installed : %(storage)s/' + installed + '\n')
 
 with fileopen(new_conf, 'w') as laymanconf:
-config.write(laymanconf)
+for line in new_lines:
+laymanconf.write(line)



[gentoo-commits] proj/layman:master commit in: layman/

2015-07-17 Thread Devan Franchini
commit: 3c05ffbe24899799a6b744212e7308d251679932
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Jul 17 16:25:59 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Jul 17 16:26:44 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=3c05ffbe

updater.py: Cleans up imports

 layman/updater.py | 9 -
 1 file changed, 4 insertions(+), 5 deletions(-)

diff --git a/layman/updater.py b/layman/updater.py
index 1959a31..54ea86a 100644
--- a/layman/updater.py
+++ b/layman/updater.py
@@ -3,15 +3,14 @@
 
 from __future__ import unicode_literals
 
-from sys import stderr
+import argparse
 import os
 import sys
-import argparse
 
-from layman.config import OptionConfig
-from layman.api import LaymanAPI
-from layman.version import VERSION
+from layman.api   import LaymanAPI
 from layman.compatibility import fileopen
+from layman.configimport OptionConfig
+from layman.version   import VERSION
 
 if sys.hexversion = 0x30200f0:
 STR = str



[gentoo-commits] proj/layman:master commit in: layman/

2015-07-17 Thread Devan Franchini
commit: 46846091abef6fb8339ad640c1baa25c63e85bc9
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Jul 17 16:12:26 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Jul 17 16:18:04 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=46846091

constants.py: Adds constant DB_TYPES for supported db checking

 layman/constants.py | 27 +--
 1 file changed, 17 insertions(+), 10 deletions(-)

diff --git a/layman/constants.py b/layman/constants.py
index a39071f..f8292f7 100644
--- a/layman/constants.py
+++ b/layman/constants.py
@@ -1,8 +1,8 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
-#
+
 # LAYMAN CONSTANTS
-#
+
 # File:   constants.py
 #
 # Handles layman actions via the command line interface.
@@ -26,11 +26,11 @@ __version__ = $Id: constants.py 2011-01-16 23:52 PST Brian 
Dolbec$
 
 
 
-#
+
 ##
 ## Color codes (taken from portage)
 ##
-#
+
 
 esc_seq = '\x1b['
 
@@ -57,31 +57,38 @@ DEBUG_VERBOSITY = 2
 FAILURE = 1
 SUCCEED = 0
 
-#
+
 ##
 ## Overlay components
 ##
-#
+
 
 COMPONENT_DEFAULTS  = ['name', 'description', 'owner', 'type', 'source']
 POSSIBLE_COMPONENTS = ['name', 'description', 'homepage', 'owner', 'quality',
'priority', 'source', 'branch', 'irc', 'feed']
 
-###
+
 ##
 ## Archive overlay possible file extensions
 ##
-###
+
 
 FILE_EXTENSIONS = {'Squashfs': ('.squashfs', '.squash', '.sqfs', '.sfs'),
'Tar': ('bz2', 'gz', 'lzma', 'xz', 'Z', 'tgz', 'tbz', 'taz',
'tlz', 'txz'),
   }
 
-###
+
 ##
 ## Overlay types mountable by script
 ##
-
+
 
 MOUNT_TYPES = ['Squashfs']
+
+
+##
+## Supported database types
+##
+
+DB_TYPES = ['json', 'xml']



[gentoo-commits] proj/layman:master commit in: layman/, layman/tests/, etc/

2015-07-17 Thread Devan Franchini
commit: 8fce6fd8a4057222edc07478c6ba19c68bb0aaa3
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Jul 17 16:21:37 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Jul 17 16:23:48 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=8fce6fd8

Removes unnecessary _db appendage to db_type var

To avoid namespace collisions in py2.7 the database modules needed
to have _db appended to their name. In order to avoid having this
ugliness in the user's config file and elsewhere in layman's code
the DbBase class simply adds the _db portion of the name itself.

 etc/layman.cfg   |  4 ++--
 layman/config.py |  2 +-
 layman/dbbase.py |  6 +++---
 layman/remotedb.py   |  2 +-
 layman/tests/external.py | 20 ++--
 5 files changed, 17 insertions(+), 17 deletions(-)

diff --git a/etc/layman.cfg b/etc/layman.cfg
index 5101f4d..e1caa33 100644
--- a/etc/layman.cfg
+++ b/etc/layman.cfg
@@ -68,8 +68,8 @@ conf_type : repos.conf
  Database Config Options   COMING SOON 
 #---
 # Database types used by layman, only one should be specified.
-# (xml_db, json_db)
-#db_type : xml_db
+# (xml, json)
+#db_type : xml
 
 #---
 

diff --git a/layman/config.py b/layman/config.py
index 0ad975b..853e22f 100644
--- a/layman/config.py
+++ b/layman/config.py
@@ -100,7 +100,7 @@ class BareConfig(object):
 'auto_sync': 'No',
 'check_official': 'Yes',
 'conf_type': 'repos.conf',
-'db_type': 'xml_db',
+'db_type': 'xml',
 'require_repoconfig': 'Yes',
 'clean_archive': 'yes',
 'make_conf' : '%(storage)s/make.conf',

diff --git a/layman/dbbase.py b/layman/dbbase.py
index 283d65c..7832565 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -105,7 +105,7 @@ class DbBase(object):
   % {'db_types': self.db_type, 'db_type': self.db_type[0]}
 self.output.warn(msg)
 
-self.db_type = self.db_type[0]
+self.db_type = self.db_type[0] + '_db'
 
 for path in self.paths:
 if not os.path.exists(path):
@@ -182,7 +182,7 @@ class DbBase(object):
 db_type = self.db_type
 
 if text and text_type:
-db_type = text_type
+db_type = text_type + '_db'
 
 #Added to keep xml functionality for cached overlay XML definitions
 if 'cache' in path and '.xml' in path:
@@ -204,7 +204,7 @@ class DbBase(object):
 db_type = self.db_type
 
 if migrate_type:
-db_type = migrate_type
+db_type = migrate_type + '_db'
 
 db_ctl = self.mod_ctl.get_class(db_type)(self.config,
  self.overlays,

diff --git a/layman/remotedb.py b/layman/remotedb.py
index 89caf7a..b9c4ae0 100644
--- a/layman/remotedb.py
+++ b/layman/remotedb.py
@@ -280,7 +280,7 @@ class RemoteDB(DbBase):
 def _check_download(self, olist, url):
 
 try:
-self.read_db(url, text=olist, text_type=xml_db)
+self.read_db(url, text=olist, text_type=xml)
 except Exception as error:
 self.output.debug(RemoteDB._check_download(), url=%s \nolist:\n
 % url,2)

diff --git a/layman/tests/external.py b/layman/tests/external.py
index 01cf5b3..e9f419a 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -154,7 +154,7 @@ class AddDeleteDB(unittest.TestCase):
 
 my_opts = {'installed' : temp_xml_path,
'conf_type' : ['make.conf', 'repos.conf'],
-   'db_type'   : 'xml_db',
+   'db_type'   : 'xml',
'nocheck'   : 'yes',
'make_conf' : make_conf,
'repos_conf': repo_conf,
@@ -556,7 +556,7 @@ class OverlayObjTest(unittest.TestCase):
 overlays = document.findall('overlay') + document.findall('repo')
 output = Message()
 
-ovl_a = Overlay({'output': output, 'db_type': 'xml_db'}, 
xml=overlays[0])
+ovl_a = Overlay({'output': output, 'db_type': 'xml'}, xml=overlays[0])
 self.assertEqual(ovl_a.name, 'wrobel')
 self.assertEqual(ovl_a.is_official(), True)
 url = ['https://overlays.gentoo.org/svn/dev/wrobel']
@@ -565,7 +565,7 @@ class OverlayObjTest(unittest.TestCase):
 self.assertEqual(ovl_a.descriptions, ['Test'])
 self.assertEqual(ovl_a.priority, 10)
 
-ovl_b = Overlay({'output': output, 'db_type': 'xml_db'}, 
xml=overlays[1])
+ovl_b = Overlay({'output': output, 'db_type': 'xml'}, xml=overlays[1])
 self.assertEqual(ovl_b.is_official(), False)
 
 
@@ -574,7 +574,7 @@ class OverlayObjTest(unittest.TestCase):
 overlays = document.findall('overlay') + document.findall('repo')
 output = Message()
 
-   

[gentoo-commits] proj/layman:master commit in: layman/

2015-07-17 Thread Devan Franchini
commit: 8448d587d1e8367ba5b2cc5aa6214166dc0649f1
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Jul 17 17:05:01 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Jul 17 17:06:02 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=8448d587

updater.py: Adds database migration tool

 layman/updater.py | 105 +-
 1 file changed, 104 insertions(+), 1 deletion(-)

diff --git a/layman/updater.py b/layman/updater.py
index 54ea86a..f727632 100644
--- a/layman/updater.py
+++ b/layman/updater.py
@@ -5,11 +5,14 @@ from __future__ import unicode_literals
 
 import argparse
 import os
+import shutil
 import sys
 
 from layman.api   import LaymanAPI
 from layman.compatibility import fileopen
 from layman.configimport OptionConfig
+from layman.constants import DB_TYPES
+from layman.dbimport DB
 from layman.version   import VERSION
 
 if sys.hexversion = 0x30200f0:
@@ -56,6 +59,8 @@ class Main(object):
 help = 'Print the NEW INSTALL help messages.')
 self.parser.add_argument(-c, --config,
 help='the path to config file')
+self.parser.add_argument(-m, --migrate_db,
+help=the database you'd like to migrate to)
 self.parser.add_argument(-R, --rebuild, action='store_true',
 help='rebuild the Package Manager config file')
 self.parser.add_argument('--version', action='version',
@@ -88,7 +93,8 @@ class Main(object):
 self.print_instructions()
 elif not self.check_is_new(self.args.rebuild):
 self.rename_check()
-
+if self.args.migrate_db:
+self.migrate_database(self.args.migrate_db)
 
 def check_is_new(self, rebuild=False):
 print_instructions = False
@@ -106,6 +112,61 @@ class Main(object):
 return False
 
 
+
+def migrate_database(self, migrate_type):
+if migrate_type not in DB_TYPES:
+msg = 'migrate_database() error; invalid migration type: '\
+  '%(db_type)s' % {'db_type': migrate_type}
+self.output.error('  ' + msg)
+raise Exception(msg)
+
+db = DB(self.config)
+installed = self.config['installed']
+backup_name = installed + '.' + self.config['db_type']
+old_ext = os.path.splitext(installed)[1]
+new_name = installed.replace(old_ext, '.db')
+
+if not os.path.isfile(installed):
+msg = 'migrate_database() error; database file %(loc)s does not 
'\
+  'exist!' % {'loc': backup_name}
+self.output.error('  ' + msg)
+raise Exception(msg)
+
+msg = '  Creating backup of %(db)s at:\n %(loc)s\n'\
+  % {'db': installed, 'loc': backup_name}
+self.output.info(msg)
+
+try:
+shutil.copy(installed, backup_name)
+except IOError as err:
+msg = '  migrate_database() error; failed to back up old database 
'\
+  'file.\n  Error was: %(err)s' % {'err': err}
+self.output.error(msg)
+raise err
+
+db.write(installed, migrate_type=migrate_type)
+
+try:
+os.rename(installed, new_name)
+except OSError as err:
+msg = '  migrate_database() error: failed to rename old database '\
+  ' to %(name)s.\n  Error was: %(err)s' % {'err': err}
+self.output.error(msg)
+raise err
+
+msg = '  Successfully migrated database from %(from_type)s to '\
+  '%(to_type)s\n' % {'from_type': self.config['db_type'],
+   'to_type': migrate_type}
+self.output.info(msg)
+
+self.set_db_type(migrate_type, os.path.basename(installed))
+
+msg = '  Warning: Please be sure to update your config file via '\
+  'the\n  `dispatch-conf` command or you *will* lose database '\
+  'functionality!\n'
+self.output.warn(msg)
+
+
 def rename_check(self):
 '''Checks for and renames the installed db if needed
 '''
@@ -209,3 +270,45 @@ class Main(object):
 from layman.config_modules.reposconf.reposconf import ConfigHandler
 repos_conf = ConfigHandler(self.config, overlays)
 repos_conf.write()
+
+def set_db_type(self, migrate_type, installed):
+if sys.hexversion = 0x30200f0:
+import configparser as ConfigParser
+else:
+import ConfigParser
+
+config = ConfigParser.ConfigParser()
+config_path = self.config['config']\
+  % {'configdir': self.config['configdir']}
+new_conf = os.path.dirname(config_path) + '/' + '._cfg_' +\
+   os.path.basename(config_path)
+
+try:
+shutil.copy(config_path, new_conf)
+except IOError as err:
+msg = '  

[gentoo-commits] proj/layman:master commit in: layman/

2015-07-15 Thread Devan Franchini
commit: 57848c6abf1a43a9df8efcefc4cbe2297d4ecac4
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Wed Jul 15 15:54:28 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Wed Jul 15 15:54:28 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=57848c6a

dbbase.py: Optimizes if check for db_type

 layman/dbbase.py | 13 +
 1 file changed, 9 insertions(+), 4 deletions(-)

diff --git a/layman/dbbase.py b/layman/dbbase.py
index 0bdd4e9..283d65c 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -179,10 +179,10 @@ class DbBase(object):
 '''
 Read the overlay database for installed overlay definitions.
 '''
+db_type = self.db_type
+
 if text and text_type:
 db_type = text_type
-else:
-db_type = self.db_type
 
 #Added to keep xml functionality for cached overlay XML definitions
 if 'cache' in path and '.xml' in path:
@@ -197,11 +197,16 @@ class DbBase(object):
 db_ctl.read_db(path, text=text)
 
 
-def write(self, path):
+def write(self, path, migrate_type=None):
 '''
 Write the list of overlays to a file.
 '''
-db_ctl = self.mod_ctl.get_class(self.db_type)(self.config,
+db_type = self.db_type
+
+if migrate_type:
+db_type = migrate_type
+
+db_ctl = self.mod_ctl.get_class(db_type)(self.config,
  self.overlays,
  self.paths,
  self.ignore,



[gentoo-commits] proj/layman:master commit in: layman/

2015-07-15 Thread Devan Franchini
commit: 1a95bc82b26678e8dc22560949756f6580169855
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Wed Jul 15 16:15:29 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Wed Jul 15 16:15:32 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=1a95bc82

version.py: Changes version to 2.4.0-git

As the next release will include some noticeable changes an increment
of the second version number in layman was necessary.

 layman/version.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/version.py b/layman/version.py
index ee73005..e6d19ff 100644
--- a/layman/version.py
+++ b/layman/version.py
@@ -24,7 +24,7 @@ from __future__ import unicode_literals
 __version__ = $Id: version.py 309 2007-04-09 16:23:38Z wrobel $
 
 
-VERSION = '2.3.1-git'
+VERSION = '2.4.0-git'
 
 if __name__ == '__main__':
 print(VERSION)



[gentoo-commits] proj/layman:master commit in: layman/tests/

2015-07-14 Thread Devan Franchini
commit: 7428f47c435073a929f9a41f72a6bd8a675b631e
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Tue Jul 14 13:30:16 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Tue Jul 14 13:30:37 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=7428f47c

external.py: Adds db_type config option to tests which need it

The Overlay, DbBase, and DB would require the db_type config option
to be set. To prevent it from falling back on config option defaults
it's best to specify it.

 layman/tests/external.py | 10 ++
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/layman/tests/external.py b/layman/tests/external.py
index 0dad278..3e41bd1 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -154,6 +154,7 @@ class AddDeleteDB(unittest.TestCase):
 
 my_opts = {'installed' : temp_xml_path,
'conf_type' : ['make.conf', 'repos.conf'],
+   'db_type'   : 'xml_db',
'nocheck'   : 'yes',
'make_conf' : make_conf,
'repos_conf': repo_conf,
@@ -480,6 +481,7 @@ class FormatBranchCategory(unittest.TestCase):
 def _run(self, number):
 #config = {'output': Message()}
 config = BareConfig()
+
 # Discuss renaming files to branch-%d.xml
 filename1 = os.path.join(HERE, 'testfiles',
 'subpath-%d.xml' % number)
@@ -554,7 +556,7 @@ class OverlayObjTest(unittest.TestCase):
 overlays = document.findall('overlay') + document.findall('repo')
 output = Message()
 
-ovl_a = Overlay({'output': output}, overlays[0])
+ovl_a = Overlay({'output': output, 'db_type': 'xml_db'}, 
xml=overlays[0])
 self.assertEqual(ovl_a.name, 'wrobel')
 self.assertEqual(ovl_a.is_official(), True)
 url = ['https://overlays.gentoo.org/svn/dev/wrobel']
@@ -563,7 +565,7 @@ class OverlayObjTest(unittest.TestCase):
 self.assertEqual(ovl_a.descriptions, ['Test'])
 self.assertEqual(ovl_a.priority, 10)
 
-ovl_b = Overlay({'output': output}, overlays[1])
+ovl_b = Overlay({'output': output, 'db_type': 'xml_db'}, 
xml=overlays[1])
 self.assertEqual(ovl_b.is_official(), False)
 
 
@@ -572,7 +574,7 @@ class OverlayObjTest(unittest.TestCase):
 overlays = document.findall('overlay') + document.findall('repo')
 output = Message()
 
-ovl = Overlay({'output': output}, overlays[0])
+ovl = Overlay({'output': output, 'db_type': 'xml_db'}, xml=overlays[0])
 test_infostr = 'wrobel\n~~\nSource  : '\
'https://overlays.gentoo.org/svn/dev/wrobel\nContact '\
': nob...@gentoo.org\nType: Subversion; Priority: '\
@@ -586,7 +588,7 @@ class OverlayObjTest(unittest.TestCase):
 overlays = document.findall('overlay') + document.findall('repo')
 output = Message()
 
-ovl = Overlay({'output': output}, overlays[0])
+ovl = Overlay({'output': output, 'db_type': 'xml_db'}, xml=overlays[0])
 test_short_list = 'wrobel[Subversion] '\
   '(https://o.g.o/svn/dev/wrobel )'
 self.assertEqual(ovl.short_list(80).decode('utf-8'), test_short_list)



[gentoo-commits] proj/layman:master commit in: layman/tests/

2015-07-14 Thread Devan Franchini
commit: c8783443cc42d4254d4b2a71796202495487fe0f
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Tue Jul 14 13:32:33 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Tue Jul 14 13:32:33 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=c8783443

external.py: Modifies ovl_dict keys to conform to new changes

 layman/tests/external.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/layman/tests/external.py b/layman/tests/external.py
index 3e41bd1..01cf5b3 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -522,11 +522,11 @@ class MakeOverlayXML(unittest.TestCase):
 
 ovl_dict = {
 'name': 'wrobel',
-'descriptions': ['Test'],
+'description': ['Test'],
 'owner_name': 'nobody',
 'owner_email': 'nob...@gentoo.org',
 'status': 'official',
-'sources': [['https://overlays.gentoo.org/svn/dev/wrobel',
+'source': [['https://overlays.gentoo.org/svn/dev/wrobel',
  'svn', '']],
 'priority': '10',
}



[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-07-14 Thread Devan Franchini
commit: cf8329cb7218173bba6cc57ed8f43e54e8ec9775
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Tue Jul 14 15:15:54 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Tue Jul 14 15:15:54 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=cf8329cb

overlay.py: Adds better error handling for missing source entries

 layman/overlays/overlay.py | 14 ++
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 6e289b6..c6a0cee 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -160,10 +160,13 @@ class Overlay(object):
 msg = 'Overlay from_dict(), name entry missing from dictionary!'
 raise Exception(msg)
 
-_sources = overlay['source']
+if 'source' in overlay:
+_sources = overlay['source']
+else:
+_sources = None
 
 if _sources == None:
-msg = 'Overlay from_dict(), %(name)s is missing a source'\
+msg = 'Overlay from_dict(), %(name)s is missing a source '\
   'entry!' % {'name': self.name}
 raise Exception(msg)
 
@@ -267,10 +270,13 @@ class Overlay(object):
 msg = 'Overlay from_json(), name entry missing from json!'
 raise Exception(msg)
 
-_sources = json['source']
+if 'source' in json:
+_sources = json['source']
+else:
+_sources = None
 
 if _sources == None:
-msg = 'Overlay from_json(), %(name)s is missing a source'\
+msg = 'Overlay from_json(), %(name)s is missing a source '\
   'entry!' % {'name': self.name}
 raise Exception(msg)
 



[gentoo-commits] proj/layman:master commit in: layman/db_modules/xml_db/

2015-07-13 Thread Devan Franchini
commit: 4c08c57f337abba1f6f4fe678bfa2a0cab569b7a
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 13 13:33:00 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 13 13:33:02 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=4c08c57f

xml_db.py: Removes unnecessary __eq__ and __ne__ functions

These functions are in the DbBase class and will continue to be used
in that class. As such there's no need for any DBHandler class to
include them in their code.

 layman/db_modules/xml_db/xml_db.py | 11 ---
 1 file changed, 11 deletions(-)

diff --git a/layman/db_modules/xml_db/xml_db.py 
b/layman/db_modules/xml_db/xml_db.py
index 6348162..38a19d2 100644
--- a/layman/db_modules/xml_db/xml_db.py
+++ b/layman/db_modules/xml_db/xml_db.py
@@ -86,17 +86,6 @@ class DBHandler(object):
 self.output.debug('Initializing XML overlay list handler', 8)
 
 
-def __eq__(self, other):
-for key in set(self.overlays.keys()) | set(other.overlays.keys()):
-if self.overlays[key] != other.overlays[key]:
-return False
-return True
-
-
-def __ne__(self, other):
-return not self.__eq__(other)
-
-
 def _broken_catalog_hint(self):
 this_function_name = sys._getframe().f_code.co_name
 



[gentoo-commits] proj/layman:master commit in: layman/

2015-07-13 Thread Devan Franchini
commit: a3ef79ecdc93c82a599cab3eef1be49d7ca40a9d
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 13 13:25:36 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 13 13:25:39 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=a3ef79ec

Adds switch on read_db if text is provided

Logically speaking, if the database document text is provided then
it will likely not be universal to every database provided. Therefore
adding another parameter that specifies the type of text that is being
provided will help distinguish which database type it is.

 layman/dbbase.py   | 11 ---
 layman/remotedb.py |  2 +-
 2 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/layman/dbbase.py b/layman/dbbase.py
index 56ef158..09133c2 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -167,12 +167,17 @@ class DbBase(object):
 return
 
 
-def read_db(self, path, text=None):
+def read_db(self, path, text=None, text_type=None):
 '''
 Read the overlay database for installed overlay definitions.
 '''
-for types in self.db_types:
-db_ctl = self.mod_ctl.get_class(types)(self.config,
+if text and text_type:
+types = [text_type]
+else:
+types = self.db_types
+
+for t in types:
+db_ctl = self.mod_ctl.get_class(t)(self.config,
  self.overlays,
  self.paths,
  self.ignore,

diff --git a/layman/remotedb.py b/layman/remotedb.py
index cd6ece3..89caf7a 100644
--- a/layman/remotedb.py
+++ b/layman/remotedb.py
@@ -280,7 +280,7 @@ class RemoteDB(DbBase):
 def _check_download(self, olist, url):
 
 try:
-self.read_db(url, text=olist)
+self.read_db(url, text=olist, text_type=xml_db)
 except Exception as error:
 self.output.debug(RemoteDB._check_download(), url=%s \nolist:\n
 % url,2)



[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-07-13 Thread Devan Franchini
commit: 9128580881ba70dbd1bd08e4cdcd8731a46699cd
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 13 18:52:15 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 13 18:52:17 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=91285808

overlay.py: Modifies error message for missing name entry

If the Overlay object has no name then trying to use the name would
result in erroneous or illogical reporting.

 layman/overlays/overlay.py | 6 ++
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index de0a035..024989c 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -157,8 +157,7 @@ class Overlay(object):
 if _name != None:
 self.name = encode(_name)
 else:
-msg = 'Overlay from dict(), %(name)s is missing a name entry!'\
-  % {'name': self.name}
+msg = 'Overlay from_dict(), name entry missing from dictionary!'
 raise Exception(msg)
 
 _sources = overlay['source']
@@ -383,8 +382,7 @@ class Overlay(object):
 elif 'name' in xml.attrib:
 self.name = encode(xml.attrib['name'])
 else:
-msg = 'Overlay from_xml(), %(name)s is missing a name entry!'\
-  % {'name': self.name}
+msg = 'Overlay from_xml(), name entry missing from xml!'
 raise Exception(msg)
 
 _sources = xml.findall('source')



[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-07-13 Thread Devan Franchini
commit: 73aa4d1bc690dbef69c0c00dfc629209a3a8540e
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 13 19:00:41 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 13 19:00:41 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=73aa4d1b

overlay.py: Corrects else on line 316

 layman/overlays/overlay.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 024989c..cf99499 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -313,7 +313,7 @@ class Overlay(object):
   'entry!' % {'name': self.name}
 if not ignore:
 raise Exception(msg)
-else ignore == 1:
+elif ignore == 1:
 self.output.warn(msg, 4)
 
  if 'description' in overlay:



[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-07-13 Thread Devan Franchini
commit: 8279886d04bb1469753144c1d204fd1ae20f528f
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 13 19:05:30 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 13 19:05:30 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=8279886d

overlay.py: Fixes any other mistakes made in haste

 layman/overlays/overlay.py | 7 +--
 1 file changed, 5 insertions(+), 2 deletions(-)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index cf99499..82e2f9f 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -316,7 +316,7 @@ class Overlay(object):
 elif ignore == 1:
 self.output.warn(msg, 4)
 
- if 'description' in overlay:
+if 'description' in overlay:
 self.descriptions = []
 _descs = overlay['description']
 for d in _descs:
@@ -602,7 +602,10 @@ class Overlay(object):
 
 def source_types(self):
 for i in self.sources:
-yield i.typedef is_official(self):
+yield i.type
+
+
+def is_official(self):
 '''
 Is the overlay official?
 '''



[gentoo-commits] proj/layman:master commit in: layman/db_modules/json_db/

2015-07-13 Thread Devan Franchini
commit: a072bcba3fd58d5d860d855061e593e429d15d30
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 13 18:45:58 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 13 18:45:58 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=a072bcba

json_db.py: Adds JSON databasing support to layman

 layman/db_modules/json_db/__init__.py |  24 +++
 layman/db_modules/json_db/json_db.py  | 120 ++
 2 files changed, 144 insertions(+)

diff --git a/layman/db_modules/json_db/__init__.py 
b/layman/db_modules/json_db/__init__.py
new file mode 100644
index 000..e095f4f
--- /dev/null
+++ b/layman/db_modules/json_db/__init__.py
@@ -0,0 +1,24 @@
+# Copyright 2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+'''
+JSON database plug-in module for layman.
+'''
+
+module_spec = {
+'name': 'json_db',
+'description': __doc__,
+'provides':{
+'json-module': {
+'name': 'json_db',
+'class': 'DBHandler',
+'description': __doc__,
+'functions': ['add_new', 'read_db', 'write'],
+'func_desc': {
+'add_new': 'Adds overlay from provided document text',
+'read_db': 'Reads the list of overlays from database file',
+'write': 'Writes the list of overlays to database file',
+},
+}
+}
+}

diff --git a/layman/db_modules/json_db/json_db.py 
b/layman/db_modules/json_db/json_db.py
new file mode 100644
index 000..47413c6
--- /dev/null
+++ b/layman/db_modules/json_db/json_db.py
@@ -0,0 +1,120 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# LAYMAN JSON DB
+#
+# File:   json_db.py
+#
+# Access JSON overlay database(s).
+#
+# Copyright:
+# (c) 2015Devan Franchini
+# Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+# Devan Franchini twitch...@gentoo.org
+#
+'''Handler for json overlay databases.'''
+
+from __future__ import unicode_literals
+
+__version__ = $Id: json.py 273 2015-07-10 10:10:49Z twitch153 $
+
+#===
+#
+# Dependencies
+#
+#---
+
+import json
+import sys
+
+from   layman.compatibility  import fileopen
+from   layman.overlays.overlay   import Overlay
+
+
+#py3.2+
+if sys.hexversion = 0x30200f0:
+_UNICODE = 'unicode'
+else:
+_UNICODE = 'UTF-8'
+
+
+
+#===
+#
+# Class DBHandler
+#
+#---
+
+class DBHandler(object):
+'''
+Handle a json overlay database.
+'''
+
+def __init__(self, config, overlays, paths=None, ignore=0,
+ ignore_init_read_errors=False):
+
+self.config = config
+self.ignore = ignore
+self.overlays = overlays
+self.paths = paths
+self.output = config['output']
+self.ignore_init_read_errors = ignore_init_read_errors
+
+self.output.debug('Initializing JSON overlay list handler', 8)
+
+
+def read_db(self, path, text=None):
+'''
+Read the overlay definition file.
+'''
+document = text
+
+if not document:
+try:
+with fileopen(path, 'r') as df:
+document = df.read()
+except Exception as error:
+if not self.ignore_init_read_errors:
+msg = 'JSON DBHandler - Failed to read the overlay list 
at'\
+  '(%(path)s)' % {'path': path}
+self.output.error(msg)
+raise error
+
+self.add_new(document, origin=path)
+
+
+def add_new(self, document=None, origin=None):
+'''
+Reads in provided json text and generates overlays to populate 
database.
+'''
+if not document:
+msg = 'JSON DBHandler - add_new() failed: JSON text cannot be 
none'\
+  '.\nOrigin: %(path)s' % {'path': origin}
+self.output.warn(msg)
+return False
+
+load = json.loads(document)['repo']
+
+for ovl in load:
+overlay = Overlay(self.config, json=ovl, ignore=self.ignore)
+self.overlays[overlay.name] = overlay
+
+return True
+
+
+def write(self, path):
+'''
+Write the list of overlays to a file.
+'''
+try:
+repo = {'@encoding': 'unicode', '@version': '1.0', 'repo': []}
+repo['repo'] = [self.overlays[key].to_json() for key in 

[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-07-13 Thread Devan Franchini
commit: e4162f49357e04722e8db20493e15538e657c3bd
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 13 18:36:51 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 13 18:36:54 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=e4162f49

overlay.py: Adds json support for overlay definitions

Also reorganizes functions alphabetically.

 layman/overlays/overlay.py | 658 +++--
 1 file changed, 403 insertions(+), 255 deletions(-)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 423b91e..de0a035 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -56,7 +56,7 @@ WHITESPACE_REGEX = re.compile('\s+')
 class Overlay(object):
 ''' Derive the real implementations from this.'''
 
-def __init__(self, config, xml=None, ovl_dict=None,
+def __init__(self, config, json=None, ovl_dict=None, xml=None,
 ignore = 0):
 self.config = config
 self.output = config['output']
@@ -69,6 +69,59 @@ class Overlay(object):
 self.from_xml(xml, ignore)
 elif ovl_dict is not None:
 self.from_dict(ovl_dict, ignore)
+elif json is not None:
+self.from_json(ovl_dict, ignore)
+
+
+def __eq__(self, other):
+for i in ('descriptions', 'homepage', 'name', 'owner_email',
+'owner_name', 'priority', 'status'):
+if getattr(self, i) != getattr(other, i):
+return False
+for i in self.sources + other.sources:
+if not i in self.sources:
+return False
+if not i in other.sources:
+return False
+return True
+
+
+def __ne__(self, other):
+return not self.__eq__(other)
+
+
+def add(self, base):
+res = 1
+first_s = True
+
+self.sources = self.filter_protocols(self.sources)
+if not self.sources:
+msg = 'Overlay.add() error: overlay %(name)s does not support '\
+  ' the given\nprotocol(s) %(protocol)s and cannot be '\
+  'installed.'\
+  % {'name': self.name,
+ 'protocol': str(self.config['protocol_filter'])}
+self.output.error(msg)
+return 1
+
+for s in self.sources:
+if not first_s:
+self.output.info('\nTrying next source of listed sources...', 
4)
+try:
+res = s.add(base)
+if res == 0:
+# Worked, throw other sources away
+self.sources = [s]
+break
+except Exception as error:
+self.output.warn(str(error), 4)
+first_s = False
+return res
+
+
+def delete(self, base):
+assert len(self.sources) == 1
+return self.sources[0].delete(base)
 
 
 def filter_protocols(self, sources):
@@ -93,6 +146,226 @@ class Overlay(object):
 return _sources
 
 
+def from_dict(self, overlay, ignore):
+'''
+Process an overlay dictionary definition
+'''
+msg = 'Overlay from_dict(); overlay %(ovl)s' % {'ovl': str(overlay)}
+self.output.debug(msg, 6)
+
+_name = overlay['name']
+if _name != None:
+self.name = encode(_name)
+else:
+msg = 'Overlay from dict(), %(name)s is missing a name entry!'\
+  % {'name': self.name}
+raise Exception(msg)
+
+_sources = overlay['source']
+
+if _sources == None:
+msg = 'Overlay from_dict(), %(name)s is missing a source'\
+  'entry!' % {'name': self.name}
+raise Exception(msg)
+
+def create_dict_overlay_source(source_):
+_src, _type, _sub = source_
+self.ovl_type = _type
+try:
+_class = self.module_controller.get_class(_type)
+except InvalidModuleName:
+_class = self.module_controller.get_class('stub')
+
+_location = encode(_src)
+if _sub:
+self.branch = encode(_sub)
+else:
+self.branch = None
+
+return _class(parent=self, config=self.config,
+_location=_location, ignore=ignore)
+
+self.sources = [create_dict_overlay_source(e) for e in _sources]
+
+if 'owner_name' in overlay:
+_owner = overlay['owner_name']
+self.owner_name = encode(_owner)
+else:
+self.owner_name = None
+
+if 'owner_email' in overlay:
+_email = overlay['owner_email']
+self.owner_email = encode(_email)
+else:
+self.owner_email = None
+msg = 'Overlay from_dict(), %(name)s is missing an 
owner.email'\
+  ' entry!' % {'name': self.name}
+if not 

[gentoo-commits] proj/layman:master commit in: layman/db_modules/json_db/

2015-07-13 Thread Devan Franchini
commit: 547b6f70d35c00f1e6387ebdbdb4eead46b5af41
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 13 18:49:04 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 13 18:49:04 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=547b6f70

json_db/__init__.py: Modifies function descriptions

 layman/db_modules/json_db/__init__.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/layman/db_modules/json_db/__init__.py 
b/layman/db_modules/json_db/__init__.py
index e095f4f..1502b9d 100644
--- a/layman/db_modules/json_db/__init__.py
+++ b/layman/db_modules/json_db/__init__.py
@@ -15,9 +15,9 @@ module_spec = {
 'description': __doc__,
 'functions': ['add_new', 'read_db', 'write'],
 'func_desc': {
-'add_new': 'Adds overlay from provided document text',
+'add_new': 'Adds overlay(s) from provided database text',
 'read_db': 'Reads the list of overlays from database file',
-'write': 'Writes the list of overlays to database file',
+'write'  : 'Writes the list of overlays to database file',
 },
 }
 }



[gentoo-commits] proj/layman:master commit in: layman/db_modules/xml_db/

2015-07-13 Thread Devan Franchini
commit: 0bd7450c52401be9b0c9c9ad8fb2e9eff5760e1b
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 13 18:48:41 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 13 18:48:41 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=0bd7450c

xml_db/__init__.py: Modifies function descriptions

 layman/db_modules/xml_db/__init__.py | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/layman/db_modules/xml_db/__init__.py 
b/layman/db_modules/xml_db/__init__.py
index ad6506c..3a3abd1 100644
--- a/layman/db_modules/xml_db/__init__.py
+++ b/layman/db_modules/xml_db/__init__.py
@@ -15,9 +15,9 @@ module_spec = {
 'description': __doc__,
 'functions': ['add_new', 'read_db', 'write'],
 'func_desc': {
-'add_new': 'Adds new overlay(s) to database',
-'read_db': 'Reads the list of registered overlays from config',
-'write'  : 'Writes the list of registered overlay to config',
+'add_new': 'Adds overlay(s) from provided database text',
+'read_db': 'Reads the list of overlays from database file',
+'write'  : 'Writes the list of overlays to database file',
 },
 }
 }



[gentoo-commits] proj/layman:master commit in: layman/, layman/overlays/

2015-07-13 Thread Devan Franchini
commit: f45dd7b5e95203540267dccd758f0bc8a69082c3
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 13 16:48:07 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 13 16:48:10 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=f45dd7b5

Code clean-up

overlay.py: Modifies what from_dict() expects in the overlay dictionary
constants.py: Modifies POSSIBLE_COMPONENTS and REQUIRED_COMPONENTS to
reflect change in overlay.py
maker.py: Modifies components that form the overlay dict to follow in
suit of what from_dict() expects.

These changes have been made primarily for uniformity with the
from_xml() function.

 layman/constants.py|  6 +++---
 layman/maker.py| 46 +++---
 layman/overlays/overlay.py | 11 +--
 3 files changed, 31 insertions(+), 32 deletions(-)

diff --git a/layman/constants.py b/layman/constants.py
index 787b610..a39071f 100644
--- a/layman/constants.py
+++ b/layman/constants.py
@@ -63,9 +63,9 @@ SUCCEED = 0
 ##
 
#
 
-COMPONENT_DEFAULTS  = ['name', 'descriptions', 'owner', 'type', 'sources']
-POSSIBLE_COMPONENTS = ['name', 'descriptions', 'homepage', 'owner', 'quality',
-   'priority', 'sources', 'branch', 'irc', 'feeds']
+COMPONENT_DEFAULTS  = ['name', 'description', 'owner', 'type', 'source']
+POSSIBLE_COMPONENTS = ['name', 'description', 'homepage', 'owner', 'quality',
+   'priority', 'source', 'branch', 'irc', 'feed']
 
 ###
 ##

diff --git a/layman/maker.py b/layman/maker.py
index e896530..caf5655 100644
--- a/layman/maker.py
+++ b/layman/maker.py
@@ -42,17 +42,17 @@ else:
 _UNICODE = 'UTF-8'
 
 AUTOCOMPLETE_TEMPLATE = {
-'bitbucket': {'feeds': (
+'bitbucket': {'feed': (
 'http://bitbucket.org/%(tail)s/atom',
 'http://bitbucket.org/%(tail)s/rss'
),
   'homepage': 'https://bitbucket.org/%(tail)s',
-  'sources': (
+  'source': (
  ('https://bitbucket.org/%(tail)s', 'mercurial', '%(branch)s'),
  ('ssh://h...@bitbucket.org/%(tail)s', 'mercurial', 
'%(branch)s')
  )
  },
-'gentoo': {'feeds': (
+'gentoo': {'feed': (
  'https://git.overlays.gentoo.org/gitweb/'\
  '?p=%(tail)s;a=atom',
  'https://git.overlays.gentoo.org/gitweb/'\
@@ -60,13 +60,13 @@ AUTOCOMPLETE_TEMPLATE = {
 ),
'homepage': 'https://git.overlays.gentoo.org/gitweb/'\
'?p=%(tail)s;a=summary',
-   'sources': (
+   'source': (
   ('https://git.overlays.gentoo.org/gitroot/%(tail)s', 'git', ''),
   ('git://git.overlays.gentoo.org/%(tail)s', 'git', ''),
   ('git+ssh://g...@git.overlays.gentoo.org/%(tail)s', 'git', '')
   )
   },
-'gentoo-branch': {'feeds': (
+'gentoo-branch': {'feed': (
 'https://git.overlays.gentoo.org/gitweb/?p='\
 '%(tail)s;a=atom;h=refs/heads/%(branch)s',
 'https://git.overlays.gentoo.org/gitweb/?p='\
@@ -75,7 +75,7 @@ AUTOCOMPLETE_TEMPLATE = {
   'homepage': 'https://git.overlays.gentoo.org/gitweb/?p='\
   '%(tail)s;a=shortlog;h=refs/heads/'\
   '%(branch)s',
-  'sources': (
+  'source': (
  ('https://git.overlays.gentoo.org/gitroot/%(tail)s', 
'git',
   '%(branch)s'),
  ('git://git.overlays.gentoo.org/%(tail)s', 'git',
@@ -84,19 +84,19 @@ AUTOCOMPLETE_TEMPLATE = {
   '%(branch)s')
  )
  },
-'github': {'feeds': ('https://github.com/%(info)s/commits/master.atom',),
+'github': {'feed': ('https://github.com/%(info)s/commits/master.atom',),
'homepage': 'https://github.com/%(info)s',
-   'sources': (
+   'source': (
   ('https://github.com/%(tail)s', 'git', ''),
   ('git://github.com/%(tail)s', 'git', ''),
   ('g...@github.com:%(tail)s', 'git', ''),
   ('https://github.com/%(tail)s', 'svn', '')
   )
   },
-'github-branch': {'feeds': ('https://github.com/%(info)s/commits/'\
+'github-branch': {'feed': ('https://github.com/%(info)s/commits/'\
'%(branch)s.atom'),
  'homepage': 'https://github.com/%(info)s/tree/%(branch)s',
-

[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-07-13 Thread Devan Franchini
commit: 9a56f1ac6a40446ea8cc210a25621e9ad1ccbe80
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 13 22:46:34 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 13 22:46:34 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=9a56f1ac

overlay.py: Renames overlay variable to json to match parameter

 layman/overlays/overlay.py | 56 +++---
 1 file changed, 28 insertions(+), 28 deletions(-)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 82e2f9f..6e289b6 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -70,7 +70,7 @@ class Overlay(object):
 elif ovl_dict is not None:
 self.from_dict(ovl_dict, ignore)
 elif json is not None:
-self.from_json(ovl_dict, ignore)
+self.from_json(json, ignore)
 
 
 def __eq__(self, other):
@@ -257,17 +257,17 @@ class Overlay(object):
 '''
 Process a json overlay definition
 '''
-msg = 'Overlay from_json(); overlay %(ovl)s' % {'ovl': str(overlay)}
+msg = 'Overlay from_json(); overlay %(ovl)s' % {'ovl': str(json)}
 self.output.debug(msg, 6)
 
-_name = overlay['name']
+_name = json['name']
 if _name != None:
 self.name = encode(_name)
 else:
 msg = 'Overlay from_json(), name entry missing from json!'
 raise Exception(msg)
 
-_sources = overlay['source']
+_sources = json['source']
 
 if _sources == None:
 msg = 'Overlay from_json(), %(name)s is missing a source'\
@@ -300,13 +300,13 @@ class Overlay(object):
 
 self.sources = [create_json_overlay_source(e) for e in _sources]
 
-if 'name' in overlay['owner']:
-self.owner_name = encode(overlay['owner']['name'])
+if 'name' in json['owner']:
+self.owner_name = encode(json['owner']['name'])
 else:
 self.owner_name = None
 
-if 'email' in overlay['owner']:
-self.owner_email = encode(overlay['owner']['email'])
+if 'email' in json['owner']:
+self.owner_email = encode(json['owner']['email'])
 else:
 self.owner_email = None
 msg = 'Overlay from_json(), %(name)s is missing an 
owner.email'\
@@ -316,49 +316,49 @@ class Overlay(object):
 elif ignore == 1:
 self.output.warn(msg, 4)
 
-if 'description' in overlay:
+if 'description' in json:
 self.descriptions = []
-_descs = overlay['description']
+_descs = json['description']
 for d in _descs:
-d = WHITESPACE_REGEX.sub(' ', d['#text'])
+d = WHITESPACE_REGEX.sub(' ', d)
 self.descriptions.append(encode(d))
 else:
 self.descriptions = ['']
+msg = 'Overlay from_json() %(name)s is missing description'\
+  'entry!' % {'name': self.name}
 if not ignore:
-raise Exception('Overlay from_json(), ' + self.name +
-' is missing a description entry!')
+raise Exception(msg)
 elif ignore == 1:
-self.output.warn('Overlay from_json(), ' + self.name +
-' is missing a description entry!', 4)
+self.output.warn(msg, 4)
 
-if '@status' in overlay:
-self.status = encode(overlay['@status'])
+if '@status' in json:
+self.status = encode(json['@status'])
 else:
 self.status = None
 
 self.quality = 'experimental'
-if '@quality' in overlay:
-if overlay['@quality'] in set(QUALITY_LEVELS):
-self.quality = encode(overlay['@quality'])
+if '@quality' in json:
+if json['@quality'] in set(QUALITY_LEVELS):
+self.quality = encode(json['@quality'])
 
-if '@priority' in overlay:
-self.priority = int(overlay['@priority'])
+if '@priority' in json:
+self.priority = int(json['@priority'])
 else:
 self.priority = 50
 
-if 'homepage' in overlay:
-self.homepage = encode(overlay['homepage'])
+if 'homepage' in json:
+self.homepage = encode(json['homepage'])
 else:
 self.homepage = None
 
-if 'feed' in overlay:
+if 'feed' in json:
 self.feeds = [encode(e) \
-for e in overlay['feed']]
+for e in json['feed']]
 else:
 self.feeds = None
 
-if 'irc' in overlay:
-self.irc = encode(overlay['irc'])
+if 'irc' in json:
+self.irc = encode(json['irc'])
 else:
 self.irc = None
 



[gentoo-commits] proj/layman:master commit in: layman/

2015-07-13 Thread Devan Franchini
commit: d4a11440154449a27357dc2b670803220e7c2f06
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Jul 13 23:05:39 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Jul 13 23:05:39 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=d4a11440

dbbase.py: Adds limitation to use only one db type

 layman/dbbase.py | 48 +---
 1 file changed, 29 insertions(+), 19 deletions(-)

diff --git a/layman/dbbase.py b/layman/dbbase.py
index 09133c2..0bdd4e9 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -82,7 +82,7 @@ class DbBase(object):
ignore_init_read_errors=False, allow_missing=False):
 
 self.config = config
-self.db_types = config['db_type']
+self.db_type = config['db_type']
 self.ignore = ignore
 self.ignore_init_read_errors = ignore_init_read_errors
 self.mod_ctl = Modules(path=MOD_PATH,
@@ -96,8 +96,16 @@ class DbBase(object):
 
 self.output.debug('Initializing overlay list handler', 8)
 
-if isinstance(self.db_types, STR):
-self.db_types = [x.strip() for x in self.db_types.split(',')]
+if isinstance(self.db_type, STR):
+self.db_type = [x.strip() for x in self.db_type.split(',')]
+
+if len(self.db_type)  1:
+msg = 'DbBase; warning, multiple instances of db_type found:'\
+  ' %(db_types)s.\nDefaulting to: %(db_type)s'\
+  % {'db_types': self.db_type, 'db_type': self.db_type[0]}
+self.output.warn(msg)
+
+self.db_type = self.db_type[0]
 
 for path in self.paths:
 if not os.path.exists(path):
@@ -172,32 +180,34 @@ class DbBase(object):
 Read the overlay database for installed overlay definitions.
 '''
 if text and text_type:
-types = [text_type]
+db_type = text_type
 else:
-types = self.db_types
+db_type = self.db_type
+
+#Added to keep xml functionality for cached overlay XML definitions
+if 'cache' in path and '.xml' in path:
+db_type = 'xml_db'
 
-for t in types:
-db_ctl = self.mod_ctl.get_class(t)(self.config,
- self.overlays,
- self.paths,
- self.ignore,
- self.ignore_init_read_errors)
+db_ctl = self.mod_ctl.get_class(db_type)(self.config,
+ self.overlays,
+ self.paths,
+ self.ignore,
+ self.ignore_init_read_errors)
 
-db_ctl.read_db(path, text=text)
+db_ctl.read_db(path, text=text)
 
 
 def write(self, path):
 '''
 Write the list of overlays to a file.
 '''
-for types in self.db_types:
-db_ctl = self.mod_ctl.get_class(types)(self.config,
- self.overlays,
- self.paths,
- self.ignore,
- self.ignore_init_read_errors)
+db_ctl = self.mod_ctl.get_class(self.db_type)(self.config,
+ self.overlays,
+ self.paths,
+ self.ignore,
+ self.ignore_init_read_errors)
 
-db_ctl.write(path)
+db_ctl.write(path)
 
 
 def select(self, overlay):



[gentoo-commits] proj/layman:master commit in: layman/db_modules/xml_db/, etc/, layman/db_modules/xml/, layman/tests/, layman/

2015-07-10 Thread Devan Franchini
commit: b32d76e2e155d2298555c9a2941517bc007ea55b
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Jul 10 13:46:49 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Jul 10 13:46:53 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=b32d76e2

Renames db module xml to xml_db

This prevents namespace collisions with the required xml class.

 etc/layman.cfg |  2 +-
 layman/config.py   |  2 +-
 layman/db_modules/{xml = xml_db}/__init__.py  |  4 ++--
 layman/db_modules/{xml/xml.py = xml_db/xml_db.py} |  4 ++--
 layman/tests/external.py   | 10 +-
 5 files changed, 11 insertions(+), 11 deletions(-)

diff --git a/etc/layman.cfg b/etc/layman.cfg
index 76f5f46..45fe3fc 100644
--- a/etc/layman.cfg
+++ b/etc/layman.cfg
@@ -69,7 +69,7 @@ conf_type : repos.conf
 #---
 # Database types used by layman
 # For now, only xml.
-#db_type : xml
+#db_type : xml_db
 
 #---
 

diff --git a/layman/config.py b/layman/config.py
index 853e22f..0ad975b 100644
--- a/layman/config.py
+++ b/layman/config.py
@@ -100,7 +100,7 @@ class BareConfig(object):
 'auto_sync': 'No',
 'check_official': 'Yes',
 'conf_type': 'repos.conf',
-'db_type': 'xml',
+'db_type': 'xml_db',
 'require_repoconfig': 'Yes',
 'clean_archive': 'yes',
 'make_conf' : '%(storage)s/make.conf',

diff --git a/layman/db_modules/xml/__init__.py 
b/layman/db_modules/xml_db/__init__.py
similarity index 92%
rename from layman/db_modules/xml/__init__.py
rename to layman/db_modules/xml_db/__init__.py
index 96861d7..ad6506c 100644
--- a/layman/db_modules/xml/__init__.py
+++ b/layman/db_modules/xml_db/__init__.py
@@ -6,11 +6,11 @@ XML database plug-in module for layman.
 '''
 
 module_spec = {
-'name': 'xml',
+'name': 'xml_db',
 'description': __doc__,
 'provides':{
 'xml-module': {
-'name': 'xml',
+'name': 'xml_db',
 'class': 'DBHandler',
 'description': __doc__,
 'functions': ['add_new', 'read_db', 'write'],

diff --git a/layman/db_modules/xml/xml.py b/layman/db_modules/xml_db/xml_db.py
similarity index 98%
rename from layman/db_modules/xml/xml.py
rename to layman/db_modules/xml_db/xml_db.py
index c444fc3..6348162 100644
--- a/layman/db_modules/xml/xml.py
+++ b/layman/db_modules/xml_db/xml_db.py
@@ -3,7 +3,7 @@
 
#
 # LAYMAN XML DB
 
#
-# File:   xml.py
+# File:   xml_db.py
 #
 # Access XML overlay database(s).
 #
@@ -18,7 +18,7 @@
 
 from __future__ import unicode_literals
 
-__version__ = $Id: xml.py 273 2015-07-07 10:30:30Z twitch153 $
+__version__ = $Id: xml_db.py 273 2015-07-07 10:30:30Z twitch153 $
 
 
#===
 #

diff --git a/layman/tests/external.py b/layman/tests/external.py
index e2a44b0..0dad278 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -637,7 +637,7 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 output = Message()
 config = {
   'output': output,
-  'db_type': 'xml',
+  'db_type': 'xml_db',
   'svn_command': '/usr/bin/svn',
   'rsync_command':'/usr/bin/rsync'
  }
@@ -672,7 +672,7 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 def read_db(self):
 output = Message()
 config = {'output': output,
-  'db_type': 'xml',}
+  'db_type': 'xml_db',}
 db = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
 keys = sorted(db.overlays)
 self.assertEqual(keys, ['wrobel', 'wrobel-stable'])
@@ -684,7 +684,7 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 def select_db(self):
 output = Message()
 config = {'output': output,
-  'db_type': 'xml',}
+  'db_type': 'xml_db',}
 db = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
 url = ['rsync://gunnarwrobel.de/wrobel-stable']
 self.assertEqual(list(db.select('wrobel-stable').source_uris()), url)
@@ -696,12 +696,12 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 config = BareConfig()
 
 a = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
-b = DbBase({'output': Message(), 'db_type': 'xml'}, [test_xml,])
+b = DbBase({'output': Message(), 'db_type': 'xml_db'}, [test_xml,])
 
 b.overlays['wrobel-stable'] = a.overlays['wrobel-stable']
   

[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-07-10 Thread Devan Franchini
commit: d8b97485f50a4922476787ec1052a55e69ae22cb
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Jul 10 16:14:02 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Jul 10 16:14:08 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=d8b97485

overlay.py: Quick code cleanup

 layman/overlays/overlay.py | 113 -
 1 file changed, 70 insertions(+), 43 deletions(-)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 1ecd509..e4195cf 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -11,14 +11,16 @@
 # (c) 2005 - 2009 Gunnar Wrobel
 # (c) 2009Sebastian Pipping
 # (c) 2009Christian Groschupp
+# (c) 2015Devan Franchini
 # Distributed under the terms of the GNU General Public License v2
 #
 # Author(s):
 # Gunnar Wrobel wro...@gentoo.org
 # Sebastian Pipping sebast...@pipping.org
 # Christian Groschupp christ...@groschupp.org
+# Devan Franchini twitch...@gentoo.org
 #
-''' Basic overlay class.'''
+'''Basic overlay class.'''
 
 from __future__ import unicode_literals
 
@@ -92,8 +94,9 @@ class Overlay(object):
 
 
 def from_xml(self, xml, ignore):
-Process an xml overlay definition
-
+'''
+Process an xml overlay definition
+'''
 def strip_text(node):
 res = node.text
 if res is None:
@@ -101,15 +104,18 @@ class Overlay(object):
 return res.strip()
 
 _name = xml.find('name')
+
 if _name != None:
 self.name = encode(strip_text(_name))
 elif 'name' in xml.attrib:
 self.name = encode(xml.attrib['name'])
 else:
-raise Exception('Overlay from_xml(), ' + self.name + \
-'is missing a name entry!')
+msg = 'Overlay from_xml(), %(name)s is missing a name entry!'\
+  % {'name': self.name}
+raise Exception(msg)
 
 _sources = xml.findall('source')
+
 # new xml format
 if _sources != []:
 _sources = [e for e in _sources if 'type' in e.attrib]
@@ -124,6 +130,7 @@ class Overlay(object):
 _branch = ''
 _type = source_elem.attrib['type']
 self.ovl_type = _type
+
 if 'branch' in source_elem.attrib:
 _branch = source_elem.attrib['branch']
 
@@ -133,23 +140,25 @@ class Overlay(object):
 _class = self.module_controller.get_class('stub')
 
 _location = encode(strip_text(source_elem))
-
 self.branch = _branch
 
 return _class(parent=self, config=self.config,
 _location=_location, ignore=ignore)
 
 if not len(_sources):
-raise Exception('Overlay from_xml(), ' + self.name + \
-' is missing a source entry!')
+msg = 'Overlay from_xml(), %(name) is missing a source entry!'\
+  % {'name': self.name}
+raise Exception(msg)
 
 self.sources = [create_overlay_source(e) for e in _sources]
 
 _owner = xml.find('owner')
+
 if _owner == None:
 _email = None
 else:
 _email = _owner.find('email')
+
 if _owner != None and _email != None:
 self.owner_email = encode(strip_text(_email))
 _name = _owner.find('name')
@@ -163,12 +172,12 @@ class Overlay(object):
 else:
 self.owner_email = ''
 self.owner_name = None
+msg = 'Overlay from_xml(), %(name)s is mising an '\
+  'owner.email entry!' % {'name': self.name}
 if not ignore:
-raise Exception('Overlay  from_xml(), ' + self.name + \
-' is missing an owner.email entry!')
+raise Exception(msg)
 elif ignore == 1:
-self.output.warn('Overlay ' + self.name + ' is missing a '
- 'owner.email entry!', 4)
+self.output.warn(msg, 4)
 
 _desc = xml.findall('description')
 if _desc != None:
@@ -178,12 +187,12 @@ class Overlay(object):
 self.descriptions.append(encode(d))
 else:
 self.descriptions = ['']
+msg = 'Overlay from_xml(), %(name)s is missing a '\
+  'description entry!' % {'name': self.name}
 if not ignore:
-raise Exception('Overlay  from_xml(), ' + self.name + \
-' is missing a description entry!')
+raise Exception(msg)
 elif ignore == 1:
-self.output.warn('Overlay ' + self.name + ' is missing a '
- 'description entry!', 4)
+self.output.warn(msg, 4)
 
 if 'status' in 

[gentoo-commits] proj/layman:master commit in: layman/

2015-07-09 Thread Devan Franchini
commit: 17fa547f5653b60c67270b1b3fffbc82d20dd09b
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Thu Jul  9 16:17:13 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Thu Jul  9 16:17:13 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=17fa547f

dbbase.py: Adds use of db module plug-in system

Other changes include code clean up and the disabling of the add_new()
function. Currently the DbBase only supports the XML DBHandler but
more support will be added soon.

 layman/dbbase.py | 143 +++
 1 file changed, 59 insertions(+), 84 deletions(-)

diff --git a/layman/dbbase.py b/layman/dbbase.py
index 3e47384..b6c32bc 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -5,12 +5,13 @@
 
#
 # File:   dbbase.py
 #
-# Access to an xml list of overlays
+# Main handler of overlay database(s).
 #
 # Copyright:
 # (c) 2005 - 2009 Gunnar Wrobel
 # (c) 2009Sebastian Pipping
 # (c) 2009Christian Groschupp
+# (c) 2015Devan Franchini
 # Distributed under the terms of the GNU General Public License v2
 #
 # Author(s):
@@ -19,11 +20,11 @@
 # Christian Groschupp christ...@groschupp.org
 # Devan Franchini twitch...@gentoo.org
 #
-'''Main handler for overlays.'''
+'''Main handler for overlay database(s).'''
 
 from __future__ import unicode_literals
 
-__version__ = $Id: overlay.py 273 2006-12-30 15:54:50Z wrobel $
+__version__ = $Id: dbbase.py 273 2015-07-09 11:35:55Z twitch153 $
 
 
#===
 #
@@ -34,22 +35,22 @@ __version__ = $Id: overlay.py 273 2006-12-30 15:54:50Z 
wrobel $
 import os
 import os.path
 import sys
-import xml
-import xml.etree.ElementTree as ET # Python 2.5
 
-#from   layman.debug  import OUT
-from   layman.utils  import indent
-from   layman.compatibility  import fileopen
+from   layman.module import Modules
 from   layman.overlays.overlay   import Overlay
 
 
 #py3.2+
 if sys.hexversion = 0x30200f0:
 _UNICODE = 'unicode'
+STR = str
 else:
 _UNICODE = 'UTF-8'
+STR = basestring
 
 
+MOD_PATH = os.path.join(os.path.dirname(__file__), 'db_modules')
+
 
#===
 #
 # Class UnknownOverlayException
@@ -65,25 +66,6 @@ class UnknownOverlayException(Exception):
 def __str__(self):
 return UnknownOverlayMessage(self.repo_name)
 
-#===
-#
-# Class BrokenOverlayCatalog
-#
-#---
-
-class BrokenOverlayCatalog(ValueError):
-def __init__(self, origin, expat_error, hint=None):
-if hint == None:
-hint = ''
-else:
-hint = '\nHint: %s' % hint
-
-super(BrokenOverlayCatalog, self).__init__(
-'XML parsing failed for %(origin)s (line %(line)d, column'\
-'%(column)d)%(hint)s' % {'line': expat_error.lineno,
- 'column':expat_error.offset + 1,
- 'origin':origin, 'hint':hint})
-
 
 
#===
 #
@@ -96,29 +78,38 @@ class DbBase(object):
 Handle a list of overlays.
 '''
 
-def __init__(self, config, paths=None, ignore = 0,
-ignore_init_read_errors=False, allow_missing=False):
+def __init__(self, config, paths=None, ignore=0,
+   ignore_init_read_errors=False, allow_missing=False):
 
 self.config = config
+self.db_types = config['db_type']
 self.ignore = ignore
-self.paths = paths
+self.ignore_init_read_errors = ignore_init_read_errors
+self.mod_ctl = Modules(path=MOD_PATH,
+   namepath='layman.db_modules',
+   output=config['output'])
 self.output = config['output']
 self.overlays = {}
-self.ignore_init_read_errors = ignore_init_read_errors
+self.paths = paths
+
 path_found = False
 
 self.output.debug('Initializing overlay list handler', 8)
 
+if isinstance(self.db_types, STR):
+self.db_types = [x.strip() for x in self.db_types.split(',')]
+
 for path in self.paths:
 if not os.path.exists(path):
 continue
 
-self.read_file(path)
+self.read_db(path)
 path_found = True
 
 if not path_found and not allow_missing:
-msg = Warning: an installed db file was not found at: %(path)s
-self.output.warn(msg % {'path': 

[gentoo-commits] proj/layman:master commit in: layman/tests/

2015-07-09 Thread Devan Franchini
commit: 218a9cbf948a70d852d1fe0e22322003d2f0b6dd
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Thu Jul  9 17:20:20 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Thu Jul  9 17:20:20 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=218a9cbf

external.py: Adds db_type to configs for DbBase tests

 layman/tests/external.py | 12 
 1 file changed, 8 insertions(+), 4 deletions(-)

diff --git a/layman/tests/external.py b/layman/tests/external.py
index 97bd6ee..e2a44b0 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -637,6 +637,7 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 output = Message()
 config = {
   'output': output,
+  'db_type': 'xml',
   'svn_command': '/usr/bin/svn',
   'rsync_command':'/usr/bin/rsync'
  }
@@ -670,7 +671,8 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 
 def read_db(self):
 output = Message()
-config = {'output': output}
+config = {'output': output,
+  'db_type': 'xml',}
 db = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
 keys = sorted(db.overlays)
 self.assertEqual(keys, ['wrobel', 'wrobel-stable'])
@@ -681,7 +683,8 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 
 def select_db(self):
 output = Message()
-config = {'output': output}
+config = {'output': output,
+  'db_type': 'xml',}
 db = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
 url = ['rsync://gunnarwrobel.de/wrobel-stable']
 self.assertEqual(list(db.select('wrobel-stable').source_uris()), url)
@@ -691,13 +694,14 @@ class ReadWriteSelectListDbBase(unittest.TestCase):
 tmpdir = tempfile.mkdtemp(prefix='laymantmp_')
 test_xml = os.path.join(tmpdir, 'test.xml')
 config = BareConfig()
+
 a = DbBase(config, [HERE + '/testfiles/global-overlays.xml', ])
-b = DbBase({'output': Message()}, [test_xml,])
+b = DbBase({'output': Message(), 'db_type': 'xml'}, [test_xml,])
 
 b.overlays['wrobel-stable'] = a.overlays['wrobel-stable']
 b.write(test_xml)
 
-c = DbBase({'output': Message()}, [test_xml,])
+c = DbBase({'output': Message(), 'db_type': 'xml'}, [test_xml,])
 keys = sorted(c.overlays)
 self.assertEqual(keys, ['wrobel-stable'])
 



[gentoo-commits] proj/layman:master commit in: layman/

2015-07-09 Thread Devan Franchini
commit: 37a7107a3eaca6a91b48b4e588be247f43107c6f
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Thu Jul  9 17:24:09 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Thu Jul  9 17:24:09 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=37a7107a

api.py: Removes annoying lack of space in error message

 layman/api.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/api.py b/layman/api.py
index 5a02aab..0718dce 100755
--- a/layman/api.py
+++ b/layman/api.py
@@ -561,7 +561,7 @@ class LaymanAPI(object):
 % str(dbreload),8)
 except Exception as error:
 self.output.error('Failed to fetch overlay list!\n Original Error'
-  'was:\n%(err)s' % {'err': error})
+  ' was:\n%(err)s' % {'err': error})
 return False
 self.get_available(dbreload)
 return succeeded



[gentoo-commits] proj/layman:master commit in: layman/db_modules/, layman/db_modules/xml/

2015-07-09 Thread Devan Franchini
commit: 1dafdc7cdfc3254fa53c50c519d9f392fdfcb2cb
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Thu Jul  9 15:29:51 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Thu Jul  9 15:29:51 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=1dafdc7c

xml.py: Adds XML database handler module

 layman/db_modules/__init__.py |   0
 layman/db_modules/xml/__init__.py |  24 ++
 layman/db_modules/xml/xml.py  | 175 ++
 3 files changed, 199 insertions(+)

diff --git a/layman/db_modules/__init__.py b/layman/db_modules/__init__.py
new file mode 100644
index 000..e69de29

diff --git a/layman/db_modules/xml/__init__.py 
b/layman/db_modules/xml/__init__.py
new file mode 100644
index 000..96861d7
--- /dev/null
+++ b/layman/db_modules/xml/__init__.py
@@ -0,0 +1,24 @@
+# Copyright 2015 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+'''
+XML database plug-in module for layman.
+'''
+
+module_spec = {
+'name': 'xml',
+'description': __doc__,
+'provides':{
+'xml-module': {
+'name': 'xml',
+'class': 'DBHandler',
+'description': __doc__,
+'functions': ['add_new', 'read_db', 'write'],
+'func_desc': {
+'add_new': 'Adds new overlay(s) to database',
+'read_db': 'Reads the list of registered overlays from config',
+'write'  : 'Writes the list of registered overlay to config',
+},
+}
+}
+}

diff --git a/layman/db_modules/xml/xml.py b/layman/db_modules/xml/xml.py
new file mode 100644
index 000..189e868
--- /dev/null
+++ b/layman/db_modules/xml/xml.py
@@ -0,0 +1,175 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+#
+# LAYMAN XML DB
+#
+# File:   xml.py
+#
+# Access XML overlay database(s).
+#
+# Copyright:
+# (c) 2015Devan Franchini
+# Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+# Devan Franchini twitch...@gentoo.org
+#
+'''Handler for xml overlay databases.'''
+
+from __future__ import unicode_literals
+
+__version__ = $Id: xml.py 273 2015-07-07 10:30:30Z twitch153 $
+
+#===
+#
+# Dependencies
+#
+#---
+
+import sys
+import xml
+import xml.etree.ElementTree as ET # Python 2.5
+
+from   layman.utils  import indent
+from   layman.compatibility  import fileopen
+from   layman.overlays.overlay   import Overlay
+
+
+#py3.2+
+if sys.hexversion = 0x30200f0:
+_UNICODE = 'unicode'
+else:
+_UNICODE = 'UTF-8'
+
+
+#===
+#
+# Class BrokenOverlayCatalog
+#
+#---
+
+class BrokenOverlayCatalog(ValueError):
+def __init__(self, origin, expat_error, hint=None):
+if hint == None:
+hint = ''
+else:
+hint = '\nHint: %s' % hint
+
+super(BrokenOverlayCatalog, self).__init__(
+'XML parsing failed for %(origin)s (line %(line)d, column'\
+'%(column)d)%(hint)s' % {'line': expat_error.lineno,
+ 'column':expat_error.offset + 1,
+ 'origin':origin, 'hint':hint})
+
+
+#===
+#
+# Class DbBase
+#
+#---
+
+class DBHandler(object):
+'''
+Handle a xml overlay database.
+'''
+
+def __init__(self, config, overlays, paths=None, ignore=0,
+ ignore_init_read_errors=False):
+
+self.config = config
+self.ignore = ignore
+self.overlays = overlays
+self.paths = paths
+self.output = config['output']
+self.ignore_init_read_errors = ignore_init_read_errors
+
+self.output.debug('Initializing XML overlay list handler', 8)
+
+
+def __eq__(self, other):
+for key in set(self.overlays.keys()) | set(other.overlays.keys()):
+if self.overlays[key] != other.overlays[key]:
+return False
+return True
+
+
+def __ne__(self, other):
+return not self.__eq__(other)
+
+
+def _broken_catalog_hint(self):
+this_function_name = sys._getframe().f_code.co_name
+
+msg = 'Method %(name)s.%(func)s not implemented'\
+  % {'name': self.__class__.__name__,
+ 'func': this_function_name}
+
+raise NotImplementedError(msg)

[gentoo-commits] proj/layman:master commit in: layman/tests/

2015-07-09 Thread Devan Franchini
commit: 0099095fd231d70b3f7e21bd7df7cbdac3c13d90
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Thu Jul  9 15:29:20 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Thu Jul  9 15:29:20 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=0099095f

external.py: Adds db_type to list of test config keys

 layman/tests/external.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/tests/external.py b/layman/tests/external.py
index f8bcc8c..97bd6ee 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -345,7 +345,7 @@ class CLIArgs(unittest.TestCase):
  'custom_news_pkg', 'cvs_addopts', 'cvs_command',
  'cvs_postsync', 'cvs_syncopts', 'darcs_addopts',
  'darcs_command', 'darcs_postsync', 'darcs_syncopts',
- 'g-common_command', 'g-common_generateopts',
+ 'db_type', 'g-common_command', 'g-common_generateopts',
  'g-common_postsync', 'g-common_syncopts',
  'g-sorcery_command', 'g-sorcery_generateopts',
  'g-sorcery_postsync', 'g-sorcery_syncopts', 'git_addopts',



[gentoo-commits] proj/layman:master commit in: layman/db_modules/xml/, layman/

2015-07-09 Thread Devan Franchini
commit: 47349f8b5ef3012c915ff8ad7825caefde103891
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Thu Jul  9 16:59:57 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Thu Jul  9 16:59:59 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=47349f8b

dbbase.py: Modifies read_db function to allow for passing a text parameter

This was done to allow for only one read*() function and add
compatibility with the way read() was originally set up.

xml.py: read_db() is also modified in this file for the same purpose.
remotedb.py: changes the calling of self.read() to self.read_db().

 layman/db_modules/xml/xml.py | 17 ++---
 layman/dbbase.py |  4 ++--
 layman/remotedb.py   |  2 +-
 3 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/layman/db_modules/xml/xml.py b/layman/db_modules/xml/xml.py
index 189e868..c444fc3 100644
--- a/layman/db_modules/xml/xml.py
+++ b/layman/db_modules/xml/xml.py
@@ -107,16 +107,19 @@ class DBHandler(object):
 raise NotImplementedError(msg)
 
 
-def read_db(self, path):
+def read_db(self, path, text=None):
 '''
 Read the overlay definition file.
 '''
-try:
-with fileopen(path, 'r') as df:
-document = df.read()
-except Exception as error:
-if not self.ignore_init_read_errors:
-msg = 'XML DBHandler - Failed to read the overlay list at'\
+document = text
+
+if not document:
+try:
+with fileopen(path, 'r') as df:
+document = df.read()
+except Exception as error:
+if not self.ignore_init_read_errors:
+msg = 'XML DBHandler - Failed to read the overlay list at'\
   '(%(path)s)' % {'path': path}
 self.output.error(msg)
 raise error

diff --git a/layman/dbbase.py b/layman/dbbase.py
index b6c32bc..56ef158 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -167,7 +167,7 @@ class DbBase(object):
 return
 
 
-def read_db(self, path):
+def read_db(self, path, text=None):
 '''
 Read the overlay database for installed overlay definitions.
 '''
@@ -178,7 +178,7 @@ class DbBase(object):
  self.ignore,
  self.ignore_init_read_errors)
 
-db_ctl.read_db(path)
+db_ctl.read_db(path, text=text)
 
 
 def write(self, path):

diff --git a/layman/remotedb.py b/layman/remotedb.py
index e6492f4..cd6ece3 100644
--- a/layman/remotedb.py
+++ b/layman/remotedb.py
@@ -280,7 +280,7 @@ class RemoteDB(DbBase):
 def _check_download(self, olist, url):
 
 try:
-self.read(olist, origin=url)
+self.read_db(url, text=olist)
 except Exception as error:
 self.output.debug(RemoteDB._check_download(), url=%s \nolist:\n
 % url,2)



[gentoo-commits] proj/layman:master commit in: layman/

2015-06-15 Thread Devan Franchini
commit: 7931ddc64b93574920fdc559927715b6e8b5d258
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Tue Jun 16 03:45:40 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Tue Jun 16 03:45:42 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=7931ddc6

cli.py: Removes docstring test and provides docstring description

 layman/cli.py | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/layman/cli.py b/layman/cli.py
index 81b10cd..bb9ea6f 100644
--- a/layman/cli.py
+++ b/layman/cli.py
@@ -108,8 +108,7 @@ class ListPrinter(object):
 
 def short_list(self, overlay):
 '''
- print(short_list(overlay))
-wrobel[Subversion] (https://o.g.o/svn/dev/wrobel   
  )
+Returns a list of information regarding the provided overlay parameter.
 '''
 name   = pad(overlay['name'], 25)
 



[gentoo-commits] proj/layman:master commit in: layman/tests/

2015-06-15 Thread Devan Franchini
commit: acf5162dc04352e1a4f2b6719157e5bedc7fb2fc
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Tue Jun 16 01:28:18 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Tue Jun 16 01:29:01 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=acf5162d

external.py: Renames test function to more appropriate name

Renames AddDeleteEnableDisableFromDB to AddDeleteEnableDisableFromConf
as the test is mainly testing the functionality of the conf files,
not the database classes.

 layman/tests/external.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/tests/external.py b/layman/tests/external.py
index eaa3510..713923b 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -53,7 +53,7 @@ if encoding != 'utf-8':
 
 HERE = os.path.dirname(os.path.realpath(__file__))
 
-class AddDeleteEnableDisableFromDB(unittest.TestCase):
+class AddDeleteEnableDisableFromConf(unittest.TestCase):
 
 def test(self):
 tmpdir = tempfile.mkdtemp(prefix='laymantmp_')



[gentoo-commits] proj/layman:master commit in: layman/tests/, layman/

2015-06-15 Thread Devan Franchini
commit: e6ff4558bedecb6e47700c815f8b6462ec02773f
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Tue Jun 16 03:34:58 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Tue Jun 16 03:35:01 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=e6ff4558

external.py: Adds AddDeleteDB test

db.py: Removes docstring tests in favor of external test suite.

 layman/db.py | 100 +--
 layman/tests/external.py |  90 ++
 2 files changed, 91 insertions(+), 99 deletions(-)

diff --git a/layman/db.py b/layman/db.py
index add8fa1..ba7399c 100644
--- a/layman/db.py
+++ b/layman/db.py
@@ -107,52 +107,7 @@ class DB(DbBase):
 def add(self, overlay):
 '''
 Add an overlay to the local list of overlays.
-
- import tempfile
- tmpdir = tempfile.mkdtemp(prefix=laymantmp_)
- write = os.path.join(tmpdir, 'installed.xml')
- write2 = os.path.join(tmpdir, 'make.conf')
- here = os.path.dirname(os.path.realpath(__file__))
- from layman.config import OptionConfig
- myoptions = {'installed' :
-...   here + '/tests/testfiles/global-overlays.xml',
-...   'local_list': here + '/tests/testfiles/overlays.xml',
-...   'make_conf' : write2,
-...   'nocheck': 'yes',
-...   'storage'   : tmpdir}
-
- config = OptionConfig(myoptions)
- config.set_option('quietness', 3)
- a = DB(config)
- config.set_option('installed', write)
- b = DB(config)
- config['output'].set_colorize(False)
-
- m = MakeConf(config, b.overlays)
- m.path = write2
- success = m.write()
- success
-True
-
-# Commented out since it needs network access:
-
-#  b.add(a.select('wrobel-stable')) #doctest: +ELLIPSIS
-# * Running command /usr/bin/rsync -rlptDvz --progress --delete 
--delete-after --timeout=180 --exclude=distfiles/* --exclude=local/* 
--exclude=packages/* rsync://gunnarwrobel.de/wrobel-stable/* 
/tmp/file.../wrobel-stable...
-#  c = DbBase([write, ], dict())
-#  c.overlays.keys()
-# ['wrobel-stable']
-
-#  m = MakeConf(config, b.overlays)
-#  [i.name for i in m.overlays] #doctest: +ELLIPSIS
-# ['wrobel-stable']
-
-#  os.unlink(write)
- os.unlink(write2)
-
- import shutil
- shutil.rmtree(tmpdir)
 '''
-
 if overlay.name not in self.overlays.keys():
 if not self._check_official(overlay):
 return False
@@ -188,61 +143,8 @@ class DB(DbBase):
 
 def delete(self, overlay):
 '''
-Add an overlay to the local list of overlays.
-
- import tempfile
- tmpdir = tempfile.mkdtemp(prefix=laymantmp_)
- write = os.path.join(tmpdir, 'installed.xml')
- write2 = os.path.join(tmpdir, 'make.conf')
- here = os.path.dirname(os.path.realpath(__file__))
- from layman.config import OptionConfig
- myoptions = {'installed' :
-...   here + '/tests/testfiles/global-overlays.xml',
-...   'local_list': here + '/tests/testfiles/overlays.xml',
-...   'make_conf' : write2,
-...   'nocheck': 'yes',
-...   'storage'   : tmpdir}
-
- config = OptionConfig(myoptions)
- config.set_option('quietness', 3)
- a = DB(config)
- config.set_option('installed', write)
- b = DB(config)
- config['output'].set_colorize(False)
-
- m = MakeConf(config, b.overlays)
- m.path = here + '/tests/testfiles/make.conf'
- m.read()
-True
-
- m.path = write2
- m.write()
-True
-
-#  b.add(a.select('wrobel-stable')) #doctest: +ELLIPSIS
-# * Running command /usr/bin/rsync -rlptDvz --progress --delete 
--delete-after --timeout=180 --exclude=distfiles/* --exclude=local/* 
--exclude=packages/* rsync://gunnarwrobel.de/wrobel-stable/* 
/tmp/file.../wrobel-stable...
-#  b.add(a.select('wrobel')) #doctest: +ELLIPSIS
-# * Running command /usr/bin/svn co 
https://overlays.gentoo.org/svn/dev/wrobel/; /tmp/file.../wrobel...
-#  c = DbBase([write, ], dict())
-#  c.overlays.keys()
-# ['wrobel', 'wrobel-stable']
-
-#  b.delete(b.select('wrobel'))
-#  c = DbBase([write, ], dict())
-#  c.overlays.keys()
-# ['wrobel-stable']
-
-#  m = MakeConf(config, b.overlays)
-#  [i.name for i in m.overlays] #doctest: +ELLIPSIS
-# ['wrobel-stable']
-
-#  os.unlink(write)
- os.unlink(write2)
-
- import shutil
- shutil.rmtree(tmpdir)
+Delete an overlay from the local list of overlays.
 '''
-
 if 

[gentoo-commits] proj/layman:master commit in: layman/

2015-06-13 Thread Devan Franchini
commit: 5d35a885435a5e01e9073826dcd6ad5c7a73201b
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Sun Jun 14 04:09:04 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Sun Jun 14 04:09:08 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=5d35a885

dbbase.py: Code cleanup

Cleans up things including:
* docstring formatting, and file name in docstring
* line spacing and formatting to coincide throughout the file
* error message output
* etc

 layman/dbbase.py | 99 
 1 file changed, 56 insertions(+), 43 deletions(-)

diff --git a/layman/dbbase.py b/layman/dbbase.py
index 4c3bf5f..3e47384 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -1,9 +1,9 @@
 #!/usr/bin/python
 # -*- coding: utf-8 -*-
 
#
-# LAYMAN OVERLAY HANDLER
+# LAYMAN DB BASE
 
#
-# File:   overlay.py
+# File:   dbbase.py
 #
 # Access to an xml list of overlays
 #
@@ -17,6 +17,7 @@
 # Gunnar Wrobel wro...@gentoo.org
 # Sebastian Pipping sebast...@pipping.org
 # Christian Groschupp christ...@groschupp.org
+# Devan Franchini twitch...@gentoo.org
 #
 '''Main handler for overlays.'''
 
@@ -78,8 +79,10 @@ class BrokenOverlayCatalog(ValueError):
 hint = '\nHint: %s' % hint
 
 super(BrokenOverlayCatalog, self).__init__(
-'XML parsing failed for %(origin)s (line %(line)d, column 
%(column)d)%(hint)s' % \
-{'line':expat_error.lineno, 'column':expat_error.offset + 1, 
'origin':origin, 'hint':hint})
+'XML parsing failed for %(origin)s (line %(line)d, column'\
+'%(column)d)%(hint)s' % {'line': expat_error.lineno,
+ 'column':expat_error.offset + 1,
+ 'origin':origin, 'hint':hint})
 
 
 
#===
@@ -89,23 +92,23 @@ class BrokenOverlayCatalog(ValueError):
 
#---
 
 class DbBase(object):
-''' Handle a list of overlays.'''
+'''
+Handle a list of overlays.
+'''
 
 def __init__(self, config, paths=None, ignore = 0,
-ignore_init_read_errors=False, allow_missing=False
-):
+ignore_init_read_errors=False, allow_missing=False):
 
 self.config = config
-self.paths = paths
 self.ignore = ignore
+self.paths = paths
 self.output = config['output']
-self.ignore_init_read_errors = ignore_init_read_errors
-
 self.overlays = {}
+self.ignore_init_read_errors = ignore_init_read_errors
+path_found = False
 
 self.output.debug('Initializing overlay list handler', 8)
 
-path_found = False
 for path in self.paths:
 if not os.path.exists(path):
 continue
@@ -114,8 +117,8 @@ class DbBase(object):
 path_found = True
 
 if not path_found and not allow_missing:
-self.output.warn(Warning: an installed db file was not found at: 
%s
-% str(self.paths))
+msg = Warning: an installed db file was not found at: %(path)s
+self.output.warn(msg % {'path': str(self.paths)})
 
 
 def __eq__(self, other):
@@ -130,8 +133,9 @@ class DbBase(object):
 
 
 def read_file(self, path):
-'''Read the overlay definition file.'''
-
+'''
+Read the overlay definition file.
+'''
 try:
 with fileopen(path, 'r') as df:
 document = df.read()
@@ -147,32 +151,33 @@ class DbBase(object):
 
 def _broken_catalog_hint(self):
 this_function_name = sys._getframe().f_code.co_name
-raise NotImplementedError('Method %s.%s not implemented' % \
-(self.__class__.__name__, this_function_name))
+msg = 'Method %(name)s.%(func)s not implemented'\
+  % {'name': self.__class__.__name__,
+ 'func': this_function_name}
+raise NotImplementedError(msg)
 
 
 def read(self, text, origin):
 '''
-Read an xml list of overlays (adding to and potentially overwriting 
existing entries)
+Read an xml list of overlays (adding to and potentially overwriting
+existing entries)
 '''
 try:
 document = ET.fromstring(text)
-except xml.parsers.expat.ExpatError as error:
-raise BrokenOverlayCatalog(origin, error, 
self._broken_catalog_hint())
+except xml.parsers.expat.ExpatError as err:
+raise BrokenOverlayCatalog(origin, err, 
self._broken_catalog_hint())
 
-overlays = document.findall('overlay') + \
- 

[gentoo-commits] proj/layman:master commit in: layman/

2015-06-12 Thread Devan Franchini
commit: 47eedeb3ec092b6916e309a36adb3e9baee4024a
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Sat Jun 13 04:51:04 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Sat Jun 13 04:51:19 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=47eedeb3

flocker.py: Adds file mode checking for get_file()

Ensures that the file being returned by get_file() is opened with
the correct mode.

 layman/flocker.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/layman/flocker.py b/layman/flocker.py
index aa5f3f8..3b9df64 100644
--- a/layman/flocker.py
+++ b/layman/flocker.py
@@ -73,7 +73,8 @@ class FileLocker(object):
 if mode not in ('r', 'w+'):
 raise LockingException('Invalid mode %(mode)s' % {'mode': mode})
 
-if path not in self.files or self.files[path].closed:
+if (path not in self.files or self.files[path].closed or
+self.files[path].mode != mode):
 self.files[path] = fileopen(path, mode)
 
 f = self.files[path]



[gentoo-commits] proj/layman:master commit in: layman/

2015-06-12 Thread Devan Franchini
commit: 5fa31f084469c2a0fc72fba1bffd7bfb3f0384e8
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Sat Jun 13 02:38:14 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Sat Jun 13 02:38:14 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=5fa31f08

flocker.py: Removes assert for more verbose exception

 layman/flocker.py | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/layman/flocker.py b/layman/flocker.py
index 36a12b8..aa5f3f8 100644
--- a/layman/flocker.py
+++ b/layman/flocker.py
@@ -70,7 +70,8 @@ class FileLocker(object):
 
 def get_file(self, path, mode='r'):
 '''Obtains file object for given path'''
-assert mode in ('r', 'w+')
+if mode not in ('r', 'w+'):
+raise LockingException('Invalid mode %(mode)s' % {'mode': mode})
 
 if path not in self.files or self.files[path].closed:
 self.files[path] = fileopen(path, mode)



[gentoo-commits] proj/layman:master commit in: layman/

2015-06-12 Thread Devan Franchini
commit: 7f3945f376304360689cb8cb9c1777ed69ac4367
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Sat Jun 13 02:30:50 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Sat Jun 13 02:30:50 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=7f3945f3

flocker.py: Adds check to ensure get_file isn't passing a closed io object

 layman/flocker.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/flocker.py b/layman/flocker.py
index 21f34c3..36a12b8 100644
--- a/layman/flocker.py
+++ b/layman/flocker.py
@@ -72,7 +72,7 @@ class FileLocker(object):
 '''Obtains file object for given path'''
 assert mode in ('r', 'w+')
 
-if path not in self.files:
+if path not in self.files or self.files[path].closed:
 self.files[path] = fileopen(path, mode)
 
 f = self.files[path]



[gentoo-commits] proj/layman:master commit in: layman/

2015-05-13 Thread Devan Franchini
commit: f73e60a7df4dfe91bc43fd0bb9cbb481fe9dc294
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Wed May 13 19:59:13 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Wed May 13 19:59:13 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=f73e60a7

flocker.py: Adds file locking utility class

 layman/flocker.py | 66 +++
 1 file changed, 66 insertions(+)

diff --git a/layman/flocker.py b/layman/flocker.py
new file mode 100644
index 000..d40925d
--- /dev/null
+++ b/layman/flocker.py
@@ -0,0 +1,66 @@
+#!/usr/bin/python
+# -*- coding: utf-8 -*-
+# File:   flocker.py
+#
+# Handles all file locking.
+#
+# Copyright:
+# (c) 2015 Devan Franchini
+# Distributed under the terms of the GNU General Public License v2
+#
+# Author(s):
+# Michał Górny mgo...@gentoo.org
+# Devan Franchini twitch...@gentoo.org
+#
+
+#===
+#
+# Dependencies
+#
+#---
+import fcntl
+
+from layman.compatibility import fileopen
+
+
+class FileLocker(object):
+
+def __init__(self):
+self.files = {}
+self.locked = set()
+
+
+def lock_file(self, path, exclusive=False):
+'''Lock the file located at path.'''
+file_mode = 'r'
+lock_mode = fcntl.LOCK_SH
+
+if exclusive:
+file_mode = 'w+'
+lock_mode = fcntl.LOCK_EX
+
+assert path not in self.locked
+
+self.locked.add(path)
+fcntl.flock(self.get_file(path, file_mode).fileno(), lock_mode)
+
+
+def unlock_file(self, path):
+'''Unlock the file located at path.'''
+assert path in self.locked
+
+fcntl.flock(self.get_file(path).fileno(), fcntl.LOCK_UN)
+self.locked.discard(path)
+
+
+def get_file(self, path, mode='r'):
+'''Obtains file object for given path'''
+assert mode in ('r', 'w+')
+
+if path not in self.files:
+self.files[path] = fileopen(path, mode)
+
+f = self.files[path]
+f.seek(0)
+
+return f



[gentoo-commits] proj/layman:master commit in: layman/

2015-05-13 Thread Devan Franchini
commit: 5c78be3e7b9ab9c7a03e7828f679ce123c5f87ab
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Wed May 13 20:06:04 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Wed May 13 20:06:04 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=5c78be3e

dbbase.py: Reorganizes imports

 layman/dbbase.py | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/layman/dbbase.py b/layman/dbbase.py
index 7bfb60f..4c3bf5f 100644
--- a/layman/dbbase.py
+++ b/layman/dbbase.py
@@ -30,7 +30,9 @@ __version__ = $Id: overlay.py 273 2006-12-30 15:54:50Z 
wrobel $
 #
 
#---
 
-import sys, os, os.path
+import os
+import os.path
+import sys
 import xml
 import xml.etree.ElementTree as ET # Python 2.5
 



[gentoo-commits] proj/layman:master commit in: layman/

2015-05-13 Thread Devan Franchini
commit: 8fad7fae53cb2ba0e4dbdfff570d7d5f4872c468
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Wed May 13 21:28:24 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Wed May 13 21:28:24 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=8fad7fae

api.py: Cleans up error message structure

 layman/api.py | 33 +
 1 file changed, 17 insertions(+), 16 deletions(-)

diff --git a/layman/api.py b/layman/api.py
index 12c2368..60ac9a8 100755
--- a/layman/api.py
+++ b/layman/api.py
@@ -126,9 +126,8 @@ class LaymanAPI(object):
 success = self._get_installed_db().delete(
 self._get_installed_db().select(ovl))
 except Exception as e:
-self._error(
-Exception caught removing repository '+ovl+
-':\n+str(e))
+self._error('Exception caught removing repository 
%(repo)s:\n'
+'%(err)s' % {'repo': ovl, 'err': e})
 results.append(success)
 self.get_installed(dbreload=True)
 if False in results:
@@ -160,8 +159,8 @@ class LaymanAPI(object):
 success = self._get_installed_db().add(
 self._get_remote_db().select(ovl))
 except Exception as e:
-self._error(Exception caught installing repository '+ovl+
-' : +str(e))
+self._error('Exception caught installing repository 
%(repo)s:'
+'\n%(err)s' % {'repo': ovl, 'err': e})
 results.append(success)
 self.get_installed(dbreload=True)
 if (True in results) and update_news:
@@ -202,7 +201,7 @@ class LaymanAPI(object):
 self._get_installed_db().select(ovl))
 except Exception as e:
 self._error('Exception caught disabling repository %(repo)s'\
-': %(err)s' % ({'repo': ovl, 'err': e}))
+':\n%(err)s' % {'repo': ovl, 'err': e})
 results.append(success)
 self.get_installed(dbreload=True)
 if (True in results) and update_news:
@@ -227,7 +226,7 @@ class LaymanAPI(object):
 self._get_installed_db().select(ovl))
 except Exception as e:
 self._error('Exception caught enabling repository %(repo)s'\
-': %(err)s' % ({'repo': ovl, 'err': e}))
+':\n%(err)s' % {'repo': ovl, 'err': e})
 results.append(success)
 self.get_installed(dbreload=True)
 if (True in results) and update_news:
@@ -467,18 +466,20 @@ class LaymanAPI(object):
 #self.output.debug(API.sync(); UnknownOverlayException 
selecting %s %ovl, 5)
 #self._error(str(error))
 fatals.append((ovl,
-'Failed to select overlay ' + ovl + '.\nError was: '
-+ str(error)))
+'Failed to select overlay %(repo)s.\nError was: 
%(error)s'
+ % {'repo': ovl, 'err': error))
 self.output.debug(API.sync(); UnknownOverlayException 
-selecting %s.   continuing to next ovl... %ovl, 5)
+selecting %(repo)s.   continuing to next ovl...
+% {'repo': ovl}, 5)
 continue
 
 try:
 self.output.debug(API.sync(); try: 
self._get_remote_db().select(ovl), 5)
 ordb = self._get_remote_db().select(ovl)
 except UnknownOverlayException:
-message = 'Overlay %s could not be found in the remote 
lists.\n' \
-'Please check if it has been renamed and re-add if 
necessary.' % ovl
+message = 'Overlay %(repo)s could not be found in the remote 
'\
+'lists.\nPlease check if it has been renamed and '\
+'re-add if necessary.' % {'repo': ovl}
 warnings.append((ovl, message))
 (diff_type, update_url) = (False, False)
 else:
@@ -516,8 +517,8 @@ class LaymanAPI(object):
 success.append((ovl,'Successfully synchronized overlay ' 
+ ovl + '.'))
 except Exception as error:
 fatals.append((ovl,
-'Failed to sync overlay ' + ovl + '.\nError was: '
-+ str(error)))
+'Failed to sync overlay %(repo)s.\nError was: %(err)s'
+% {'repo': ovl, 'err': error}))
 
 if output_results:
 if success:
@@ -559,8 +560,8 @@ class LaymanAPI(object):
 'LaymanAPI.fetch_remote_list(); cache updated = %s'
 % str(dbreload),8)
 except Exception as error:
-self.output.error('Failed to fetch overlay list!\n Original Error 

[gentoo-commits] proj/layman:master commit in: layman/

2015-05-13 Thread Devan Franchini
commit: 9edab5141973bd1275117cc1f2b818cf3b36d060
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Wed May 13 21:32:37 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Wed May 13 21:32:37 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=9edab514

api.py: Properly closes fatal error message brackets on line 470

 layman/api.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/api.py b/layman/api.py
index 60ac9a8..5a02aab 100755
--- a/layman/api.py
+++ b/layman/api.py
@@ -467,7 +467,7 @@ class LaymanAPI(object):
 #self._error(str(error))
 fatals.append((ovl,
 'Failed to select overlay %(repo)s.\nError was: 
%(error)s'
- % {'repo': ovl, 'err': error))
+ % {'repo': ovl, 'err': error}))
 self.output.debug(API.sync(); UnknownOverlayException 
 selecting %(repo)s.   continuing to next ovl...
 % {'repo': ovl}, 5)



[gentoo-commits] proj/layman:master commit in: layman/

2015-05-13 Thread Devan Franchini
commit: 5087e5f1a7e958eb2b28815453c403572e9e2f1f
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Wed May 13 20:39:20 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Wed May 13 20:39:20 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=5087e5f1

flocker.py: Adds exception raising to relay errors properly

 layman/flocker.py | 19 +--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/layman/flocker.py b/layman/flocker.py
index d40925d..21f34c3 100644
--- a/layman/flocker.py
+++ b/layman/flocker.py
@@ -22,6 +22,17 @@ import fcntl
 
 from layman.compatibility import fileopen
 
+class LockingException(Exception):
+'''
+Exception class for relay errors properly
+'''
+def __init__(self, msg):
+self.msg = msg
+
+
+def __str__(self):
+return repr(self.msg)
+
 
 class FileLocker(object):
 
@@ -39,7 +50,9 @@ class FileLocker(object):
 file_mode = 'w+'
 lock_mode = fcntl.LOCK_EX
 
-assert path not in self.locked
+if path in self.locked:
+raise LockingException('%(path)s is already locked.'
+% {'path': path})
 
 self.locked.add(path)
 fcntl.flock(self.get_file(path, file_mode).fileno(), lock_mode)
@@ -47,7 +60,9 @@ class FileLocker(object):
 
 def unlock_file(self, path):
 '''Unlock the file located at path.'''
-assert path in self.locked
+if path not in self.locked:
+raise LockingException('%(path)s is not locked, unlocking failed'
+% {'path': path})
 
 fcntl.flock(self.get_file(path).fileno(), fcntl.LOCK_UN)
 self.locked.discard(path)



[gentoo-commits] proj/layman:master commit in: layman/

2015-04-22 Thread Devan Franchini
commit: 46f4adc7bdf67b69d130defbfcec9f623cbfef78
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Wed Apr 22 17:40:04 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Wed Apr 22 17:40:07 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=46f4adc7

api.py: Adds prompt for user to re-add overlay after unsuccessful URL update

X-Gentoo-Bug: 547388
X-Gentoo-Bug-URL: https://bugs.gentoo.org/547388

 layman/api.py | 9 ++---
 1 file changed, 6 insertions(+), 3 deletions(-)

diff --git a/layman/api.py b/layman/api.py
index 82436fc..12c2368 100755
--- a/layman/api.py
+++ b/layman/api.py
@@ -26,7 +26,7 @@ from layman.remotedbimport RemoteDB
 from layman.overlays.source import require_supported
 #from layman.utils import path, delete_empty_directory
 from layman.compatibility   import encode
-from layman.utils   import verify_overlay_src
+from layman.utils   import get_ans, verify_overlay_src
 from layman.mounter import Mounter
 
 if sys.hexversion = 0x30200f0:
@@ -499,8 +499,11 @@ class LaymanAPI(object):
 warnings.append((ovl, url_msg))
 update_success = db.update(ordb, available_srcs)
 if not update_success:
-self.output.warn('Failed to update 
repo...readding', 2)
-self.readd_repos(ovl)
+msg = 'Failed to update source URL for 
overlay'\
+  '%(ovl)s. Re-add overlay? [y/n]'\
+  % {'ovl': ovl}
+if get_ans(msg, color='yellow'):
+self.readd_repos(ovl)
 except Exception as error:
 self.output.warn('Failed to perform overlay type or url 
updates', 2)
 self.output.warn('for Overlay: %s' % ovl, 2)



[gentoo-commits] proj/layman:master commit in: layman/config_modules/reposconf/

2015-04-20 Thread Devan Franchini
commit: 155056d851373a3415faedc6c00faae04e9b48b1
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Apr 20 17:11:25 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Apr 20 17:11:29 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=155056d8

reposconf.py: Adds proper disabling of overlays when option is ALL

X-Gentoo-Bug: 546852
X-Gentoo-Bug-URL: https://bugs.gentoo.org/546852

 layman/config_modules/reposconf/reposconf.py | 8 +---
 1 file changed, 5 insertions(+), 3 deletions(-)

diff --git a/layman/config_modules/reposconf/reposconf.py 
b/layman/config_modules/reposconf/reposconf.py
index a57c87e..1f0fd04 100644
--- a/layman/config_modules/reposconf/reposconf.py
+++ b/layman/config_modules/reposconf/reposconf.py
@@ -194,9 +194,11 @@ class ConfigHandler:
 # start over with a fresh instance
 self.repo_conf = ConfigParser.ConfigParser()
 if not self.repo_conf.sections():
-for i in sorted(self.overlays):
-if not i == delete:
-self.add(self.overlays[i], no_write=True)
+if ('disable' in self.config.keys() and not
+self.config['disable'][0].lower() == 'all'):
+for i in sorted(self.overlays):
+if not i == delete:
+self.add(self.overlays[i], no_write=True)
 self.repo_conf.write(laymanconf)
 self.rebuild = False
 return True



[gentoo-commits] proj/layman:master commit in: layman/

2015-04-20 Thread Devan Franchini
commit: 0c3521396aac386705a46f97c70b72785a992395
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Mon Apr 20 17:14:29 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Mon Apr 20 17:14:34 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=0c352139

updater.py: Corrects Package misspelling

X-Gentoo-Bug: 546032
X-Gentoo-Bug-URL: https://bugs.gentoo.org/546032

 layman/updater.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/updater.py b/layman/updater.py
index 521f9b3..1959a31 100644
--- a/layman/updater.py
+++ b/layman/updater.py
@@ -58,7 +58,7 @@ class Main(object):
 self.parser.add_argument(-c, --config,
 help='the path to config file')
 self.parser.add_argument(-R, --rebuild, action='store_true',
-help='rebuild the Pacakge Manager config file')
+help='rebuild the Package Manager config file')
 self.parser.add_argument('--version', action='version',
 version='%(prog)s ' + VERSION)
 



[gentoo-commits] proj/layman:master commit in: layman/tests/

2015-03-27 Thread Devan Franchini
commit: 18e0e25f18745a507a25b175986b855e0ec996a9
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Mar 27 20:50:17 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Mar 27 20:50:17 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=18e0e25f

external.py: Adds protocol_filter to keys to test for CLIArgs test

 layman/tests/external.py | 15 +++
 1 file changed, 7 insertions(+), 8 deletions(-)

diff --git a/layman/tests/external.py b/layman/tests/external.py
index ad630e6..d9ef858 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -258,14 +258,13 @@ class CLIArgs(unittest.TestCase):
  'make_conf', 'mercurial_addopts', 'mercurial_command',
  'mercurial_postsync', 'mercurial_syncopts',
  'news_reporter', 'nocheck', 'overlay_defs', 'overlays',
- 'quietness', 'repos_conf', 'require_repoconfig',
- 'rsync_command', 'rsync_postsync', 'rsync_syncopts',
- 'squashfs_addopts', 'squashfs_command',
- 'squashfs_postsync', 'squashfs_syncopts',
- 'storage', 'support_url_updates', 'svn_addopts',
- 'svn_command', 'svn_postsync', 'svn_syncopts',
- 't/f_options', 'tar_command', 'tar_postsync', 'umask',
- 'width']
+ 'protocol_filter', 'quietness', 'repos_conf',
+ 'require_repoconfig', 'rsync_command', 'rsync_postsync',
+ 'rsync_syncopts', 'squashfs_addopts', 'squashfs_command',
+ 'squashfs_postsync', 'squashfs_syncopts', 'storage',
+ 'support_url_updates', 'svn_addopts', 'svn_command',
+ 'svn_postsync', 'svn_syncopts', 't/f_options',
+ 'tar_command', 'tar_postsync', 'umask', 'width']
 # Due to this not being a dict object, the keys() invocation is needed.
 self.assertEqual(sorted(a.keys()), test_keys)
 



[gentoo-commits] proj/layman:master commit in: layman/tests/

2015-03-27 Thread Devan Franchini
commit: 7011c1ec70ad98f818f3fc7b549c3dae8f5ad1da
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Mar 27 21:37:58 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Mar 27 21:37:58 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=7011c1ec

external.py: Adds __future__ import for unicode_literals

 layman/tests/external.py | 1 +
 1 file changed, 1 insertion(+)

diff --git a/layman/tests/external.py b/layman/tests/external.py
index d9ef858..64a4263 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -15,6 +15,7 @@
 #
 
 from __future__ import print_function
+from __future__ import unicode_literals
 
 '''Runs external (non-doctest) test cases.'''
 



[gentoo-commits] proj/layman:master commit in: layman/tests/

2015-03-27 Thread Devan Franchini
commit: c782c43b14d71766ed22b9eb39c6bd5bec9a264c
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Mar 27 22:02:48 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Mar 27 22:02:51 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=c782c43b

external.py: Attempts to set default string encoding to utf-8

X-Gentoo-Bug: 539416
X-Gentoo-Bug-URL: https://bugs.gentoo.org/539416

 layman/tests/external.py | 6 ++
 1 file changed, 6 insertions(+)

diff --git a/layman/tests/external.py b/layman/tests/external.py
index 64a4263..eaa3510 100755
--- a/layman/tests/external.py
+++ b/layman/tests/external.py
@@ -45,6 +45,12 @@ from  layman.repoconfmanager  import RepoConfManager
 from  layman.utilsimport path
 from  warnings import filterwarnings, resetwarnings
 
+encoding = sys.getdefaultencoding()
+
+if encoding != 'utf-8':
+reload(sys)
+sys.setdefaultencoding('utf-8')
+
 HERE = os.path.dirname(os.path.realpath(__file__))
 
 class AddDeleteEnableDisableFromDB(unittest.TestCase):



[gentoo-commits] proj/layman:master commit in: layman/

2015-03-27 Thread Devan Franchini
commit: d1bb8a0ba7e2a906db4e550d653dbabaf2d9a8b5
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Fri Mar 27 23:16:38 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Fri Mar 27 23:40:19 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=d1bb8a0b

version.py: Bumps version

 layman/version.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/version.py b/layman/version.py
index 75feadb..ee73005 100644
--- a/layman/version.py
+++ b/layman/version.py
@@ -24,7 +24,7 @@ from __future__ import unicode_literals
 __version__ = $Id: version.py 309 2007-04-09 16:23:38Z wrobel $
 
 
-VERSION = '2.3.0'
+VERSION = '2.3.1-git'
 
 if __name__ == '__main__':
 print(VERSION)



[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-03-26 Thread Devan Franchini
commit: f581549abe1d807c9d6d84d76978a08c8394ee3b
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Thu Mar 26 18:13:45 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Thu Mar 26 18:13:45 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=f581549a

overlay.py: Adds overlay source protocol filtering

 layman/overlays/overlay.py | 35 +--
 1 file changed, 33 insertions(+), 2 deletions(-)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 55ef8a8..59aa74b 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -69,6 +69,29 @@ class Overlay(object):
 self.from_dict(ovl_dict, ignore)
 
 
+def filter_protocols(self, sources, create_source_func):
+'''
+Filters any protocols not specified in self.config['protocol_order']
+from the overlay's sources.
+'''
+_sources = []
+if not 'protocol_order' in self.config.keys():
+return [create_source_func(e) for e in sources]
+
+for e in sources:
+source = create_source_func(e)
+for protocol in self.config['protocol_order']:
+protocol = protocol.lower()
+#re.search considers \+ as the literal +.
+if protocol == 'git+ssh':
+protocol = 'git\+ssh'
+protocol += '://'
+if re.search('^' + protocol, source.src):
+_sources.append(source)
+
+return _sources
+
+
 def from_xml(self, xml, ignore):
 Process an xml overlay definition
 
@@ -121,7 +144,7 @@ class Overlay(object):
 raise Exception('Overlay from_xml(), ' + self.name + \
 ' is missing a source entry!')
 
-self.sources = [create_overlay_source(e) for e in _sources]
+self.sources = self.filter_protocols(_sources, create_overlay_source)
 
 _owner = xml.find('owner')
 if _owner == None:
@@ -231,7 +254,7 @@ class Overlay(object):
 return _class(parent=self, config=self.config,
 _location=_location, ignore=ignore)
 
-self.sources = [create_dict_overlay_source(e) for e in _sources]
+self.sources = self.filter_protocols(_sources, 
create_dict_overlay_source)
 
 if 'owner_name' in overlay:
 _owner = overlay['owner_name']
@@ -379,6 +402,14 @@ class Overlay(object):
 def add(self, base):
 res = 1
 first_s = True
+
+if 'protocol_order' in self.config.keys() and not self.sources:
+msg = 'Overlay.add() error: overlay %s does not support any of'\
+  ' the given\nprotocols %s and cannot be installed.'\
+  % (self.name, str(self.config['protocol_order']))
+self.output.error(msg)
+return 1
+
 for s in self.sources:
 if not first_s:
 self.output.info(\nTrying next source of listed sources..., 
4)



[gentoo-commits] proj/layman:master commit in: layman/

2015-03-26 Thread Devan Franchini
commit: ba4a302400a01aa9c524cfe0cb5c6a0af1b0f010
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Thu Mar 26 22:05:54 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Thu Mar 26 22:05:54 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=ba4a3024

argsparser.py: Fixes default override of protocol_order config option

 layman/argsparser.py | 12 +++-
 1 file changed, 11 insertions(+), 1 deletion(-)

diff --git a/layman/argsparser.py b/layman/argsparser.py
index a12b95a..44b2ca4 100644
--- a/layman/argsparser.py
+++ b/layman/argsparser.py
@@ -358,7 +358,17 @@ class ArgsParser(BareConfig):
 storage = self.options[key]
 if storage:
 return storage
-
+
+if key == 'protocol_order':
+protocol_order = []
+if (key in self.options.keys()
+and not self.options[key] is None):
+protocol_order = self.options[key]
+if self.config.has_option('MAIN', 'protocol_order'):
+protocol_order = self.config.get('MAIN', 'protocol_order')
+if protocol_order:
+return protocol_order
+
 if key == 'overlays':
 overlays = ''
 if (key in self.options.keys()



[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-03-26 Thread Devan Franchini
commit: e0f317c1e3443b8b43fe11033897624dbda83483
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Thu Mar 26 23:47:36 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Thu Mar 26 23:47:36 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=e0f317c1

overlay.py: Closes off interpolation tuple for error message in update()

 layman/overlays/overlay.py | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 2257373..fa728f6 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -435,7 +435,7 @@ class Overlay(object):
 if not self.sources or not available_srcs:
 msg = 'Overlay.update() error: overlay %s does not support the'\
   'given protocol(s) %s and cannot be updated.'\
-  % (self.name, str(self.config['protocol_order'])
+  % (self.name, str(self.config['protocol_order']))
 self.output.error(msg)
 return 1
 



[gentoo-commits] proj/layman:master commit in: layman/

2015-03-26 Thread Devan Franchini
commit: e8f1abce52ccf6812b2b25ec6cd0f4d901302c64
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Thu Mar 26 22:48:39 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Thu Mar 26 22:48:39 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=e8f1abce

argsparser.py: Adds proper splitting of protocol_order config option

 layman/argsparser.py | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/layman/argsparser.py b/layman/argsparser.py
index 44b2ca4..eede806 100644
--- a/layman/argsparser.py
+++ b/layman/argsparser.py
@@ -367,6 +367,8 @@ class ArgsParser(BareConfig):
 if self.config.has_option('MAIN', 'protocol_order'):
 protocol_order = self.config.get('MAIN', 'protocol_order')
 if protocol_order:
+if not isinstance(protocol_order, list):
+protocol_order = [e.strip() for e in 
protocol_order.split(',')]
 return protocol_order
 
 if key == 'overlays':



[gentoo-commits] proj/layman:master commit in: layman/overlays/

2015-03-26 Thread Devan Franchini
commit: a263463472cee1763e9e6abb915b015ee1de0cb7
Author: Devan Franchini twitch153 AT gentoo DOT org
AuthorDate: Thu Mar 26 23:06:25 2015 +
Commit: Devan Franchini twitch153 AT gentoo DOT org
CommitDate: Thu Mar 26 23:06:27 2015 +
URL:https://gitweb.gentoo.org/proj/layman.git/commit/?id=a2634634

overlay.py: Modifies the implementation of filter_protocols

This modification allows for layman to only filter protocols
when running Overlay.add() and Overlay.update(), preventing
redundant code and checks along the way.

X-Gentoo-Bug: 542342
X-Gentoo-Bug-URL: https://bugs.gentoo.org/542342

 layman/overlays/overlay.py | 29 +++--
 1 file changed, 19 insertions(+), 10 deletions(-)

diff --git a/layman/overlays/overlay.py b/layman/overlays/overlay.py
index 59aa74b..2257373 100755
--- a/layman/overlays/overlay.py
+++ b/layman/overlays/overlay.py
@@ -69,17 +69,16 @@ class Overlay(object):
 self.from_dict(ovl_dict, ignore)
 
 
-def filter_protocols(self, sources, create_source_func):
+def filter_protocols(self, sources):
 '''
 Filters any protocols not specified in self.config['protocol_order']
 from the overlay's sources.
 '''
 _sources = []
-if not 'protocol_order' in self.config.keys():
-return [create_source_func(e) for e in sources]
+if not self.config['protocol_order']:
+return sources
 
-for e in sources:
-source = create_source_func(e)
+for source in sources:
 for protocol in self.config['protocol_order']:
 protocol = protocol.lower()
 #re.search considers \+ as the literal +.
@@ -144,7 +143,7 @@ class Overlay(object):
 raise Exception('Overlay from_xml(), ' + self.name + \
 ' is missing a source entry!')
 
-self.sources = self.filter_protocols(_sources, create_overlay_source)
+self.sources = [create_overlay_source(e) for e in _sources]
 
 _owner = xml.find('owner')
 if _owner == None:
@@ -254,7 +253,7 @@ class Overlay(object):
 return _class(parent=self, config=self.config,
 _location=_location, ignore=ignore)
 
-self.sources = self.filter_protocols(_sources, 
create_dict_overlay_source)
+self.sources = [create_dict_overlay_source(e) for e in _sources]
 
 if 'owner_name' in overlay:
 _owner = overlay['owner_name']
@@ -403,9 +402,10 @@ class Overlay(object):
 res = 1
 first_s = True
 
-if 'protocol_order' in self.config.keys() and not self.sources:
-msg = 'Overlay.add() error: overlay %s does not support any of'\
-  ' the given\nprotocols %s and cannot be installed.'\
+self.sources = filter_protocols(self.sources)
+if not self.sources:
+msg = 'Overlay.add() error: overlay %s does not support the'\
+  ' given\nprotocol(s) %s and cannot be installed.'\
   % (self.name, str(self.config['protocol_order']))
 self.output.error(msg)
 return 1
@@ -430,6 +430,15 @@ class Overlay(object):
 first_src = True
 result = False
 
+self.sources = filter_protocols(self.sources)
+available_srcs = filter_protocols(available_srcs)
+if not self.sources or not available_srcs:
+msg = 'Overlay.update() error: overlay %s does not support the'\
+  'given protocol(s) %s and cannot be updated.'\
+  % (self.name, str(self.config['protocol_order'])
+self.output.error(msg)
+return 1
+
 if isinstance(available_srcs, str):
 available_srcs = [available_srcs]
 



  1   2   3   >