Skip to content

Commit 6fa109e

Browse files
committed
computers-add: better handling of bind mounts
1 parent 624f32f commit 6fa109e

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

library/createdb/computers_add.py

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,12 @@ def parse_args(action, usage):
1313

1414
arggroups.database(parser)
1515
if action == consts.SC.computers_add:
16+
parser.add_argument("--ignore-mounts", nargs="+", default=[], help="List of mountpoints to ignore")
1617
parser.add_argument("hostnames", nargs="+", help="List of hostnames to connect to")
1718
args = parser.parse_args()
1819
arggroups.args_post(args, parser, create_db=True)
20+
21+
args.ignore_mounts = [s.rstrip(os.sep) for s in args.ignore_mounts]
1922
return args
2023

2124

@@ -44,14 +47,25 @@ def gather_system_info(hostname):
4447

4548
def log_warning_if_same_free_space(computer_info, disks):
4649
seen_free_spaces = set()
50+
seen_devices = set()
4751
for i, disk in enumerate(disks):
52+
device = disk["device"]
53+
if device in seen_devices:
54+
log.warning(
55+
"Skipping already seen device %s... any bind mounts? %s",
56+
device,
57+
[d for d in disks if d["device"] == device],
58+
)
59+
continue
60+
seen_devices.add(device)
61+
4862
free_space = disk["free"]
4963
if free_space in seen_free_spaces:
5064
log.warning(
51-
"%s mount %s has the same free space as another disk! You should open a ticket with this info: %s",
52-
computer_info["path"],
65+
"%s mount %s has the same free space as another disk! You are lucky! Or not and you should open a ticket with this info: %s",
66+
computer_info["node"],
5367
disk["path"],
54-
disks,
68+
[d for d in disks if d["free"] == free_space],
5569
)
5670
else:
5771
seen_free_spaces.add(free_space)
@@ -73,6 +87,7 @@ def computer_add(args, hostnames):
7387
disks = computer_info.pop("disks")
7488
log.debug(computer_info)
7589

90+
disks = [d for d in disks if d["path"] not in args.ignore_mounts]
7691
log_warning_if_same_free_space(computer_info, disks)
7792

7893
computer_info["path"] = hostname

library/createdb/getty_add.py

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -17,32 +17,32 @@ def parse_args():
1717

1818

1919
def activity_stream_extract(args, json_data):
20-
assert json_data['type'] == 'OrderedCollectionPage'
20+
assert json_data["type"] == "OrderedCollectionPage"
2121

2222
data = []
23-
if 'orderedItems' in json_data:
24-
for item in json_data['orderedItems']:
25-
for k in ['id', 'created', 'endTime']:
23+
if "orderedItems" in json_data:
24+
for item in json_data["orderedItems"]:
25+
for k in ["id", "created", "endTime"]:
2626
item.pop(k)
27-
obj = item.pop('object')
27+
obj = item.pop("object")
2828

29-
type_ = item.pop('type')
30-
if type_ == 'Delete':
29+
type_ = item.pop("type")
30+
if type_ == "Delete":
3131
with args.db.conn:
32-
args.db["activity_stream"].delete_where("path = ?", [obj.get('id')])
33-
elif type_ == 'Update':
32+
args.db["activity_stream"].delete_where("path = ?", [obj.get("id")])
33+
elif type_ == "Update":
3434
continue # TODO: implement in-band Update mechanism
35-
elif type_ not in ['Create']:
35+
elif type_ not in ["Create"]:
3636
raise
3737

3838
obj_info = {
39-
'path': obj.get('id'),
40-
'type': obj.get('type'),
41-
**{k: v for k, v in obj.items() if k not in ['id', 'type']},
39+
"path": obj.get("id"),
40+
"type": obj.get("type"),
41+
**{k: v for k, v in obj.items() if k not in ["id", "type"]},
4242
}
4343
data.append(obj_info)
4444
if item:
45-
print('item', item)
45+
print("item", item)
4646

4747
else:
4848
raise
@@ -68,23 +68,24 @@ def activity_stream_fetch(url):
6868

6969
return r.json()
7070

71+
7172
def update_activity_stream(args):
72-
current_page = int(args.db.pop('select max(page) from activity_stream') or 0) + 1
73+
current_page = int(args.db.pop("select max(page) from activity_stream") or 0) + 1
7374

7475
next_page_url = f"https://data.getty.edu/museum/collection/activity-stream/page/{current_page}"
7576
while next_page_url:
7677
log.debug("Fetching %s...", next_page_url)
7778

7879
page_data = activity_stream_fetch(next_page_url)
7980
if page_data:
80-
current_page = int(page_data['id'].split('/')[-1])
81+
current_page = int(page_data["id"].split("/")[-1])
8182

8283
activities = activity_stream_extract(args, page_data)
8384
args.db["activity_stream"].insert_all(
8485
[{"page": current_page, **activity} for activity in activities], alter=True, replace=True # pk="id",
8586
)
8687

87-
next_page_url = page_data.get('next', {}).get('id')
88+
next_page_url = page_data.get("next", {}).get("id")
8889
else:
8990
break
9091

@@ -94,6 +95,7 @@ def getty_add():
9495

9596
update_activity_stream(args)
9697

98+
9799
# https://data.getty.edu/museum/collection/group/ee294bfc-bbe5-42b4-95b2-04872b802bfe
98100
# https://data.getty.edu/museum/collection/object/08eaed9f-1354-4817-8aed-1db49e893a03
99101
# https://data.getty.edu/museum/collection/document/37194afd-905c-43df-9f28-baacdd91062a

0 commit comments

Comments
 (0)