mirror of
https://gitlab.com/wgp/dougal/software.git
synced 2025-12-06 11:37:08 +00:00
Do not fail if some data files are missing
This commit is contained in:
@@ -96,16 +96,21 @@ if __name__ == '__main__':
|
|||||||
with db.conn.cursor() as cursor:
|
with db.conn.cursor() as cursor:
|
||||||
columns = exportables["public"][table]
|
columns = exportables["public"][table]
|
||||||
path = os.path.join(VARDIR, "-"+table)
|
path = os.path.join(VARDIR, "-"+table)
|
||||||
with open(path, "rb") as fd:
|
try:
|
||||||
print(" →→ ", path, " ←← ", table, columns)
|
with open(path, "rb") as fd:
|
||||||
if columns is not None:
|
print(" →→ ", path, " ←← ", table, columns)
|
||||||
import_table(fd, table, columns, cursor)
|
if columns is not None:
|
||||||
else:
|
import_table(fd, table, columns, cursor)
|
||||||
try:
|
else:
|
||||||
print(f"Copying from {path} into {table}")
|
try:
|
||||||
cursor.copy_from(fd, table)
|
print(f"Copying from {path} into {table}")
|
||||||
except psycopg2.errors.UniqueViolation:
|
cursor.copy_from(fd, table)
|
||||||
print(f"It looks like table {table} may have already been imported. Skipping it.")
|
except psycopg2.errors.UniqueViolation:
|
||||||
|
print(f"It looks like table {table} may have already been imported. Skipping it.")
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(f"File not found. Skipping {path}")
|
||||||
|
|
||||||
|
db.conn.commit()
|
||||||
|
|
||||||
print("Reading surveys")
|
print("Reading surveys")
|
||||||
for survey in surveys:
|
for survey in surveys:
|
||||||
@@ -124,15 +129,18 @@ if __name__ == '__main__':
|
|||||||
path = os.path.join(pathPrefix, "-"+table)
|
path = os.path.join(pathPrefix, "-"+table)
|
||||||
print(" ←← ", path, " →→ ", table, columns)
|
print(" ←← ", path, " →→ ", table, columns)
|
||||||
|
|
||||||
with open(path, "rb") as fd:
|
try:
|
||||||
if columns is not None:
|
with open(path, "rb") as fd:
|
||||||
import_table(fd, table, columns, cursor)
|
if columns is not None:
|
||||||
else:
|
import_table(fd, table, columns, cursor)
|
||||||
try:
|
else:
|
||||||
print(f"Copying from {path} into {table}")
|
try:
|
||||||
cursor.copy_from(fd, table)
|
print(f"Copying from {path} into {table}")
|
||||||
except psycopg2.errors.UniqueViolation:
|
cursor.copy_from(fd, table)
|
||||||
print(f"It looks like table {table} may have already been imported. Skipping it.")
|
except psycopg2.errors.UniqueViolation:
|
||||||
|
print(f"It looks like table {table} may have already been imported. Skipping it.")
|
||||||
|
except FileNotFoundError:
|
||||||
|
print(f"File not found. Skipping {path}")
|
||||||
|
|
||||||
# If we don't commit the data does not actually get copied
|
# If we don't commit the data does not actually get copied
|
||||||
db.conn.commit()
|
db.conn.commit()
|
||||||
|
|||||||
Reference in New Issue
Block a user