def main(): """Main program""" (options, _args) = parse_args() verify_password_is_configured() if options.drop_database: drop_database() if options.create_database: create_database() if options.restore_file: restore_from_dump(options.restore_file) sql_dir = first_true(SQL_SEARCH_PATH, pred=_is_sql_dir) if not sql_dir: die("could not find SQL schema files using search path %s" % os.pathsep.join(SQL_SEARCH_PATH)) sync = Synchronizer(sql_dir, options.apply_out_of_order_changes) try: sync.connect() except psycopg2.OperationalError as err: die(err) sync.synchronize()
def get_native_and_trunked_vlans(self, interface) -> Tuple[int, List[int]]: if not self.is_els: switching = EthernetSwitchingInterfaceTable(self.device.device) switching.get(interface_name=interface.ifname) vlans = switching[interface.ifname].vlans else: switching = ElsEthernetSwitchingInterfaceTable(self.device.device) switching.get(interface_name=interface.ifname) vlans = [vlan for vlan in switching if vlan.tagged is not None] tagged = [vlan.tag for vlan in vlans if vlan.tagged] untagged = first_true(vlans, pred=lambda vlan: not vlan.tagged) return (untagged.tag if untagged else None), tagged
def main(): """Main program""" (options, _args) = parse_args() verify_password_is_configured() if options.drop_database: drop_database() if options.create_database: create_database() if options.restore_file: restore_from_dump(options.restore_file) sql_dir = first_true(SQL_SEARCH_PATH, pred=_is_sql_dir) if not sql_dir: die("could not find SQL schema files using search path %s" % os.pathsep.join(SQL_SEARCH_PATH)) sync = Synchronizer(sql_dir, options.apply_out_of_order_changes) try: sync.connect() except psycopg2.OperationalError, err: die(err)
def test_first_true_should_parse_predicate_correctly(self): elems = ["foo", "bar", "baz", "frobnicate"] assert first_true(elems, pred=lambda x: x == "baz") == "baz"
def test_first_true_should_return_default_value_when_no_true_found(self): elems = [False, False, False] default = object() assert first_true(elems, default=default) is default
def test_first_true_should_find_true_element(self): elems = [False, False, True, False] assert first_true(elems) == True