Exemple #1
0
    os.remove('filelist.txt')
fl = open('filelist.txt', 'w')

files = []
for i in range(1, len(sys.argv)):
    files.extend(glob.iglob(os.path.abspath(sys.argv[i])))

files = [file for file in files if os.path.splitext(file)[1] != '.original']

masks = {}

info('Examining {} files'.format(len(files)))
for fname in files:

    try:
        header = IO.readheader(fname)
    except IOError:  #, err:
        fl.write("Couldn't IO %s\n" % fname)
        continue
    except:
        fl.write("%s is unreadable\n" % fname)
        continue

    lamps = ""
    try:
        if header["pwstata7"] == 1:
            lamps += header["pwloca7"][0:2]
        if header["pwstata8"] == 1:
            lamps += header["pwloca8"][0:2]
    except KeyError:
        lamps = "???"
Exemple #2
0
def make():
    """Make the database"""

    db = load_db()
    c = db.cursor()
    create(c)
    dirs = os.walk(Options.indir)

    Options.indir = Options.indir.rstrip("/")

    for root, dirs, files in dirs:
        if root == Options.indir: continue
        ignore, path = root.split(Options.indir)

        if len(path.split("/")) != 2: continue

        try:
            date = int(path.split("/")[1][0:4])
        except:
            continue

        if (date < 2012) or (date > 2030): continue

        for file in files:
            if len(file) != 17: continue
            p = os.path.join(root, file)

            num = db.execute('select count(*) from files where path = "%s"' %
                             p).fetchall()
            if num[0][0] > 0:
                print("Skipping: " + p + " [already in db]")
                continue
            print(p)

            hdr = IO.readheader(p)

            try:
                fdate = file.split("_")[0][1:]
                number = file.split("_")[1][:-5]
            except:
                print("Skipping: " + p)
                continue

            insert_sql = "insert into files(path,fdate,number,"
            vals = "?,?,?,"
            values = [p, fdate, number]

            for key in hdr.keys():

                if key == 'COMMENT': continue

                value = hdr[key]
                T = type(value)
                key = key.replace("-", "_")

                insert_sql += key + ","
                vals += "?,"
                values.append(value)

                if key in keys: continue
                keys.append(key)

                if T == int: typename = 'integer'
                if T == float: typename = 'real'
                else: typename = 'text'
                append_column(c, key, typename)

            insert_sql = insert_sql[:-1] + ") values (" + vals[:-1] + ")"
            try:
                c.execute(insert_sql, tuple(values))
            except:
                print "Query failed on:"
                print insert_sql
                traceback.print_exc()
                #sys.exit()

    db.commit()
    os.remove('filelist.txt')
fl = open('filelist.txt', 'w')


files = []
for i in range(1, len(sys.argv)):
    files.extend(glob.iglob(sys.argv[i]))

masks = {}


info('Examining {} files'.format(len(files)))
for fname in files:

    try:
        header = IO.readheader(fname)
    except IOError:#, err:
        fl.write("Couldn't IO %s\n" % fname)
        continue
    except:
        fl.write("%s is unreadable\n" % fname)
        continue

    lamps = ""
    try:
        if header["pwstata7"] == 1:
            lamps += header["pwloca7"][0:2]
        if header["pwstata8"] == 1:
            lamps += header["pwloca8"][0:2]
    except KeyError:
        lamps = "???"
def make():
    """Make the database"""

    db = load_db()
    c = db.cursor()
    create(c)
    dirs = os.walk(Options.indir)

    Options.indir = Options.indir.rstrip("/")

    for root, dirs, files in dirs:
        if root == Options.indir: continue
        ignore, path = root.split(Options.indir)

        if len(path.split("/")) != 2: continue

        try: date = int(path.split("/")[1][0:4])
        except: continue

        if (date < 2012) or (date > 2030): continue

        for file in files:
            if len(file) != 17: continue
            p = os.path.join(root, file)

            num = db.execute('select count(*) from files where path = "%s"' %
                    p).fetchall()
            if num[0][0] > 0: 
                print("Skipping: " + p + " [already in db]")
                continue
            print(p)

            hdr = IO.readheader(p)

            try:
                fdate = file.split("_")[0][1:]
                number = file.split("_")[1][:-5]
            except:
                print("Skipping: " + p)
                continue

            insert_sql = "insert into files(path,fdate,number,"
            vals = "?,?,?,"
            values = [p, fdate, number]

            for key in list(hdr.keys()):

                if key == 'COMMENT': continue

                value = hdr[key]
                T = type(value)
                key = key.replace("-","_")

                insert_sql += key + ","
                vals += "?,"
                values.append(value)

                if key in keys: continue
                keys.append(key)
            


                if T == int: typename = 'integer'
                if T == float: typename = 'real'
                else: typename = 'text'
                append_column(c, key, typename)


            insert_sql = insert_sql[:-1] + ") values (" + vals[:-1] + ")"
            try:
                c.execute(insert_sql, tuple(values))
            except:
                print("Query failed on:")
                print(insert_sql)
                traceback.print_exc()
                #sys.exit()
                 

    db.commit()