Commits

JanKanis committed 17c2780

add setup.py to hg; monkeypatch a post install_script hook to create the right symlinks

  • Participants
  • Parent commits d2933d3

Comments (0)

Files changed (1)

+
+from distutils.core import setup
+
+import os
+from os import path
+
+from distutils.command.install_scripts import install_scripts
+from distutils.errors import DistutilsFileError
+from distutils import log
+
+
+# When installing, at least on posix, there should be two commands in the path: wiki2csv and csv2wiki. There seems to be no clean way to have a hook called after the install is finished but before the rest of the setup.py process continues, so I have monkeypatched my own solution. 
+
+# monkeypatch the script installation
+old_run = install_scripts.run
+def run(self, *args, **kwargs):
+  # retval should always be None, but just pass it up anyway. 
+  retval = old_run(self, *args, **kwargs)
+
+  # symlinks require posix. Windows can just use wiki2csv.py. 
+  if os.name != 'posix':
+    return retval
+
+  for pth in list(self.outfiles):
+    installpath, scriptfile = os.path.split(pth)
+    if scriptfile != 'wiki2csv.py':
+      continue
+    outfiles = [self.move_file(pth, path.join(installpath, 'wiki2csv'))]
+    if make_symlink(path.join(installpath, 'csv2wiki'), 'wiki2csv', dry_run=self.dry_run):
+      outfiles.append(path.join(installpath, 'csv2wiki'))
+    self.outfiles.remove(pth)
+    self.outfiles += outfiles
+
+  return retval
+
+install_scripts.run = run
+
+    
+def make_symlink(src, dest, dry_run=False, verbose=1):
+  """make a symlink in the same style as distutils/file_util.py functions"""
+  if verbose >= 1:
+    log.info("symlinking %s -> %s", src, dest)
+
+  if dry_run:
+    return src
+
+  try:
+    os.symlink(dest, src)
+  except os.error, (num, msg):
+    raise DistutilsFileError(
+      "couldn't symlink '%s' to '%s': %s" % (src, dest, msg))
+  return src
+  
+
+setup(
+  name = 'wiki2csv',
+  version = '1.0.1',
+  scripts = ['wiki2csv.py'],
+  author = 'Jan Kanis',
+  author_email = 'jan.code@jankanis.nl',
+  url = 'http://bitbucket.org/JanKanis/wiki2csv',
+  description = 'convert wikipedia tables to csv and back for editing in Excel/LibreOffice',
+  long_description = '''Wiki2csv is a command line tool to convert a file containing a table in wikipedia's `wikitable syntax <http://en.wikipedia.org/wiki/Help:Wikitable>`_ to comma separated value syntax and the other way around. It was designed to allow editing of large wikipedia tables using the easier interface of common spreadsheet programs such as Microsoft Excel or `LibreOffice <http://www.libreoffice.org/>`_. Therefore it tries to preserve as much of the layout and formatting directives from the wikitable as possible, and it tries to be fully round trippable.''',
+  classifiers = [
+    'Programming Language :: Python :: 2.7',
+    'Development Status :: 4 - Beta',
+    'Environment :: Console',
+    'License :: OSI Approved :: GNU General Public License v3 or later (GPLv3+)',
+    'Operating System :: OS Independent',
+    'Topic :: Internet',
+    'Topic :: Text Processing :: Markup',
+    'Topic :: Utilities',
+  ],
+  options = {'bdist': {'plat_name': 'linux'}},
+)