Gentoo Archives: gentoo-commits

From: Brian Dolbec <brian.dolbec@×××××.com>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/
Date: Fri, 02 May 2014 23:13:38
Message-Id: 1399071905.1ebdf50910a3efaba00f7c64b865cdfdf1cca9e9.dol-sen@gentoo
1 commit: 1ebdf50910a3efaba00f7c64b865cdfdf1cca9e9
2 Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org>
3 AuthorDate: Wed Feb 19 08:22:42 2014 +0000
4 Commit: Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
5 CommitDate: Fri May 2 23:05:05 2014 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=1ebdf509
7
8 Initial stubbing out of a common SyncBase class
9
10 Add copyright
11 Optimize bin_command handling in __init__().
12
13 ---
14 pym/portage/sync/syncbase.py | 100 +++++++++++++++++++++++++++++++++++++++++++
15 1 file changed, 100 insertions(+)
16
17 diff --git a/pym/portage/sync/syncbase.py b/pym/portage/sync/syncbase.py
18 new file mode 100644
19 index 0000000..2b6b8c7
20 --- /dev/null
21 +++ b/pym/portage/sync/syncbase.py
22 @@ -0,0 +1,100 @@
23 +# Copyright 2014 Gentoo Foundation
24 +# Distributed under the terms of the GNU General Public License v2
25 +
26 +'''
27 +Base class for performing sync operations.
28 +This class contains common initialization code and functions.
29 +'''
30 +
31 +
32 +import os
33 +
34 +import portage
35 +from portage.util import writemsg_level
36 +
37 +
38 +class SyncBase(object):
39 + '''Base Sync class for subclassing'''
40 +
41 + short_desc = "Perform sync operations on repositories"
42 +
43 + @staticmethod
44 + def name():
45 + return "BlankSync"
46 +
47 +
48 + def can_progressbar(self, func):
49 + return False
50 +
51 +
52 + def __init__(self, bin_command, bin_pkg):
53 + self.options = None
54 + self.settings = None
55 + self.logger = None
56 + self.repo = None
57 + self.xterm_titles = None
58 + self.spawn_kwargs = None
59 + self.bin_command = portage.process.find_binary(bin_command)
60 +
61 + self.has_bin = True
62 + if bin_command and self.bin_command is None:
63 + msg = ["Command not found: %s" % bin_command,
64 + "Type \"emerge %s\" to enable %s support." % (bin_pkg, bin_command)]
65 + for l in msg:
66 + writemsg_level("!!! %s\n" % l,
67 + level=self.logger.ERROR, noiselevel=-1)
68 + self.has_bin = False
69 +
70 +
71 + def _kwargs(self, kwargs):
72 + '''Sets internal variables from kwargs'''
73 + self.options = kwargs.get('options', {})
74 + self.settings = self.options.get('settings', None)
75 + self.logger = self.options.get('logger', None)
76 + self.repo = self.options.get('repo', None)
77 + self.xterm_titles = self.options.get('xterm_titles', False)
78 + self.spawn_kwargs = self.options.get('spawn_kwargs', None)
79 +
80 +
81 + def exists(self, **kwargs):
82 + '''Tests whether the repo actually exists'''
83 + if kwargs:
84 + self._kwargs(kwargs)
85 + elif not self.repo:
86 + return False
87 +
88 +
89 + if not os.path.exists(self.repo.location):
90 + return False
91 + return True
92 +
93 +
94 + def sync(self, **kwargs):
95 + '''Sync the repository'''
96 + if kwargs:
97 + self._kwargs(kwargs)
98 +
99 + if not self.has_bin:
100 + return (1, False)
101 +
102 + if not self.exists():
103 + return self.new()
104 + return self._sync()
105 +
106 +
107 + def new(self, **kwargs):
108 + '''Do the initial download and install of the repository'''
109 + pass
110 +
111 + def _sync(self):
112 + '''Update existing repository
113 + '''
114 + pass
115 +
116 + def post_sync(self, portdb, location, emerge_config):
117 + '''repo.sync_type == "Blank":
118 + # NOTE: Do this after reloading the config, in case
119 + # it did not exist prior to sync, so that the config
120 + # and portdb properly account for its existence.
121 + '''
122 + pass