~jstys-z/helioviewer.org/client5

« back to all changes in this revision

Viewing changes to install/shared/jp2.py

  • Committer: Keith Hughitt
  • Date: 2012-04-23 18:45:32 UTC
  • mto: This revision was merged to the branch mainline in revision 732.
  • Revision ID: keith.hughitt@nasa.gov-20120423184532-qwf3dvx7t1gojrdc
Unified logging for installer, updater, and downloader

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
# -*- coding: utf-8 -*-
2
2
"""Helioviewer.org JPEG 2000 processing functions"""
3
3
import os
4
 
from datetime import datetime
5
 
from xml.dom.minidom import parseString
 
4
import logging
6
5
from shared.db import get_datasources, enable_datasource
7
6
 
8
7
__INSERTS_PER_QUERY__ = 500
29
28
        import MySQLdb
30
29
    else:
31
30
        import pgdb
32
 
    
33
 
    # Error message
34
 
    error = ""
35
31
 
36
32
    # Return tree of known data-sources
37
33
    sources = get_datasources(cursor)
47
43
            meta_info["filepath"] = img
48
44
        except Exception as e:
49
45
            directory, filename = os.path.split(img)
50
 
            error += "Unable to process header for %s (%s)\n" % (filename, e)
 
46
            logging.error("Unable to process header for %s (%s)\n", filename, e)
51
47
            print("Error processing %s" % filename)
52
48
        else:
53
49
            valid_images.append(meta_info)
58
54
        valid_images = valid_images[__INSERTS_PER_QUERY__:]
59
55
        insert_images(subset, __INSERTS_PER_QUERY__, sources, rootdir, cursor, 
60
56
                      mysql, step_function)
61
 
        
62
 
    # Log any errors encountered
63
 
    if error:
64
 
        import time
65
 
        f = open('error.log', 'a')
66
 
        f.write(time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime()) + "\n" + error)
67
57
    
68
58
def insert_images(images, sources, rootdir, cursor, mysql, step_function=None):
69
59
    """Inserts multiple images into a database using a single query