Permalink
Browse files

Fixes #23; @vadmium’s patches applied.

Signed-off-by: Kwpolska <kwpolska@gmail.com>
  • Loading branch information...
1 parent 2d3197d commit e9e7d2257040bc1fd79e91596d09d429709ed588 @Kwpolska committed Oct 27, 2012
Showing with 246 additions and 409 deletions.
  1. +2 −43 docs/aur.rst
  2. +2 −63 docs/build.rst
  3. +23 −1 docs/conf.py
  4. +2 −1 docs/index.rst
  5. +0 −34 docs/localization.rst
  6. +2 −5 docs/main.rst
  7. +2 −41 docs/pbds.rst
  8. +2 −26 docs/upgrade.rst
  9. +3 −58 docs/utils.rst
  10. +2 −1 docs/wrapper.rst
  11. +18 −2 pkgbuilder/aur.py
  12. +69 −48 pkgbuilder/build.py
  13. +69 −45 pkgbuilder/main.py
  14. +8 −1 pkgbuilder/pbds.py
  15. +34 −34 pkgbuilder/upgrade.py
  16. +8 −4 pkgbuilder/utils.py
  17. +0 −2 requirements.txt
View
45 docs/aur.rst
@@ -7,49 +7,8 @@ aur module (AUR class)
:Date: 2012-10-17
:Version: 2.1.5.5
-.. module:: aur
-
-AUR
-===
-
.. index:: AUR; RPC
.. index:: RPC
.. versionadded:: 2.1.0.0
-.. class:: AUR
-
-This is the class used for calling the AUR API. It defines four methods:
-
-.. method:: request(rtype, arg[, prot])
-.. index:: request
-
-Makes a request and returns data. Valid types of requests are listed on
-the `AUR API's page`_. Currently tested and working ones are:
-
-+---------+-----------------------------------+
-+ name | purpose |
-+=========+===================================+
-| info | get info about `arg` |
-+---------+-----------------------------------+
-| search | search for `arg` in the AUR |
-+---------+-----------------------------------+
-| msearch | show packages maintained by `arg` |
-+---------+-----------------------------------+
-
-multiinfo is implemented in another function, :meth:`multiinfo()`.
-
-.. _`AUR API's page`: http://aur.archlinux.org/rpc.php
-
-.. method:: multiinfo(args[, prot])
-.. index:: multiinfo
-
-Makes a multiinfo request. A multiinfo request can retrieve information
-for multiple packages.
-
-.. method:: jsonreq(rtype, arg[, prot])
-
-Makes a :meth:`request()`, but returns plain JSON data. Valid values of
-`rtype` are listed in :meth:`request()`'s documentation.
-
-.. method:: jsonmultiinfo(args[, prot])
-
-Makes a :meth:`multiinfo()` request, but returns plain JSON data.
+.. automodule:: pkgbuilder.aur
+ :members:
View
65 docs/build.rst
@@ -7,68 +7,7 @@ build module (Build class)
:Date: 2012-10-17
:Version: 2.1.5.5
-.. module:: build
-
-Build
-=====
-
.. index:: Build
.. versionadded:: 2.1.0.0
-.. class:: Build
-
-This is the class for building packages. It defines two base methods and
-four additional ones.
-
-.. method:: auto_build(pkgname[, performdepcheck][, pkginstall])
-.. index:: makepkg; build
-
-This is a function that handles building packages automatically. This is
-the recommended way of building packages through PKGBUILDer.
-
-.. note::
-
- This function returns a list of packages to install with pacman -U. Please
- take care of it. Running PKGBUILDer/PBWrapper standalone or .main.main()
- will do that.
-
-.. method:: build_runner(pkgname[, performdepcheck][, pkginstall])
-.. index:: makepkg; build; validate
-
-This is the function running building. It is not supposed to be used
-standalone, because it is embedded by :meth:`auto_build()`.
-
-.. note::
-
- Data returned by this function may not be helpful. Using :meth:`auto_build()`
- eliminates this problem.
-
-.. method:: validate(pkgnames)
-
-Check if packages were installed.
-
-.. method:: install(pkgpaths[, sigpaths])
-
-Install packages through ``pacman -U``.
-
-.. method:: download(urlpath, filename[, prot])
-
-Downloads an AUR tarball. Data normally provided by :meth:`build_runner()`.
-
-.. method:: extract(filename)
-
-Extracts an AUR tarball. Data normally provided by :meth:`build_runner()`.
-
-.. method:: prepare_deps(pkgbuild)
-.. index:: depcheck, dependency
-
-.. versionchanged:: 2.1.3.7
-
-Gets (make)depends from a PKGBUILD and returns them.
-
-..note:: due to a radical change of the algorithm, please provide the **absolute** path to the PKGBUILD (``os.path.abspath``). Handles are not supported. Strings are not supported since 2.1.4.0.
-
-.. method:: depcheck(depends)
-.. index:: depcheck, dependency
-
-Performs a dependency check. Data normally provided by
-:meth:`prepare_deps()`.
+.. automodule:: pkgbuilder.build
+ :members:
View
24 docs/conf.py
@@ -16,7 +16,7 @@
# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.
-#sys.path.insert(0, os.path.abspath('.'))
+sys.path.insert(0, os.path.abspath('..'))
# -- General configuration -----------------------------------------------------
@@ -231,3 +231,25 @@
# How to display URL addresses: 'footnote', 'no', or 'inline'.
#texinfo_show_urls = 'footnote'
+
+class Mock(object):
+ def __init__(self, *args, **kwargs):
+ pass
+
+ def __call__(self, *args, **kwargs):
+ return Mock()
+
+ @classmethod
+ def __getattr__(cls, name):
+ if name in ('__file__', '__path__'):
+ return '/dev/null'
+ elif name[0] == name[0].upper():
+ mockType = type(name, (), {})
+ mockType.__module__ = __name__
+ return mockType
+ else:
+ return Mock()
+
+MOCK_MODULES = ['pyalpm', 'pycman']
+for mod_name in MOCK_MODULES:
+ sys.modules[mod_name] = Mock()
View
3 docs/index.rst
@@ -6,7 +6,7 @@ PKGBUILDer. An AUR helper (and library) in Python 3.
This documentation is compatible with version |release| of
PKGBUILDer.
The current version on your system can be checked by running
- `pkgbuilder -v`.
+ ``pkgbuilder -v``.
Most of the documentation is likely compatible with previous
releases of the |version| series.
@@ -43,6 +43,7 @@ Table of Contents
upgrade
utils
wrapper
+ sample-scripts
CONTRIBUTING
LICENSE
CHANGELOG
View
34 docs/localization.rst
@@ -1,34 +0,0 @@
-==============================
-Appendix A. Localization Guide
-==============================
-:Author: Kwpolska
-:Copyright: © 2011-2012, Kwpolska.
-:License: BSD (see /LICENSE or :doc:`Appendix B <LICENSE>`.)
-:Date: 2012-10-17
-:Version: 2.1.5.5
-
-.. index:: locale
-
-Hello! It looks like you want to localize PKGBUILDer. Great! Doing so is not
-so hard, and requires just a few minutes.
-
-1. Fork the repo on GitHub and clone your fork locally.
-2. Run ``mkdir -p locale/[CODE]/LC_MESSAGES`` in your terminal, replacing
- ``[CODE]`` by your language code, as in /usr/share/locale.
-3. Copy the ``/messages.pot`` file to
- ``locale/[CODE]/LC_MESSAGES/pkgbuilder.po``.
-4. Do your work. The comments will inform you where this string is, and the
- ones starting with 'TRANSLATORS:' are for you to read and make use of.
- Other comments come from my code and you shouldn’t care about them. And
- if it is directed for translators, let me know. The Poedit_ app may be
- of help. Please take care of the headers at the top of the file (with a
- text editor, do not use poedit for that!) and modify them. The
- Last-Translator, Language-Team and Language are important, the others are
- auto-generated anyways.
-5. Commit (with the ``-s/--signoff`` flag!) and hit *Pull Request* on GitHub.
-6. Your translation will be added in the next release, or, if a release isn’t
- planned in the near future, a new release will be made. Your addition will
- be appreciated. Note that I cannot translate new strings, and, as a result,
- I might ask you for additions in the future.
-
-.. _Poedit: http://www.poedit.net/
View
7 docs/main.rst
@@ -9,8 +9,5 @@ main module
.. index:: main
.. versionadded:: 2.1.3.0
-.. module:: main
-
-main()
-======
-The main routine. Please do not use it unless you have a good reason.
+.. automodule:: pkgbuilder.main
+ :members:
View
43 docs/pbds.rst
@@ -49,8 +49,6 @@ information (not including information humans should not touch and care about):
+-----------+-----------------------------------------------+---------------+
| hassudo | If ``sudo`` is present (see :meth:`sudo`) | (bool) |
+-----------+-----------------------------------------------+---------------+
-| uid | User UID | (int) |
-+-----------+-----------------------------------------------+---------------+
.. [colors] Code below.
@@ -86,42 +84,5 @@ information (not including information humans should not touch and care about):
.. [conf] In order: ``~/.config/``, ``~/.config/kwpolska``,
``~/.config/kwpolska/pkgbuilder`` (may differ depending on system config)
-It also has a few methods:
-
-.. method:: sudo(\*args)
-
-.. versionadded:: 2.1.4.8
-
-Run as root. ``sudo`` if present, ``su -c`` otherwise, nothing if
-already running as root.
-
-.. note:: Accepts only one command. `shell=False`, for safety.
-
-``*args`` is catching all the arguments. However, in order to make sure that
-nothing breaks, it checks if the element is a list or a tuple. If yes, it is
-appended to the argument list (Python’s ``+`` operator); if not, it is split on
-spaces (``.split(' ')``) and appended to the argument list. Finally, the list
-is passed to ``subprocess.call``.
-
-.. method:: debugmode(nochange)
-
-.. versionadded:: 2.1.4.0
-
-Print all the logged messages to stderr.
-
-.. method:: colorson()
-
-Turns colors on.
-
-.. method:: colorsoff()
-
-Turns colors off.
-
-.. method:: fancy_msg(msg)
-.. method:: fancy_msg2(msg)
-.. method:: fancy_warning(msg)
-.. method:: fancy_warning2(msg)
-.. method:: fancy_error(msg)
-.. method:: fancy_error2(msg)
-
-``makepkg``’s message functions with PKGBUILDer’s own additions. Use for displaying messages.
+.. automodule:: pkgbuilder.pbds
+ :members:
View
28 docs/upgrade.rst
@@ -8,32 +8,8 @@ upgrade module (Upgrade class)
:Date: 2012-10-17
:Version: 2.1.5.5
-.. module:: upgrade
-
-Upgrade
-=======
-
.. index:: Upgrade
-.. index:: Update
.. index:: Syu
.. versionadded:: 2.1.0.0
-.. class:: Upgrade
-
-This is the class for upgrading the installed packages. It defines one base
-method and two additional ones.
-
-.. method:: auto_upgrade([downgrade][, vcsup])
-.. index:: upgrade
-
-Upgrades packages. Simillar to :meth:`Build.auto_build()`.
-
-.. method:: gather_foreign_packages()
-.. index:: foreign packages
-
-Gathers a list of all foreign packages.
-
-.. method:: list_upgradable(pkglist[, vcsup])
-
-.. versionchanged:: 2.1.4.4
-
-Compares package versions and returns upgradable and downgradable ones.
+.. automodule:: pkgbuilder.upgrade
+ :members:
View
61 docs/utils.rst
@@ -8,61 +8,6 @@ utils module (Utils class)
:Date: 2012-10-17
:Version: 2.1.5.5
-.. module:: utils
-
-Utils
-=====
-
-.. index:: Utils; Utilities
-.. versionadded:: 2.1.0.0
-.. class:: Utils
-
-Common global utilities. Provides useful data. It defines three methods:
-
-
-.. method:: info(pkgname)
-.. index:: info
-
-.. versionchanged:: 2.1.4.8
-
-Returns informations about packages. Almost equivalent to
-:meth:`AUR.multiinfo(pkgnames)`, but returns ``[]`` if no packages were found.
-
-.. method:: search(pkgname)
-.. index:: search
-
-Searches for AUR packages and returns them as a list. Almost equivalent
-to :meth:`AUR.request('search', pkgname)`, but returns ``[]`` if no
-packages were found.
-
-.. method:: print_package_search(pkg[, use_categories][, cachemode][, prefix][, prefixp])
-.. index:: print
-
-Outputs/returns a package representation similar to ``pacman -Ss``. Format::
-
- category/name version (count votes) [installed: version] [out of date]
- description
-
-(``category`` becomes ``aur`` when running with ``-S``. Installed version
-displayed only if it is different than the one in the AUR.)
-
-.. method:: print_package_info(pkg[, cachemode][, force_utc])
-.. index:: print
-
-
-.. versionchanged:: 2.1.4.8
-
-Outputs/returns a package representation similar to ``pacman -Si``. Format (with en/C locale)::
-
- Repository : aur
- Category : package category
- Name : package name
- Version : package version
- URL : package URL (from PKGBUILD)
- Licenses : package license
- Votes : votes count
- Out of Date : out of date (yes/no), red if yes
- Maintainer : package maintainer
- First Submitted: date of package’s first submission
- Last Updated : date of package’s last update
- Description : package description
+.. index:: Utils
+.. automodule:: pkgbuilder.utils
+ :members:
View
3 docs/wrapper.rst
@@ -11,7 +11,8 @@ PBWrapper
.. index:: wrapper
.. index:: PBWrapper
.. versionadded:: 2.1.4.0
-.. module:: wrapper
+.. automodule:: pkgbuilder.wrapper
+ :members:
This is the wrapper for pacman and PKGBUILDer, ``bin/pb``. It is a complete
mess, but at least it works. All the arguments it gets are passed to pacman,
View
20 pkgbuilder/aur.py
@@ -8,7 +8,7 @@
# Names convention: pkg = a package object, pkgname = a package name.
"""
- pkgbuilder.AUR
+ pkgbuilder.aur
~~~~~~~~~~~~~~
A class for calling the AUR API.
@@ -23,7 +23,23 @@
### AUR AUR RPC calls ###
class AUR:
- """A class for calling the AUR API."""
+ """A class for calling the AUR API.
+
+ Valid request types for :meth:`request()` (and
+ :meth:`jsonrequest()`):
+
+ +---------+-----------------------------------+
+ + name | purpose |
+ +=========+===================================+
+ | info | get info about `arg` |
+ +---------+-----------------------------------+
+ | search | search for `arg` in the AUR |
+ +---------+-----------------------------------+
+ | msearch | show packages maintained by `arg` |
+ +---------+-----------------------------------+
+
+ multiinfo is implemented in another function, :meth:`multiinfo()`.
+ """
rpc = '{}://aur.archlinux.org/rpc.php?type={}&arg={}'
mrpc = '{}://aur.archlinux.org/rpc.php?type=multiinfo{}'
View
117 pkgbuilder/build.py
@@ -8,7 +8,7 @@
# Names convention: pkg = a package object, pkgname = a package name.
"""
- pkgbuilder.Build
+ pkgbuilder.build
~~~~~~~~~~~~~~~~
Functions for building packages.
@@ -18,6 +18,7 @@
from . import DS, _, PBError
from .utils import Utils
+import sys
import os
import pyalpm
import pycman
@@ -102,23 +103,22 @@ def auto_build(self, pkgname, performdepcheck=True,
elif build_result[0] == 72789: # PBSUX.
raise PBError(_('PKGBUILDer had a problem.'))
exit(1)
- elif build_result[0] == 72737: # PBREQ.
- # TRANSLATORS: do not translate the word 'requests'.
- raise PBError(_('PKGBUILDer (or the requests library) had '
- 'problems with fulfilling an HTTP request.'))
- exit(1)
elif build_result[0] == 72101: # I/O error.
raise PBError(_('There was an input/output error.'))
exit(1)
elif build_result[0] == 72337: # PBDEP.
DS.fancy_warning(_('Building more AUR packages is required.'))
toinstall2 = []
+ sigs2 = []
for pkgname2 in build_result[1]:
- toinstall2 += self.auto_build(pkgname2, performdepcheck,
- pkginstall)
+ (toinstall, sigs) = self.auto_build(pkgname2,
+ performdepcheck,
+ pkginstall)[0]
+ toinstall2 += toinstall
+ sigs2 += sigs
- if toinstall2:
- self.install(toinstall2)
+ if toinstall2 and sigs2:
+ self.install(toinstall2, sigs2)
if DS.validate:
self.validate(build_result[1])
@@ -130,11 +130,7 @@ def auto_build(self, pkgname, performdepcheck=True,
self.auto_build(pkgname, performdepcheck,
pkginstall)
- # Package installation magic. To be parsed later.
- if pkginstall and build_result[0] < 72000:
- return build_result[1]
- else:
- return None
+ return build_result
except PBError as inst:
DS.fancy_error(str(inst))
@@ -173,11 +169,11 @@ def prepare_deps(self, pkgbuild):
# And it takes only 7 lines instead of about 40 in the pyparsing
# implementation.
- pb = subprocess.Popen('source ' + pkgbuild + '; for i in ${depends'
- '[*]}; do echo $i; done; for i in '
- '${makedepends[*]}; do echo $i; done',
- shell=True, stdout=subprocess.PIPE)
- deps = pb.stdout.read()
+ deps = subprocess.check_output('source ' + pkgbuild + '; for i in '
+ '${depends[*]}; do echo $i; done; for '
+ 'i in ${makedepends[*]}; do echo $i; '
+ 'done',
+ shell=True)
deps = deps.decode('utf-8')
deps = deps.split('\n')
@@ -225,30 +221,67 @@ def build_runner(self, pkgname, performdepcheck=True,
unless you re-implement auto_build.
"""
try:
- # exists
+ pkg = None
try:
- pkg = self.utils.info([pkgname])[0]
+ pkgname[9001]
+ pkg = self.utils.info([pkgname])
+ pkg = pkg[0]
+ useabs = False
except IndexError:
+ try:
+ DS.log.info('{} not found in the AUR, checking in '
+ 'ABS'.format(pkgname))
+ pyc = pycman.config.init_with_config('/etc/pacman.conf')
+ syncpkgs = []
+ for j in [i.pkgcache for i in pyc.get_syncdbs()]:
+ syncpkgs.append(j)
+ syncpkgs = functools.reduce(lambda x, y: x + y, syncpkgs)
+ abspkg = pyalpm.find_satisfier(syncpkgs, pkgname)
+ pkg = {'CategoryID': '0', 'Category': abspkg.db.name,
+ 'Name': abspkg.name, 'Version': abspkg.version,
+ 'Description': abspkg.desc, 'OutOfDate': '0',
+ 'NumVotes': 'n/a', 'Arch': abspkg.arch}
+ useabs = True
+ except AttributeError:
+ pass
+
+ if not pkg:
raise PBError(_('Package {} not found.').format(pkgname))
+
pkgname = pkg['Name']
DS.fancy_msg(_('Building {}...').format(pkgname))
self.utils.print_package_search(pkg,
prefix=DS.colors['blue'] +
' ->' + DS.colors['all_off'] +
DS.colors['bold'] + ' ',
prefixp=' -> ')
- print(DS.colors['all_off'], end='')
- filename = pkgname + '.tar.gz'
- # Okay, this package exists, great then. Thanks, user.
-
- DS.fancy_msg(_('Downloading the tarball...'))
- downloadbytes = self.download(pkg['URLPath'], filename)
- kbytes = int(downloadbytes) / 1000
- DS.fancy_msg2(_('{} kB downloaded').format(kbytes))
-
- DS.fancy_msg(_('Extracting...'))
- DS.fancy_msg2(_('{} files extracted').format(self.extract(
- filename)))
+ sys.stdout.write(DS.colors['all_off'])
+ if useabs:
+ DS.fancy_msg(_('Synchronizing the ABS tree...'))
+ rsync = ['rsync', '-mrtv', '--no-motd', '--delete-after',
+ '--no-p', '--no-o', '--no-g', # '--delete-excluded',
+ '--include=/{}'.format(pkg['Category']),
+ '--include=/{}/{}'.format(pkg['Category'],
+ pkg['Name']),
+ '--exclude=/{}/*'.format(pkg['Category']),
+ '--exclude=/*',
+ 'rsync.archlinux.org::abs/{}/'.format(pkg['Arch']),
+ '.']
+ rstatus = subprocess.call(rsync)
+ if rstatus > 0:
+ raise PBError(_('Failed to synchronize the ABS tree.'))
+
+ os.chdir('./{}/'.format(pkg['Category']))
+ else:
+ filename = pkgname + '.tar.gz'
+ DS.fancy_msg(_('Downloading the tarball...'))
+ downloadbytes = self.download(pkg['URLPath'], filename)
+ kbytes = int(downloadbytes) / 1000
+ DS.fancy_msg2(_('{} kB downloaded').format(kbytes))
+
+ DS.fancy_msg(_('Extracting...'))
+ DS.fancy_msg2(_('{} files extracted').format(self.extract(
+ filename)))
os.chdir('./{}/'.format(pkgname))
if performdepcheck:
@@ -280,7 +313,7 @@ def build_runner(self, pkgname, performdepcheck=True,
if DS.uid == 0:
mpparams += ' --asroot'
- mpstatus = subprocess.call('/usr/bin/makepkg -sf' + mpparams,
+ mpstatus = subprocess.call('makepkg -sf' + mpparams,
shell=True)
if pkginstall:
# .pkg.tar.xz FTW, but some people change that.
@@ -314,22 +347,10 @@ def build_runner(self, pkgname, performdepcheck=True,
else:
toinstall = [None, None]
- return [mpstatus, toinstall]
+ return [mpstatus, toinstall, useabs]
except PBError as inst:
DS.fancy_error(str(inst))
return [72789, None]
- except requests.exceptions.ConnectionError as inst:
- DS.fancy_error(str(inst))
- return [72737, None]
- except requests.exceptions.HTTPError as inst:
- DS.fancy_error(str(inst))
- return [72737, None]
- except requests.exceptions.Timeout as inst:
- DS.fancy_error(str(inst))
- return [72737, None]
- except requests.exceptions.TooManyRedirects as inst:
- DS.fancy_error(str(inst))
- return [72737, None]
except IOError as inst:
DS.fancy_error(str(inst))
return [72101, None]
View
114 pkgbuilder/main.py
@@ -8,8 +8,8 @@
# Names convention: pkg = a package object, pkgname = a package name.
"""
- pkgbuilder.main()
- ~~~~~~~~~~~~~~~~
+ pkgbuilder.main
+ ~~~~~~~~~~~~~~~
Main routine of PKGBUILDer.
:Copyright: © 2011-2012, Kwpolska.
@@ -22,7 +22,8 @@
from .upgrade import Upgrade
import argparse
import os
-import subprocess
+import sys
+import requests
### main() The main routine ###
@@ -47,7 +48,7 @@ def main(source='AUTO', quit=True):
argopt = parser.add_argument_group(_('options'))
argopr = parser.add_argument_group(_('operations'))
argopt.add_argument('-c', '--clean', action='store_true',
- default=True, dest='cleanup', help=_('clean up '
+ default=False, dest='cleanup', help=_('clean up '
'work files after build'))
argopt.add_argument('-C', '--nocolors', action='store_false',
default=True, dest='color', help=_('don\'t use '
@@ -61,8 +62,8 @@ def main(source='AUTO', quit=True):
default=False, dest='vcsup', help=_('upgrade '
'all the VCS/date-versioned packages'))
argopt.add_argument('-v', '--novalidation', action='store_false',
- default=True, dest='valid', help=_('don\'t check '
- 'if packages were installed after build'))
+ default=True, dest='validate', help=_('don\'t '
+ 'check if packages were installed after build'))
argopt.add_argument('-w', '--buildonly', action='store_false',
default=True, dest='pkginst', help=_('don\'t '
'install packages after building'))
@@ -88,12 +89,10 @@ def main(source='AUTO', quit=True):
else:
args = parser.parse_args()
- DS.validate = args.valid
- DS.depcheck = args.depcheck
DS.pacman = args.pac
- DS.pkginst = args.pkginst
DS.protocol = args.protocol
DS.cleanup = args.cleanup
+ pkgnames = args.pkgnames
utils = Utils()
build = Build()
upgrade = Upgrade()
@@ -111,18 +110,18 @@ def main(source='AUTO', quit=True):
if args.info:
DS.log.debug('Showing info...')
- utils.print_package_info(utils.info(args.pkgnames))
+ utils.print_package_info(utils.info(pkgnames))
if quit:
exit(0)
if args.search:
- if not args.pkgnames:
+ if not pkgnames:
if quit:
exit(1)
else:
DS.log.debug('Searching...')
- searchstring = '+'.join(args.pkgnames)
+ searchstring = '+'.join(pkgnames)
if len(searchstring) < 2:
# this would be too many entries, but this is an actual API
# limitation and not an idea of yours truly.
@@ -139,7 +138,7 @@ def main(source='AUTO', quit=True):
DS.colors['all_off'] +
DS.colors['bold'] + ' '),
prefixp=' -> ')
- print(DS.colors['all_off'], end='')
+ sys.stdout.write(DS.colors['all_off'])
if quit:
exit(0)
else:
@@ -166,39 +165,64 @@ def main(source='AUTO', quit=True):
os.mkdir(path)
os.chdir(path)
+ if args.upgrade > 0:
+ DS.log.info('Starting upgrade...')
+ dodowngrade = args.upgrade > 1
+ upnames = upgrade.auto_upgrade(dodowngrade, args.vcsup)
+ pkgnames = upnames + pkgnames
+
+ # If we didn't quit, we should build the packages.
+ if pkgnames:
+ if DS.uid == 0:
+ DS.log.warning('Running as root! (UID={})'.format(DS.uid))
+ DS.fancy_warning(_('Running PKGBUILDer as root can break your '
+ 'system!'))
+
+ DS.log.info('Starting build...')
+ toinstall = []
+ sigs = []
+ tovalidate = set(pkgnames)
+
+ for pkgname in pkgnames:
+ DS.log.info('Building {}'.format(pkgname))
+ out = build.auto_build(pkgname, args.depcheck, args.pkginst)
+ if out:
+ toinstall += out[1][0]
+ sigs += out[1][1]
+ if out[2]:
+ tovalidate = tovalidate - set([pkgname])
+
+ if toinstall:
+ build.install(toinstall, sigs)
+
+ if args.validate and tovalidate:
+ build.validate(tovalidate)
+ except requests.exceptions.ConnectionError as inst:
+ DS.fancy_error(str(inst))
+ # TRANSLATORS: do not translate the word 'requests'.
+ DS.fancy_error(_('PKGBUILDer (or the requests library) had '
+ 'problems with fulfilling an HTTP request.'))
+ exit(1)
+ except requests.exceptions.HTTPError as inst:
+ DS.fancy_error(str(inst))
+ # TRANSLATORS: do not translate the word 'requests'.
+ DS.fancy_error(_('PKGBUILDer (or the requests library) had '
+ 'problems with fulfilling an HTTP request.'))
+ exit(1)
+ except requests.exceptions.Timeout as inst:
+ DS.fancy_error(str(inst))
+ # TRANSLATORS: do not translate the word 'requests'.
+ DS.fancy_error(_('PKGBUILDer (or the requests library) had '
+ 'problems with fulfilling an HTTP request.'))
+ exit(1)
+ except requests.exceptions.TooManyRedirects as inst:
+ DS.fancy_error(str(inst))
+ # TRANSLATORS: do not translate the word 'requests'.
+ DS.fancy_error(_('PKGBUILDer (or the requests library) had '
+ 'problems with fulfilling an HTTP request.'))
+ exit(1)
except PBError as inst:
DS.fancy_error(str(inst))
- exit(0)
-
- if args.upgrade > 0:
- DS.log.info('Starting upgrade...')
- dodowngrade = args.upgrade > 1
- upgrade.auto_upgrade(dodowngrade, args.vcsup)
-
- if quit:
- exit(0)
-
- # If we didn't quit, we should build the packages.
- if args.pkgnames:
- if DS.uid == 0:
- DS.log.warning('Running as root! (UID={})'.format(DS.uid))
- DS.fancy_warning(_('Running PKGBUILDer as root can break your '
- 'system!'))
-
- DS.log.info('Starting build...')
- toinstall = []
- sigs = []
- for pkgname in args.pkgnames:
- DS.log.info('Building {}'.format(pkgname))
- out = build.auto_build(pkgname, DS.depcheck, DS.pkginst)
- if out:
- toinstall += out[0]
- sigs += out[1]
-
- if toinstall:
- build.install(toinstall, sigs)
-
- if DS.validate:
- build.validate(args.pkgnames)
+ exit(1)
DS.log.info('Quitting.')
View
9 pkgbuilder/pbds.py
@@ -8,7 +8,7 @@
# Names convention: pkg = a package object, pkgname = a package name.
"""
- pkgbuilder.PBDS
+ pkgbuilder.pbds
~~~~~~~~~~~~~~~
PKGBUILDer Data Storage.
@@ -104,6 +104,13 @@ def sudo(self, *rargs):
already running as root.
.. note:: Accepts only one command. `shell=False`, for safety.
+
+ ``*rargs`` is catching all the arguments. However, in order to make
+ sure that nothing breaks, it checks if the element is a list or a
+ tuple. If yes, it is appended to the argument list (Python’s ``+``
+ operator); if not, it is split on spaces (``.split(' ')``) and
+ appended to the argument list. Finally, the list is passed to
+ ``subprocess.call``.
"""
args = []
for i in rargs:
View
68 pkgbuilder/upgrade.py
@@ -8,20 +8,22 @@
# Names convention: pkg = a package object, pkgname = a package name.
"""
- pkgbuilder.Upgrade
+ pkgbuilder.upgrade
~~~~~~~~~~~~~~~~~~
Tools for performing upgrades of AUR packages.
:Copyright: © 2011-2012, Kwpolska.
:License: BSD (see /LICENSE).
"""
-from . import DS, _, PBError
+from . import DS, _
from .aur import AUR
from .build import Build
import pyalpm
import pycman
import datetime
+import subprocess
+import textwrap
### Upgrade upgrade AUR packages ###
@@ -80,8 +82,8 @@ def list_upgradable(self, pkglist, vcsup=False):
v = i['Version']
try:
- d = datetime.datetime.strptime(v.split('-')[0],
- '%Y%m%d')
+ datetime.datetime.strptime(v.split('-')[0],
+ '%Y%m%d')
datever = True
except:
datever = False
@@ -129,8 +131,8 @@ def auto_upgrade(self, downgrade=False, vcsup=False):
if downlen > 0:
for i in downgradable:
if DS.pacman:
- print(_('{}: local ({}) is newer than aur ({})').format(
- i[0], i[1], i[2]))
+ print(_('{}: local ({}) is newer than aur '
+ '({})').format(i[0], i[1], i[2]))
else:
DS.fancy_warning(_('{}: local ({}) is newer than aur '
'({})').format(i[0], i[1], i[2]))
@@ -153,38 +155,36 @@ def auto_upgrade(self, downgrade=False, vcsup=False):
if upglen > 0:
if DS.pacman:
print()
- print(_('Targets ({}): ').format(upglen), end='')
- print(' '.join(upgstrings))
+ targetstring = _('Targets ({}): ').format(upglen)
+ size = subprocess.check_output(['stty', 'size'])
+ try:
+ termwidth = int(size.split()[1])
+ except IndexError:
+ termwidth = 9001 # Auto-wrap by terminal. A reference to
+ # an old meme and a cheat, too. Sorry.
+
+ nowrap = targetstring + ' '.join(upgstrings)
+ wrapv = textwrap.wrap(nowrap, termwidth)
+ wrap0 = wrapv[0]
+ wraprest = textwrap.wrap(wrapv[1:],
+ termwidth - len(targetstring))
+ # TODO wraprest ' ' -> ' ' -> ' '
+ wraprest = [i.replace(' ', ' ').replace(' ', ' ') for i in wraprest]
+ print(wrap0)
+ print('\n'.join(wraprest))
print()
query = _('Proceed with installation? [Y/n] ')
else:
DS.fancy_msg(_('Targets ({}): ').format(upglen))
DS.fancy_msg2(' '.join(upgstrings))
- query = (DS.colors['green'] + '==>' + DS.colors['all_off'] +
- DS.colors['bold'] + ' ' + _('Proceed with '
- 'installation? [Y/n] ') + DS.colors['all_off'])
+ query = (DS.colors['green'] + '==>' +
+ DS.colors['all_off'] + DS.colors['bold'] + ' ' +
+ _('Proceed with installation? [Y/n] ') +
+ DS.colors['all_off'])
yesno = input(query)
- if yesno.lower().startswith('n'):
- return 0
-
- toinstall = []
- sigs = []
-
- if DS.uid == 0:
- DS.log.warning('Running as root! (UID={})'.format(DS.uid))
- DS.fancy_warning(_('Running PKGBUILDer as root can break '
- 'your system!'))
- for pkgname in upgnames:
- DS.log.info('Building {}'.format(pkgname))
- out = self.build.auto_build(pkgname, DS.depcheck,
- DS.pkginst)
- if out:
- toinstall += out[0]
- sigs += out[1]
-
- if toinstall:
- self.build.install(toinstall, sigs)
-
- if DS.validate:
- self.build.validate(upgnames)
+
+ if yesno.lower().startswith('y'):
+ return upgnames
+ else:
+ return []
View
12 pkgbuilder/utils.py
@@ -8,7 +8,7 @@
# Names convention: pkg = a package object, pkgname = a package name.
"""
- pkgbuilder.Utils
+ pkgbuilder.utils
~~~~~~~~~~~~~~~~
Common global utilities. Provides useful data.
@@ -88,10 +88,14 @@ def print_package_search(self, pkg, use_categories=True,
if pkg['OutOfDate'] == '1':
installed = (installed + ' ' + DS.colors['red'] + _(
'[out of date]') + DS.colors['all_off'])
- if use_categories:
- category = DS.categories[int(pkg['CategoryID'])]
+
+ if pkg['CategoryID'] != '0':
+ if use_categories:
+ category = DS.categories[int(pkg['CategoryID'])]
+ else:
+ category = 'aur'
else:
- category = 'aur'
+ category = pkg['Category'] # ABS build cheat.
descl = textwrap.wrap(pkg['Description'], termwidth - len(prefixp2))
View
2 requirements.txt
@@ -1,3 +1 @@
-pyparsing
-pyalpm>=0.5.0
requests

0 comments on commit e9e7d22

Please sign in to comment.