def test_deleting_single_item_top_level_list(self): base = {'key1': ['value1']} target = ['value1'] du.recursive_dict_removal(base, target) self.assertEqual(0, len(base['key1']))
def main(): """Run the main application.""" # Parse user args user_args = args() # Get the contents of the system environment json environment_file = file_find(filename=user_args['file']) with open(environment_file, 'rb') as f_handle: inventory = json.loads(f_handle.read()) # Make a table with hosts in the left column and details about each in the # columns to the right if user_args['list_host'] is True: print(print_inventory(inventory, user_args['sort'])) # Groups in first column, containers in each group on the right elif user_args['list_groups'] is True: print(print_groups_per_container(inventory)) # Containers in the first column, groups for each container on the right elif user_args['list_containers'] is True: print(print_containers_per_group(inventory)) elif user_args['export'] is True: print(json.dumps(export_host_info(inventory), indent=2)) else: recursive_dict_removal(inventory, user_args['remove_item']) with open(environment_file, 'wb') as f_handle: f_handle.write(json.dumps(inventory, indent=2)) print('Success. . .')
def test_deleting_single_item(self): base = {"key1": {"key1.1": "value1"}} target = ["value1"] du.recursive_dict_removal(base, target) self.assertEqual("value1", base["key1"]["key1.1"])
def test_deleting_single_item(self): base = {'key1': {'key1.1': 'value1'}} target = ['value1'] du.recursive_dict_removal(base, target) self.assertEqual('value1', base['key1']['key1.1'])
def test_deleting_single_nested_key(self): base = {'key1': {'key1.1': {'key1.1.1': ['value1']}}} target = ['key1.1.1'] du.recursive_dict_removal(base, target) self.assertNotIn('key1.1.1', base['key1']['key1.1'])
def main(): """Run the main application.""" # Parse user args user_args = args() # Get the contents of the system inventory inventory, filename = filesys.load_from_json(user_args['file']) # Make a table with hosts in the left column and details about each in the # columns to the right if user_args['list_host'] is True: print(print_inventory(inventory, user_args['sort'])) # Groups in first column, containers in each group on the right elif user_args['list_groups'] is True: print(print_groups_per_container(inventory)) # Containers in the first column, groups for each container on the right elif user_args['list_containers'] is True: print(print_containers_per_group(inventory)) elif user_args['export'] is True: print(json.dumps(export_host_info(inventory), indent=2)) elif user_args['clear_ips'] is True: remove_ip_addresses(inventory) inventory_json = json.dumps(inventory, indent=2) filesys.save_inventory(inventory_json, filename) print('Success. . .') else: du.recursive_dict_removal(inventory, user_args['remove_item']) inventory_json = json.dumps(inventory, indent=2) filesys.save_inventory(inventory_json, filename) print('Success. . .')
def main(): """Run the main application.""" # Parse user args user_args = args() # Get the contents of the system inventory inventory = load_from_json(user_args['file']) # Make a table with hosts in the left column and details about each in the # columns to the right if user_args['list_host'] is True: print(print_inventory(inventory, user_args['sort'])) # Groups in first column, containers in each group on the right elif user_args['list_groups'] is True: print(print_groups_per_container(inventory)) # Containers in the first column, groups for each container on the right elif user_args['list_containers'] is True: print(print_containers_per_group(inventory)) elif user_args['export'] is True: print(json.dumps(export_host_info(inventory), indent=2)) elif user_args['clear_ips'] is True: remove_ip_addresses(inventory) save_to_json(user_args['file'], inventory) print('Success. . .') else: recursive_dict_removal(inventory, user_args['remove_item']) save_to_json(user_args['file'], inventory) print('Success. . .')
def test_deleting_single_nested_key(self): base = {"key1": {"key1.1": {"key1.1.1": ["value1"]}}} target = ["key1.1.1"] du.recursive_dict_removal(base, target) self.assertNotIn("key1.1.1", base["key1"]["key1.1"])
def test_deleting_single_item_top_level_list(self): base = {"key1": ["value1"]} target = ["value1"] du.recursive_dict_removal(base, target) self.assertEqual(0, len(base["key1"]))
def test_deleting_single_item_from_list(self): base = {'key1': {'key1.1': ['value1']}} target = ['value1'] du.recursive_dict_removal(base, target) self.assertEqual(0, len(base['key1']['key1.1'])) self.assertNotIn('value1', base['key1']['key1.1'])
def test_deleting_single_item_in_single_level_noop(self): """The funtion only operates on nested dictionaries""" base = {'key1': 'value1'} target = ['value1'] du.recursive_dict_removal(base, target) self.assertEqual('value1', base['key1'])
def test_deleting_single_item_in_single_level_noop(self): """The function only operates on nested dictionaries""" base = {'key1': 'value1'} target = ['value1'] du.recursive_dict_removal(base, target) self.assertEqual('value1', base['key1'])
def test_deleting_single_item_in_single_level_noop(self): """The funtion only operates on nested dictionaries""" base = {"key1": "value1"} target = ["value1"] du.recursive_dict_removal(base, target) self.assertEqual("value1", base["key1"])
def test_deleting_single_item_from_list(self): base = {"key1": {"key1.1": ["value1"]}} target = ["value1"] du.recursive_dict_removal(base, target) self.assertEqual(0, len(base["key1"]["key1.1"])) self.assertNotIn("value1", base["key1"]["key1.1"])
def test_deleting_single_item_from_nested_list(self): """The function only operates on the 2nd level dictionary""" base = {"key1": {"key1.1": {"key1.1.1": ["value1"]}}} target = ["value1"] du.recursive_dict_removal(base, target) self.assertEqual(1, len(base["key1"]["key1.1"]["key1.1.1"])) self.assertIn("value1", base["key1"]["key1.1"]["key1.1.1"])
def test_deleting_single_item_from_nested_list(self): """The function only operates on the 2nd level dictionary""" base = {'key1': {'key1.1': {'key1.1.1': ['value1']}}} target = ['value1'] du.recursive_dict_removal(base, target) self.assertEqual(1, len(base['key1']['key1.1']['key1.1.1'])) self.assertIn('value1', base['key1']['key1.1']['key1.1.1'])
def remove_inventory_item(remove_item, inventory, filepath=None): """Removes inventory item from the inventory dictionary Writes the changes into the inventory file in filepath if available All container_networks information for containers will be deleted. """ du.recursive_dict_removal(inventory, remove_item) if filepath is not None: inventory_json = json.dumps(inventory, indent=2, separators=(',', ': ')) filesys.save_inventory(inventory_json, filepath)