Git Repositories

Setup.py
authorCyrille Pontvieux <jrd@enialis.net>
Sun, 8 Jun 2014 13:51:55 +0000 (15:51 +0200)
committerCyrille Pontvieux <jrd@enialis.net>
Sun, 8 Jun 2014 21:06:01 +0000 (23:06 +0200)
23 files changed:
.gitignore
README.rst [moved from README.md with 100% similarity]
bootsetup/__init__.py [moved from src/lib/__init__.py with 62% similarity]
bootsetup/bootsetup.glade [moved from src/resources/bootsetup.glade with 100% similarity, mode: 0644]
bootsetup/bootsetup.py [moved from src/bootsetup.py with 87% similarity]
bootsetup/bootsetup_curses.py [moved from src/lib/bootsetup_curses.py with 97% similarity]
bootsetup/bootsetup_gtk.py [moved from src/lib/bootsetup_gtk.py with 96% similarity]
bootsetup/config.py [moved from src/lib/config.py with 100% similarity]
bootsetup/gathercurses.py [moved from src/lib/gathercurses.py with 99% similarity]
bootsetup/gathergui.py [moved from src/lib/gathergui.py with 99% similarity]
bootsetup/grub2.py [moved from src/lib/grub2.py with 100% similarity]
bootsetup/lilo.py [moved from src/lib/lilo.py with 99% similarity]
bootsetup/resources/bootsetup.png [moved from src/resources/bootsetup.png with 100% similarity]
make [new file with mode: 0755]
resources/bootsetup.desktop.in [moved from data/bootsetup.desktop.in with 100% similarity]
resources/icons/bootsetup-128.png [moved from data/icons/bootsetup-128.png with 100% similarity, mode: 0644]
resources/icons/bootsetup-24.png [moved from data/icons/bootsetup-24.png with 100% similarity, mode: 0644]
resources/icons/bootsetup-64.png [moved from data/icons/bootsetup-64.png with 100% similarity, mode: 0644]
resources/icons/bootsetup.svg [moved from data/icons/bootsetup.svg with 100% similarity, mode: 0644]
resources/po/bootsetup.pot [moved from data/po/bootsetup.pot with 100% similarity]
resources/po/fr.po [moved from data/po/fr.po with 100% similarity]
setup.cfg [new file with mode: 0644]
setup.py [new file with mode: 0755]

index 621374a..f30c9a5 100644 (file)
@@ -6,5 +6,6 @@
 *.dep
 *.sug
 *.con
-data/locale
 build
