public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Chris Reffett" <creffett@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:plugin-sync commit in: pym/portage/sync/modules/git/
Date: Sat,  8 Feb 2014 04:03:12 +0000 (UTC)	[thread overview]
Message-ID: <1391832138.28bb54f8d527979ad56375b73f70a43a28429755.creffett@gentoo> (raw)

commit:     28bb54f8d527979ad56375b73f70a43a28429755
Author:     Chris Reffett <creffett <AT> gentoo <DOT> org>
AuthorDate: Sat Feb  8 04:02:18 2014 +0000
Commit:     Chris Reffett <creffett <AT> gentoo <DOT> org>
CommitDate: Sat Feb  8 04:02:18 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=28bb54f8

Add exists() and new() functions, make sync() private and add new sync
pointing either to new() or _sync().

---
 pym/portage/sync/modules/git/git.py | 109 +++++++++++++++++++++++++-----------
 1 file changed, 75 insertions(+), 34 deletions(-)

diff --git a/pym/portage/sync/modules/git/git.py b/pym/portage/sync/modules/git/git.py
index 0c75dc7..833d7d9 100644
--- a/pym/portage/sync/modules/git/git.py
+++ b/pym/portage/sync/modules/git/git.py
@@ -51,7 +51,71 @@ class GitSync(object):
 		self.repo = self.options.get('repo', None)
 		self.xterm_titles = self.options.get('xterm_titles', False)
 
+
+	def exists(self, **kwargs):
+                '''Tests whether the repo actually exists'''
+		if kwargs:
+			self._kwargs(kwargs)
+		elif not self.repo:
+			return False
+		spawn_kwargs = self.options.get('spawn_kwargs', None)
+
+		if not os.path.exists(self.repo.location):
+			return False
+		exitcode = portage.process.spawn_bash("cd %s ; git rev-parse" %\
+			(portage._shell_quote(self.repo.location),),
+			**portage._native_kwargs(spawn_kwargs))
+		if exitcode == 128:
+			return False
+		return True
+
+
 	def sync(self, **kwargs):
+		'''Sync/Clone the repository'''
+		if kwargs:
+			self._kwargs(kwargs)
+
+		if not self.has_git:
+			return (1, False)
+
+		if not self.exists():
+			return self.new()
+		return self._sync()
+
+
+	def new(self, **kwargs):
+		'''Do the initial clone of the repository'''
+		if kwargs:
+			self._kwargs(kwargs)
+                emerge_config = self.options.get('emerge_config', None)
+		spawn_kwargs = self.options.get('spawn_kwargs', None)
+		portdb = self.options.get('portdb', None)
+		try:
+			if not os.path.exists(self.repo.location):
+				os.makedirs(self.repo.location)
+				self.logger(self.xterm_titles,
+					'Created new directory %s' % self.repo.location)
+		except IOError:
+			return (1, False)
+		msg = ">>> Cloning git repository from upstream into %s..." % self.repo.location
+		self.logger(self.xterm_titles, msg)
+		writemsg_level(msg + "\n")
+		exitcode = portage.process.spawn_bash("cd %s ; git clone %s ." % \
+			(portage._shell_quote(self.repo.location),
+			portage._shell_quote(self.repo.sync_uri)),
+			**portage._native_kwargs(spawn_kwargs))
+		if exitcode != os.EX_OK:
+			msg = "!!! git clone error in %s" % self.repo.location
+			self.logger(self.xterm_titles, msg)
+			writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1)
+		return (exitcode, False)
+		msg = ">>> Git clone successful"
+		self.logger(self.xterm_titles, msg)
+		writemsg_level(msg + "\n")
+		return self.post_sync(portdb, self.repo.location, emerge_config)
+
+
+	def _sync(self, **kwargs):
 		''' Update existing git repository, and ignore the syncuri. We are
 		going to trust the user and assume that the user is in the branch
 		that he/she wants updated. We'll let the user manage branches with
@@ -59,44 +123,22 @@ class GitSync(object):
 		'''
 		if kwargs:
 			self._kwargs(kwargs)
-			emerge_config = self.options.get('emerge_config', None)
-			spawn_kwargs = self.options.get('spawn_kwargs', None)
-			portdb = self.options.get('portdb', None)
-
-		if not self.has_git:
-			return self.repo.location, 1, False
+		emerge_config = self.options.get('emerge_config', None)
+		spawn_kwargs = self.options.get('spawn_kwargs', None)
+		portdb = self.options.get('portdb', None)
 
