Esempio n. 1
0
    def main(err, log, append, d, dest,
            user, host, port, password, dburi,
            tablename, dbname, filenames):

      filenames = list(filenames)

      with file(err, 'w') as errfile:
          plevel = logging.DEBUG if d else logging.WARNING
          _log = get_logger(fname=log, plevel=plevel)
          dbsettings = dict(
              dbname = dbname,
              hostname = host,
              username = user,
              port = port,
              password = password,
              uri = dburi
          )

          import_datafiles(filenames, not append, tablename, errfile, PGMethods,
                          **dbsettings)
          errfile.close()
Esempio n. 2
0
File: pg.py Progetto: imclab/dbtruck
import pdb
import traceback

sys.path.append('..')
sys.path.append( os.path.abspath(os.path.dirname(__file__)) )

from collections import *
from dateutil.parser import parse as dateparse
from StringIO import StringIO
from sqlalchemy import *

from dbtruck.util import get_logger, to_utf, block_iter
from dbtruck.infertypes import *
from dbtruck.exporters.base import BaseMethods

_log = get_logger()
copy_re = re.compile('line (?P<line>\d+), column\ (?P<col>\w+): \"(?P<val>.+)\"')
cr_re = re.compile(r'[\r\f\v]')


class PGMethods(BaseMethods):

    def __init__(self, *args, **kwargs):
        super(PGMethods, self).__init__(*args, **kwargs)

        self.dbname = kwargs['dbname']
        self.hostname = kwargs.get('hostname', 'localhost')
        self.username = kwargs.get('user', '')
        self.password = kwargs.get('password', None)
        self.port = kwargs.get('port', 0)
Esempio n. 3
0
    parser.add_argument('--port', dest='port', default=5432,
                        help='database port (if applicable)')
    parser.add_argument('-d', action='store_true', dest='debug', default=False,
                        help='print debug messages to stdout')
    parser.add_argument('tname', nargs=1, help='tablename')
    parser.add_argument('dbname', nargs=1, help='database name', default="test")
    parser.add_argument('fnames', nargs='+', help='data file name')
    args = parser.parse_args()

    tablename, dbname, fnames = args.tname[0], args.dbname[0], args.fnames
    dbuser = args.user
    dbport = args.port and int(args.port) or 5432 
    errfile = file(args.errfile, 'w')

    plevel = logging.DEBUG if args.debug else logging.WARNING
    _log = get_logger(fname=args.logfile, plevel=plevel)


    dbsettings = {
    'dbname' : dbname,
    'hostname' : 'localhost',
    'username' : dbuser,
    'port' : dbport,
    }


    import_datafiles(fnames, not args.append, tablename, errfile, PGMethods,
                     **dbsettings)
    errfile.close()

# potential options