Browse files

- eliminated python-colorama dependency, using logging module instead

  • Loading branch information...
1 parent e448ff0 commit f246ce4c510ceca00b06910ed948eb1f0138ce23 @erlehmann erlehmann committed Feb 4, 2013
Showing with 9 additions and 68 deletions.
  1. +0 −1 README
  2. +0 −33 helpers/__init__.py
  3. +5 −4 oa-cache
  4. +4 −30 sources/pmc.py
View
1 README
@@ -14,7 +14,6 @@ Commands:
oa-put upload-media [dummy|pmc|pmc_doi]
Dependencies:
- python-colorama <http://pypi.python.org/pypi/colorama> (optional)
python-dateutil <http://pypi.python.org/pypi/python-dateutil>
python-elixir <http://elixir.ematia.de/trac/wiki>
python-gst0.10 <http://gstreamer.freedesktop.org/modules/gst-python.html>
View
33 helpers/__init__.py
@@ -1,41 +1,8 @@
#!/usr/local/bin/python
# -*- coding: utf-8 -*
-try:
- from colorama import Fore, Style
- color = True
- red = Fore.RED
- yellow = Fore.YELLOW
- bright = Style.BRIGHT
- reset = Style.RESET_ALL
-except:
- color = False
- red = ""
- yellow = ""
- bright = ""
- reset = ""
-
from sys import stderr
-def emit_error(title, text):
- error = "%s%s%s %s%s\n" % (
- red,
- bright,
- title,
- reset,
- text
- )
- stderr.write(error)
-
-def emit_warning(text):
- warning = "%s%s%s%s\n" % (
- yellow,
- bright,
- text,
- reset
- )
- stderr.write(warning)
-
def make_datestring(year, month, day):
datestring = "%04d" % year # YYYY
if month is not None:
View
9 oa-cache
@@ -15,6 +15,7 @@ import gobject, pygst
pygst.require("0.10")
import gst
+import logging
import progressbar
import mutagen.oggtheora
@@ -23,7 +24,7 @@ import pprint
import subprocess
-from helpers import media, emit_error, emit_warning, make_datestring
+from helpers import media, make_datestring
from model import session, setup_all, create_all, set_source, \
Article, Category, Journal, SupplementaryMaterial
@@ -142,8 +143,8 @@ if action == 'convert-media':
m.find_streams()
m.convert(temporary_media_path)
except RuntimeError, e:
- emit_error(e, "Skipping conversion of “%s”." % \
- media_raw_path.encode('utf-8'))
+ logging.error("%s: Skipping conversion of “%s”.", \
+ e, media_raw_path.encode('utf-8'))
continue
try:
@@ -165,7 +166,7 @@ if action == 'convert-media':
if value is not None:
f[key] = value
else:
- emit_warning('Missing metadata: %s.' % key)
+ logging.warning('Missing metadata: %s.', key)
f.save()
except mutagen.oggtheora.OggTheoraHeaderError:
pass # Most probably an encoding failure.
View
34 sources/pmc.py
@@ -1,33 +1,6 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-try:
- import colorama
- colorama.init()
- color=True
-except:
- color=False
-
-
-def _emit_error(title, text):
- error = ""
- if color:
- error += colorama.Fore.RED + colorama.Style.BRIGHT
- error += title + ' '
- if color:
- error += colorama.Style.RESET_ALL
- error += text + '\n'
- stderr.write(error)
-
-def _emit_warning(text):
- warning = ""
- if color:
- warning += colorama.Fore.YELLOW + colorama.Style.BRIGHT
- warning += text + '\n'
- if color:
- warning += colorama.Style.RESET_ALL
- stderr.write(warning)
-
from datetime import date
from os import listdir, path
from sys import stderr
@@ -38,6 +11,7 @@ def _emit_warning(text):
from hashlib import md5
import tarfile
+import logging
# According to <ftp://ftp.ncbi.nlm.nih.gov/README.ftp>, this should be
# 33554432 (32MiB) for best performance. Note that on slow connections,
@@ -518,15 +492,15 @@ def _get_text_from_element(element):
elif copyright_statement is not None:
copyright_statement_text = _get_text_from_element(copyright_statement)
else:
- _emit_warning('No <license> or <copyright-statement> element found in XML.')
+ logging.error('No <license> or <copyright-statement> element found in XML.')
return None, None, None
if license_url is None:
if license_text is not None:
try:
license_url = license_url_equivalents[license_text]
except:
- _emit_error('Unknown license:', license_text)
+ logging.error('Unknown license: %s', license_text)
elif copyright_statement_text is not None:
copyright_statement_found = False
@@ -536,7 +510,7 @@ def _get_text_from_element(element):
copyright_statement_found = True
break
if not copyright_statement_found:
- _emit_error('Unknown copyright statement:', copyright_statement_text)
+ logging.error('Unknown copyright statement: %s', copyright_statement_text)
def _fix_license_url(license_url):
if license_url in license_url_fixes.keys():

0 comments on commit f246ce4

Please sign in to comment.