+dist
+*.egg-info
similarity index 100%
rename from README.md
rename to README.rst
similarity index 62%
rename from src/lib/__init__.py
rename to bootsetup/__init__.py
index 6d9ce8f..f021fe2 100644 (file)
@@ -6,5 +6,4 @@ BootSetup helps installing LiLo or Grub2 on your computer.
 """
 from __future__ import unicode_literals, print_function, division, absolute_import
 
-__copyright__ = 'Copyright 2013-2014, Salix OS'
-__license__ = 'GPL2+'
+from .bootsetup import __app__, __copyright__, __author__, __credits__, __maintainer__, __email__, __license__, __version__  # noqa
old mode 100755 (executable)
new mode 100644 (file)
similarity index 100%
rename from src/resources/bootsetup.glade
rename to bootsetup/bootsetup.glade
similarity index 87%
rename from src/bootsetup.py
rename to bootsetup/bootsetup.py
index 8a31ffb..8de7649 100755 (executable)
@@ -9,11 +9,11 @@ from __future__ import unicode_literals, print_function, division, absolute_impo
 
 __app__ = 'bootsetup'
 __copyright__ = 'Copyright 2013-2014, Salix OS'
-__author__ = 'Cyrille Pontvieux <jrd~at~enialis~dot~net> and Pierrick Le Brun <akuna~at~salixos~dot~org>'
+__author__ = 'Cyrille Pontvieux <jrd@enialis~dot~net> and Pierrick Le Brun <akuna@salixos~dot~org>'
 __credits__ = ['Cyrille Pontvieux', 'Pierrick Le Brun']
 __maintainer__ = 'Cyrille Pontvieux'
-__email__ = 'jrd~at~enialis~dot~net'
-__license__ = 'GPL2+'
+__email__ = 'jrd@enialis~dot~net'
+__license__ = 'GPLv2+'
 __version__ = '0.1'
 
 import abc
@@ -57,7 +57,7 @@ class BootSetup:
     """
     Displays an error message.
     """
-    return result_error
+    raise NotImplementedError()
 
 
 def usage():
@@ -92,7 +92,7 @@ def die(s, exit=1):
     sys.exit(exit)
 
 
-if __name__ == '__main__':
+def main(args=sys.argv[1:]):
   if os.path.dirname(__file__):
     os.chdir(os.path.dirname(__file__))
   is_graphic = bool(os.environ.get('DISPLAY'))
@@ -102,7 +102,7 @@ if __name__ == '__main__':
   target_partition = None
   locale_dir = '/usr/share/locale'
   gettext.install(__app__, locale_dir, True)
-  for arg in sys.argv[1:]:  # argv[0] = own name
+  for arg in args:
     if arg:
       if arg == '--help':
         usage()
@@ -135,9 +135,12 @@ if __name__ == '__main__':
   if target_partition and not os.path.exists(target_partition):
     die(_("Partition {0} not found.").format(target_partition))
   if is_graphic:
-    from lib.bootsetup_gtk import *
-    bootsetup = BootSetupGtk(__app__, __version__, locale_dir, bootloader, target_partition, is_test, use_test_data)
+    from .bootsetup_gtk import BootSetupGtk as BootSetupImpl
   else:
-    from lib.bootsetup_curses import *
-    bootsetup = BootSetupCurses(__app__, __version__, locale_dir, bootloader, target_partition, is_test, use_test_data)
+    from .bootsetup_curses import BootSetupCurses as BootSetupImpl
+  bootsetup = BootSetupImpl(__app__, __version__, locale_dir, bootloader, target_partition, is_test, use_test_data)
   bootsetup.run_setup()
+
+
+if __name__ == '__main__':
+  main()
similarity index 97%
rename from src/lib/bootsetup_curses.py
rename to bootsetup/bootsetup_curses.py
index 51c36a9..4919933 100644 (file)
@@ -13,8 +13,8 @@ import os
 import sys
 import gettext  # noqa
 import urwidm
-from gathercurses import *
-from bootsetup import *
+from .bootsetup import *
+from .gathercurses import *
 
 
 class BootSetupCurses(BootSetup):
similarity index 96%
rename from src/lib/bootsetup_gtk.py
rename to bootsetup/bootsetup_gtk.py
index 7a8d25e..6cd02e5 100644 (file)
@@ -14,8 +14,8 @@ import sys
 import gettext  # noqa
 import gtk
 import gtk.glade
-from bootsetup import *
-from gathergui import *
+from .bootsetup import *
+from .gathergui import *
 
 
 class BootSetupGtk(BootSetup):
similarity index 100%
rename from src/lib/config.py
rename to bootsetup/config.py
similarity index 99%
rename from src/lib/gathercurses.py
rename to bootsetup/gathercurses.py
index e9bebd0..d102f6b 100644 (file)
@@ -13,9 +13,10 @@ import gettext  # noqa
 import urwidm
 import re
 import libsalt as slt
-from .config import *
-from .lilo import *
-from .grub2 import *
+from .config import Config
+from .lilo import Lilo
+from .grub2 import Grub2
+
 
 class GatherCurses:
   """
similarity index 99%
rename from src/lib/gathergui.py
rename to bootsetup/gathergui.py
index 232a28e..f1bbafb 100644 (file)
@@ -15,9 +15,10 @@ import gtk
 import gtk.glade
 import re
 import libsalt as slt
-from .config import *
-from .lilo import *
-from .grub2 import *
+from .config import Config
+from .lilo import Lilo
+from .grub2 import Grub2
+
 
 class GatherGui:
   """
similarity index 100%
rename from src/lib/grub2.py
rename to bootsetup/grub2.py
similarity index 99%
rename from src/lib/lilo.py
rename to bootsetup/lilo.py
index 4b90245..d643a3d 100644 (file)
@@ -16,7 +16,7 @@ import os
 import glob
 import codecs
 import libsalt as slt
-import subprocess
+from subprocess import CalledProcessError
 from operator import itemgetter
 
 
@@ -293,7 +293,7 @@ vga = {vga}
     """
     try:
       fbGeometry = slt.execGetOutput("/usr/sbin/fbset | grep -w geometry")
-    except subprocess.CalledProcessorError:
+    except CalledProcessError:
       self.__debug("Impossible to determine frame buffer mode, default to text.")
       fbGeometry = None
     mode = None
