[projects/git-slug: 16/170] Ported to python 3.x

glen glen at pld-linux.org
Mon Sep 21 21:40:09 CEST 2015


commit 9ff4f73163af7177c68beb21e053c0deef250ebf
Author: Artur Frysiak <wiget at pld-linux.org>
Date:   Wed Sep 14 10:23:37 2011 +0200

    Ported to python 3.x

 pldrepo/gitrepo.py  |  4 ++--
 pldrepo/refsdata.py |  6 ++++--
 post-receive        |  4 ++--
 setup.py            |  3 ++-
 slug.py             | 22 +++++++++++-----------
 5 files changed, 21 insertions(+), 18 deletions(-)
---
diff --git a/pldrepo/gitrepo.py b/pldrepo/gitrepo.py
index e1f0ae0..f552b44 100644
--- a/pldrepo/gitrepo.py
+++ b/pldrepo/gitrepo.py
@@ -1,4 +1,4 @@
-from gitconst import *
+from .gitconst import *
 
 import os
 from subprocess import PIPE
@@ -40,7 +40,7 @@ class GitRepo:
     def configvalue(self, option):
         clist = ['config', '-z', option]
         try:
-            return self.commandexc(clist)[0]
+            return self.commandexc(clist)[0].decode("utf-8")
         except GitRepoError:
             return None
 
diff --git a/pldrepo/refsdata.py b/pldrepo/refsdata.py
index e27b30d..237b0a5 100644
--- a/pldrepo/refsdata.py
+++ b/pldrepo/refsdata.py
@@ -2,8 +2,8 @@
 import collections
 import fnmatch
 import os
-from gitconst import EMPTYSHA1, REFFILE, REFREPO, GITSERVER
-from gitrepo import GitRepo
+from .gitconst import EMPTYSHA1, REFFILE, REFREPO, GITSERVER
+from .gitrepo import GitRepo
 
 
 class RemoteRefsError(Exception):
@@ -14,6 +14,8 @@ class RemoteRefsData:
         self.heads = collections.defaultdict(lambda: collections.defaultdict(lambda: EMPTYSHA1))
         pattern = os.path.join('refs/heads', pattern)
         for line in stream.readlines():
+            if isinstance(line, bytes):
+                line = line.decode("utf-8")
             (sha1, ref, repo) = line.split()
             if fnmatch.fnmatchcase(ref, pattern) and fnmatch.fnmatchcase(repo, dirpattern):
                 self.heads[repo][ref] = sha1
diff --git a/post-receive b/post-receive
index d203644..6e26437 100755
--- a/post-receive
+++ b/post-receive
@@ -1,4 +1,4 @@
-#!/usr/bin/python -u
+#!/usr/bin/python3 -u
 
 import fcntl
 import os
@@ -19,7 +19,7 @@ else:
 
 with open(os.path.join(os.getenv('HOME'), REFREPO, REFFILE), 'r+') as headfile:
     fcntl.lockf(headfile, fcntl.LOCK_EX)
-    print 'Lock obtained'
+    print('Lock obtained')
     refs = RemoteRefsData(headfile, '*')
     refs.put(gitrepo, data)
     headfile.seek(0)
diff --git a/setup.py b/setup.py
index 007ee40..efad648 100644
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,4 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 from distutils.core import setup
 
@@ -8,6 +8,7 @@ setup(name='pldrepo',
       author='Kacper Kornet',
       author_email='draenog at pld-linux.org',
       url='https://github.com/draenog/slug',
+      classifiers=['Programming Language :: Python :: 3'],
       packages=['pldrepo'],
       scripts=['slug.py']
      )
diff --git a/slug.py b/slug.py
index ee9da41..0bae605 100755
--- a/slug.py
+++ b/slug.py
@@ -1,11 +1,11 @@
-#!/usr/bin/python
+#!/usr/bin/python3
 
 import glob
 import sys
 import os
 import shutil
 import subprocess
-import Queue
+import queue
 import threading
 
 import argparse
@@ -29,7 +29,7 @@ class ThreadFetch(threading.Thread):
             (package, ref2fetch) = self.queue.get()
             gitrepo = GitRepo(os.path.join(self.packagesdir, package))
             (stdout, stderr) = gitrepo.fetch(ref2fetch, self.depth)
-            print '------', package, '------\n' + stderr
+            print('------', package, '------\n' + stderr)
             self.queue.task_done()
 
 def get_user():
@@ -49,7 +49,7 @@ def initpackage(name, options):
 
 def createpackage(name, options):
     if not options.user:
-        print >> sys.stderr, 'user not defined'
+        print('user not defined', file=sys.stderr)
         sys.exit(1)
     if subprocess.Popen(['ssh', options.user+'@'+GITSERVER, 'create', name]).wait():
         sys.exit(1)
@@ -60,7 +60,7 @@ def create_packages(options):
         createpackage(package, options)
 
 def fetch_packages(options):
-    fetch_queue = Queue.Queue()
+    fetch_queue = queue.Queue()
     for i in range(options.j):
         t = ThreadFetch(fetch_queue, options.packagesdir, options.depth)
         t.setDaemon(True)
@@ -71,14 +71,14 @@ def fetch_packages(options):
     try:
         refs = GitRemoteRefsData(options.remoterefs, options.branch, options.dirpattern)
     except GitRepoError as e:
-        print >> sys.stderr, 'Problem with repository {}: {}'.format(options.remoterefs,e)
+        print('Problem with repository {}: {}'.format(options.remoterefs,e), file=sys.stderr)
         sys.exit(1)
     except RemoteRefsError as e:
-        print >> sys.stderr, 'Problem with file {} in repository {}'.format(*e)
+        print('Problem with file {} in repository {}'.format(*e), file=sys.stderr)
         sys.exit(1)
 
 
-    print 'Read remotes data'
+    print('Read remotes data')
     for dir in sorted(refs.heads):
         gitdir = os.path.join(options.packagesdir, dir, '.git')
         if not os.path.isdir(gitdir):
@@ -101,15 +101,15 @@ def fetch_packages(options):
         try:
             refs = GitRemoteRefsData(options.remoterefs, '*')
         except GitRepoError as e:
-            print >> sys.stderr, 'Problem with repository {}: {}'.format(options.remoterefs,e)
+            print('Problem with repository {}: {}'.format(options.remoterefs,e), file=sys.stderr)
             sys.exit(1)
         except RemoteRefsError as e:
-            print >> sys.stderr, 'Problem with file {} in repository {}'.format(*e)
+            print('Problem with file {} in repository {}'.format(*e), file=sys.stderr)
             sys.exit(1)
         for fulldir in glob.iglob(os.path.join(options.packagesdir,options.dirpattern)):
             dir = os.path.basename(fulldir)
             if len(refs.heads[dir]) == 0 and os.path.isdir(os.path.join(fulldir, '.git')):
-                print 'Removing', fulldir
+                print('Removing', fulldir)
                 shutil.rmtree(fulldir)
 
 
================================================================

---- gitweb:

http://git.pld-linux.org/gitweb.cgi/projects/git-slug.git/commitdiff/4ed64f73960519a2f4fd04c42950b2c96ae795c5



More information about the pld-cvs-commit mailing list