def f6(): opt = libdar.archive_options_read() passwd ="*****@*****.**" secu_pass = libdar.secu_string(passwd, len(passwd)) entrepot = libdar.entrepot_libcurl(ui, libdar.mycurl_protocol.proto_ftp, "anonymous", secu_pass, "ftp.dm3c.org", "", False, "", "", "", 5) print(entrepot.get_url()) opt.set_entrepot(entrepot) opt.set_info_details(True) arch2 = libdar.archive(ui, libdar.path("/dar.linux.free.fr/"), "exemple", "dar", opt) opt2 = libdar.archive_options_test() opt2.set_display_treated(True, False) arch2.op_test(opt2)
def f1(): opt = libdar.archive_options_create() opt.set_info_details(True) opt.set_display_treated(True, False) opt.set_display_finished(True) fsroot = libdar.path("/etc") print("creating the archive") libdar.archive(ui, fsroot, sauv_path, arch_name, ext, opt)
def list_dir(archive, chem="", indent=""): content = archive.get_children_in_table(chem, True) # contents is a list of libdar.list_entry objects for ent in content: ligne = indent if ent.is_eod(): continue if ent.is_hard_linked(): ligne += "*" else: ligne += " " if ent.is_dir(): ligne += "d" else: if ent.is_file(): ligne += "f" else: if ent.is_symlink(): ligne += "l" else: if ent.is_char_device(): ligne += "c" else: if ent.is_block_device(): ligne += "b" else: if ent.is_unix_socket(): ligne += "s" else: if ent.is_named_pipe(): ligne += "p" else: if ent.is_door_inode(): ligne += "D" else: if ent.is_removed_entry(): ligne += "Removed entry which was of of type {}".format( ent.get_removed_type()) else: ligne += "WHAT THIS????" continue ligne += ent.get_perm() + " " + ent.get_name() + " " ligne += ent.get_uid(True) + "/" + ent.get_gid(True) + " " ligne += ent.get_last_modif() print(ligne) # now peparing the recursion when we meet a directory: if ent.is_dir(): if chem != "": nchem = (libdar.path(chem) + ent.get_name()).display() else: nchem = ent.get_name() nindent = indent + " " list_dir(archive, nchem, nindent)
def f5(): opt = libdar.archive_options_read() arch1 = libdar.archive(ui, sauv_path, arch_name, ext, opt); tree1 = libdar.simple_path_mask("/etc/ssh", False) tree2 = libdar.simple_path_mask("/etc/grub.d", False) tree = libdar.ou_mask() tree.add_mask(tree1) tree.add_mask(tree2) opt = libdar.archive_options_diff() opt.set_subtree(tree) opt.set_info_details(True) opt.set_display_treated(True, False) opt.set_ea_mask(libdar.bool_mask(True)) opt.set_furtive_read_mode(False) arch1.op_diff(libdar.path("/etc"), opt) rest = libdar.path("./Restore") try: os.rmdir(rest.display()) except: pass os.mkdir(rest.display()) opt = libdar.archive_options_extract() # the overwriting policy can receive # objects from many different crit_action_* classes # - crit_constant_action() used here does always the same # action on Data and EA+FSA when a conflict arise that # would lead to overwriting # - testing(criterium) the action depends on the evaluation # of the provided criterium (see below) # - crit_chain() + add(crit_action) performs the different # crit_actions added in sequence the first one that provides # an action for Data and/or EA+FSA is retained. If no action # is left undefined the following crit_action of the chain are # not evaluated # # for the testing crit_action inherited class, we need to provide # a criterium object. Here too there is a set of inherited classes # that come to help: # - crit_in_place_is_inode # - crit_in_place_is_dir # - crit_in_place_is_file # - ... # - crit_not (to take the negation of the given criterium) # - crit_or + add_crit() + add_crit() ... makes the logical OR # - crit_and + add_crit() + add_crit()... for the logical AND # - crit_invert for the in_place/to_be_added inversion # Read the manual page about overwriting policy for details # but in substance the criterum return true of false for each # file in conflict and the object if class testing that uses # this criterium applies the action given as "go_true" or the # action given as "go_false" in regard of the provided result over_policy = libdar.crit_constant_action(libdar.over_action_data.data_preserve, libdar.over_action_ea.EA_preserve) opt.set_overwriting_rules(over_policy) # fsa_scope is a std::set in C++ side and translates to a # python set on python side. Use the add() method to add # values to the set: fsa_scope = set() fsa_scope.add(libdar.fsa_family.fsaf_hfs_plus) fsa_scope.add(libdar.fsa_family.fsaf_linux_extX) opt.set_fsa_scope(fsa_scope) stats = libdar.statistics() arch1.op_extract(rest, opt, stats) display_stats(stats)
# now peparing the recursion when we meet a directory: if ent.is_dir(): if chem != "": nchem = (libdar.path(chem) + ent.get_name()).display() else: nchem = ent.get_name() nindent = indent + " " list_dir(archive, nchem, nindent) # in the following we will provide several functions that # either create, read, test, diff or extract an archive # all will rely on the following global variables: ui = myui() sauv_path = libdar.path(".") arch_name = "arch1" ext = "dar" # let's create an archive. the class # libdar.archive_options_create has a default constructor # that set the options to their default values, the clear() # method can also be used to reset thm to default. # then a bunch of method are provided to modify each of them # according to your needs. See help(libdar.archive_options_create) # and the API reference documentation for their nature and meaning # the libdar.path can be set from a python string but has some # method to pop, add a sub-directory easily. the libdar.path.display() # method provides the representative string of the path def f1():