diff --git a/make b/make
new file mode 100755 (executable)
index 0000000..35e3575
--- /dev/null
+++ b/make
@@ -0,0 +1,82 @@
+#!/usr/bin/env python
+# coding: utf8
+# vim:et:sta:st=2:ts=2:tw=0:
+from __future__ import division, unicode_literals, print_function, absolute_import
+import sys
+import os
+import shutil
+from glob import glob
+import pip
+from pip.util import get_installed_distributions as pip_get_installed
+
+
+MODULE_NAME = 'bootsetup'
+os.chdir(os.path.dirname(os.path.abspath(sys.argv[0])))
+
+
+def usage():
+  print("""\
+Usage: make ACTION
+ACTION:
+  clean: clean the mess
+  build: create a .whl (python wheel) file
+  install [global]: install the wheel file, eventually globaly
+  info: information about {0}, if installed
+""".format(MODULE_NAME))
+
+
+def clean():
+  shutil.rmtree('wheelhouse', True)
+
+
+def pip_run(*args):
+  pip.main(list(args))
+  pip.logger.consumers = []  # correct an error on multile call to pip.main
+
+
+def build():
+  clean()
+  pip_run('wheel', '.')
+
+
+def install(local=True):
+  build()
+  wheel_file = glob('wheelhouse/*.whl')[0]
+  args = ['install', '--upgrade', '--force-reinstall']
+  if local:
+    args.append('--user')
+  args.append(wheel_file)
+  pip_run(*args)
+
+
+def info():
+  if [d.key for d in pip_get_installed() if d.key == MODULE_NAME]:
+    pip_run('show', MODULE_NAME)
+  else:
+    print("{0} is not installed, try ./make install or ./make install global".format(MODULE_NAME), file=sys.stderr)
+    sys.exit(1)
+
+args = sys.argv[1:]
+if not args:
+  args = ['build']
+while args:
+  arg = args[0]
+  args = args[1:]
+  if arg == 'help' or arg == '--help':
+    usage()
+    sys.exit(0)
+  elif arg == 'clean':
+    clean()
+  elif arg == 'build':
+    build()
+  elif arg == 'install':
+    if args and args[0] == 'global':
+      args = args[1:]
+      install(False)
+    else:
+      install()
+  elif arg == 'info':
+    info()
+  else:
+    usage()
+    sys.exit(1)
old mode 100755 (executable)
new mode 100644 (file)
similarity index 100%
rename from data/icons/bootsetup-128.png
rename to resources/icons/bootsetup-128.png
old mode 100755 (executable)
new mode 100644 (file)
similarity index 100%
rename from data/icons/bootsetup-24.png
rename to resources/icons/bootsetup-24.png
old mode 100755 (executable)
new mode 100644 (file)
similarity index 100%
rename from data/icons/bootsetup-64.png
rename to resources/icons/bootsetup-64.png
old mode 100755 (executable)
new mode 100644 (file)
similarity index 100%
rename from data/icons/bootsetup.svg
rename to resources/icons/bootsetup.svg
similarity index 100%
rename from data/po/fr.po
rename to resources/po/fr.po
diff --git a/setup.cfg b/setup.cfg
new file mode 100644 (file)
index 0000000..5e40900
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,2 @@
+[wheel]
+universal = 1
diff --git a/setup.py b/setup.py
new file mode 100755 (executable)
index 0000000..6e43c92
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,63 @@
+#!/bin/env python
+# coding: utf-8
+# vim:et:sta:sw=2:sts=2:ts=2:tw=0:
+
+import os
+import codecs
+import re
+from setuptools import setup
+
+
+def read(*paths):
+  """Build a file path from *paths* and return the contents."""
+  with codecs.EncodedFile(open(os.path.join(*paths), 'rb'), 'utf-8') as f:
+    return f.read()
+
+
+def find_info(info, *file_paths):
+  info_file = read(*file_paths)
+  info_match = re.search(r"^__{0}__ = ['\"]([^'\"]*)['\"]".format(info), info_file, re.M)
+  if info_match:
+    return info_match.group(1)
+  raise RuntimeError("Unable to find {0} string.".format(info))
+
+
+def find_version(*file_paths):
+  return find_info('version', *file_paths)
+
+
+config = {
+  'name': 'BootSetup',
+  'description': 'Helps installing a bootloader like LiLo or Grub2 on your computer',
+  'long_description': read('README.rst'),
+  'license': find_info('license', 'bootsetup', 'bootsetup.py'),
+  'author': find_info('author', 'bootsetup', 'bootsetup.py'),
+  'author_email': find_info('email', 'bootsetup', 'bootsetup.py'),
+  'version': find_version('bootsetup', 'bootsetup.py'),
+  'url': 'https://github.com/jrd/bootsetup/',
+  'download_url': 'https://github.com/jrd/bootsetup/archive/master.zip',
+  'packages': ['bootsetup'],
+  'include_package_data': True,
+  'package_data': {'bootsetup': ['*.glade']},
+  'entry_points': {'console_scripts': ['bootsetup = bootsetup.bootsetup:main']},
+  'classifiers': [  # https://pypi.python.org/pypi?:action=list_classifiers
+    'Development Status :: 4 - Beta',
+    'Environment :: Console',
+    'Environment :: Console :: Curses',
+    'Environment :: X11 Applications',
+    'Environment :: X11 Applications :: GTK',
+    'Intended Audience :: End Users/Desktop',
+    'Intended Audience :: System Administrators',
+    'Natural Language :: English',
+    'License :: OSI Approved :: GNU General Public License v2 or later (GPLv2+)',
+    'Operating System :: POSIX :: Linux',
+    'Programming Language :: Python',
+    'Programming Language :: Python :: 2',
+    'Programming Language :: Python :: 2.7',
+    'Programming Language :: Python :: 3',
+    'Programming Language :: Python :: 3.3',
+    'Topic :: System :: Boot',
+    'Topic :: System :: Recovery Tools',
+  ],
+}
+setup(**config)