-		# Test if the directory is a valid git repo, and run
-		# git clone if not
-		exitcode = portage.process.spawn_bash("cd %s ; git rev-parse" %\
+		msg = ">>> Starting git pull in %s..." % self.repo.location
+		self.logger(self.xterm_titles, msg)
+		writemsg_level(msg + "\n")
+		exitcode = portage.process.spawn_bash("cd %s ; git pull" % \
 			(portage._shell_quote(self.repo.location),),
 			**portage._native_kwargs(spawn_kwargs))
-		if exitcode == 128:
-			msg = "!!! Git repo does not already exist, cloning from upstream..."
+		if exitcode != os.EX_OK:
+			msg = "!!! git pull error in %s" % self.repo.location
 			self.logger(self.xterm_titles, msg)
-			writemsg_level(msg + "\n")
-			exitcode = portage.process.spawn_bash("cd %s ; git clone %s ." % \
-				(portage._shell_quote(self.repo.location),
-				portage._shell_quote(self.repo.sync_uri)),
-				**portage._native_kwargs(spawn_kwargs))
-			if exitcode != os.EX_OK:
-				msg = "!!! git clone error in %s." % self.repo.location
-				self.logger(self.xterm_titles, msg)
-				writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1)
+			writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1)
 			return (exitcode, False)
-		else:
-			msg = ">>> Starting git pull in %s..." % self.repo.location
-			self.logger(self.xterm_titles, msg )
-			writemsg_level(msg + "\n")
-			exitcode = portage.process.spawn_bash("cd %s ; git pull" % \
-				(portage._shell_quote(self.repo.location),),
-			**portage._native_kwargs(spawn_kwargs))
-			if exitcode != os.EX_OK:
-				msg = "!!! git pull error in %s." % self.repo.location
-				self.logger(self.xterm_titles, msg)
-				writemsg_level(msg + "\n", level=logging.ERROR, noiselevel=-1)
-				return (exitcode, False)
-		msg = ">>> Git pull in %s successful" % self.repo.location
+		msg = ">>> Git pull successful" % self.repo.location
 		self.logger(self.xterm_titles, msg)
 		writemsg_level(msg + "\n")
 		return self.post_sync(portdb, self.repo.location, emerge_config)
@@ -119,4 +161,3 @@ class GitSync(object):
 		if exitcode == os.EX_OK:
 			updatecache_flg = True
 		return (exitcode, updatecache_flg)
-


             reply	other threads:[~2014-02-08  4:03 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-02-08  4:03 Chris Reffett [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-12-04 20:16 [gentoo-commits] proj/portage:master commit in: pym/portage/sync/modules/git/ Brian Dolbec
2014-12-04 20:04 ` [gentoo-commits] proj/portage:plugin-sync " Brian Dolbec
2014-12-04 20:04 Brian Dolbec
2014-12-04 20:04 Brian Dolbec
2014-12-01 21:50 Michał Górny
2014-12-01 21:50 Michał Górny
2014-12-01 21:50 Michał Górny
2014-10-22 11:02 Zac Medico
2014-10-21  5:05 Zac Medico
2014-10-21  5:05 Zac Medico
2014-10-21  1:49 Zac Medico
2014-10-21  1:15 Zac Medico
2014-09-03 23:36 Brian Dolbec
2014-06-16 22:45 Brian Dolbec
2014-06-16 22:45 Brian Dolbec
2014-06-16 15:46 Brian Dolbec
2014-06-16 15:46 Brian Dolbec
2014-05-02 23:13 Brian Dolbec
2014-05-02 23:13 Brian Dolbec
2014-05-02 23:13 Brian Dolbec
2014-05-02 23:13 Brian Dolbec
2014-04-22  2:36 Brian Dolbec
2014-03-14 16:23 Brian Dolbec
2014-02-19 15:37 Brian Dolbec
2014-02-10  4:07 Chris Reffett
2014-02-08 15:41 Chris Reffett
2014-02-08  4:03 Chris Reffett
2014-02-08  4:03 Chris Reffett

Reply instructions:

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

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

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

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

  git send-email \
    --in-reply-to=1391832138.28bb54f8d527979ad56375b73f70a43a28429755.creffett@gentoo \
    --to=creffett@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

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

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