Пример #1
0
def add_files_in_dir(nom_fuz, noms, start_dir, printer=0):
    #start_dir numero de ligne ou commence le dossier
    fusioned = file(nom_fuz, "rb")
    copy = file(get_path(nom_fuz) + "copy", "wb")
    ligne = 0
    if printer: print "copie du debut du fichier de fusion"
    for i in range(start_dir - 3):
        copy.write(fusioned.readline())
    string = fusioned.readline()[:-1]
    copy.write(
        int_len(int_base(base_int(string, 254) +
                         len(noms), 254), len(string)) + "\n")
    for nom in noms:
        if printer: print nom, "\ncalcule de la taille du fichier"
        ligne = 0
        for i in file(nom, "rb").read_lines():
            ligne += 1
        copy.write(get_name(nom) + "\n" + int_base(ligne, 254) + "\n")
        if printer: print "copie du fichier"
        for i in file(nom, "rb").read_lines():
            copy.write(i)
        copy.write("\n")
    if printer: print "copie de la fin du fichier de fusion"
    for i in fusioned.read_lines():
        copy.write(i)
    copy.close()
    remove(nom_fuz)
    rename(get_path(nom_fuz) + "copy", nom_fuz)
    if printer: print "creation de l'index du fichier de fusion"
    create_index_dir(nom_fuz)
Пример #2
0
def create_index_file(nom, nom_dir="",start=-1, stop=-1):
      if nom_dir:
            name = nom.replace("\\","/")+"."+nom_dir.replace("\\","/").replace("/",".")+".zid"
            fichier = file(name,"wb")
      else: fichier = file(".".join(nom.split(".")[:-1])+".zid","wb")
      fusioned = file(nom,"rb")
      if stop <= -1 >= start: fichier.write("0")

      for f, start, stop in voir_files(nom,start,stop):
            print f
            fichier.write(f+"\n"+int_base(start,254)+"\n"+int_base(stop,254)+"\n")
      fichier.close()
Пример #3
0
def create_index_file(nom, nom_dir="", start=-1, stop=-1):
    if nom_dir:
        name = nom.replace("\\", "/") + "." + nom_dir.replace(
            "\\", "/").replace("/", ".") + ".zid"
        fichier = file(name, "wb")
    else:
        fichier = file(".".join(nom.split(".")[:-1]) + ".zid", "wb")
    fusioned = file(nom, "rb")
    if stop <= -1 >= start: fichier.write("0")

    for f, start, stop in voir_files(nom, start, stop):
        print f
        fichier.write(f + "\n" + int_base(start, 254) + "\n" +
                      int_base(stop, 254) + "\n")
    fichier.close()
Пример #4
0
def fusion_files(liste, path="", file_fuz=""):
	if type(liste) != type([]) : liste = list(liste)

	if not file_fuz:
		temp = liste[0]
		if "." in temp: temp = ".".join(liste[0].split(".")[:-1])
		fusioned_name = temp+".fuz"
		fusioned = file(try_file(fusioned_name),"wb")
		fusioned.write("0")
	elif type(file_fuz) == type("") or type(file_fuz) == type(u""):
		fusioned_name = file_fuz
		fusioned = file(try_file(fusioned_name),"wb")
		fusioned.write("0")
	else: fusioned = file_fuz

	for i in liste:
		name = force_encode(i.replace("\\","/").split("/")[-1])
		size = 0
		print "\t",name

		fichier = file((path+"/")*bool(len(path))+i,"rb")
		while fichier.readline() != "" : size += 1
		fichier.close()
		fusioned.write(name+"\n"+int_base(size, 254)+"\n")
		fichier = file(path+"/"*bool(len(path))+i,"rb")
		string = fichier.readline()
		while string != "":
			fusioned.write(string)
			string = fichier.readline()
		fichier.close()
		if size: fusioned.write("\n")

	if type(file_fuz) == type("") or type(file_fuz) == type(u""):
		fusioned.close()
		return fusioned_name
Пример #5
0
def fusion_files(liste, path="", file_fuz=""):
	if type(liste) != type([]) : liste = list(liste)

	if not file_fuz:
		temp = liste[0]
		if "." in temp: temp = ".".join(liste[0].split(".")[:-1])
		fusioned_name = temp+".fuz"
		fusioned = file(try_file(fusioned_name),"wb")
		fusioned.write("0")
	elif type(file_fuz) == type("") or type(file_fuz) == type(u""):
		fusioned_name = file_fuz
		fusioned = file(try_file(fusioned_name),"wb")
		fusioned.write("0")
	else: fusioned = file_fuz

	for i in liste:
		name = i.replace("\\","/").split("/")[-1].encode("cp1252")
		size = 0
		print "\t",name

		fichier = file((path+"/")*bool(len(path))+i,"rb")
		while fichier.readline() != "" : size += 1
		fichier.close()
		fusioned.write(name+"\n"+int_base(size, 254)+"\n")
		fichier = file(path+"/"*bool(len(path))+i,"rb")
		string = fichier.readline()
		while string != "":
			fusioned.write(string)
			string = fichier.readline()
		fichier.close()
		if size: fusioned.write("\n")

	if type(file_fuz) == type("") or type(file_fuz) == type(u""):
		fusioned.close()
		return fusioned_name
Пример #6
0
def create_index_dir(nom, nom_dir="",start=-1, stop=-1):
	if nom_dir:
		name = nom.replace("\\","/")+":"+nom_dir.replace("\\","/").replace("/",":")+".zid"
		fichier = file(name,"wb")
	else: fichier = file(".".join(nom.split(".")[:-1])+".zid","wb")
	fusioned = file(nom,"rb")
	if stop > -1 < start: fusioned.read(1)
	dirs, nbr_dir, len_nbr = get_arborescence(fusioned, start, stop)
	fichier.write("1"+int_base(len_nbr)+"\n")

	for i,files in enumerate(files_in_dir(fusioned,(dirs, nbr_dir, len_nbr), start, stop)):
		c_dir, files = files
		nbr_files = len(files)
		if nbr_files:
			fichier.write(int_len(int_base(dirs.index(c_dir)),len_nbr)+int_base(nbr_files,254)+"\n")
			x = 0
			for f, start, stop in files: fichier.write(f+"\n"+int_base(start,254)+"\n"+int_base(stop,254)+"\n")
Пример #7
0
def create_index_dir(nom, nom_dir="", start=-1, stop=-1):
    if nom_dir:
        name = nom.replace("\\", "/") + ":" + nom_dir.replace(
            "\\", "/").replace("/", ":") + ".zid"
        fichier = file(name, "wb")
    else:
        fichier = file(".".join(nom.split(".")[:-1]) + ".zid", "wb")
    fusioned = file(nom, "rb")
    if stop > -1 < start: fusioned.read(1)
    dirs, nbr_dir, len_nbr = get_arborescence(fusioned, start, stop)
    fichier.write("1" + int_base(len_nbr) + "\n")

    for i, files in enumerate(
            files_in_dir(fusioned, (dirs, nbr_dir, len_nbr), start, stop)):
        c_dir, files = files
        nbr_files = len(files)
        if nbr_files:
            fichier.write(
                int_len(int_base(dirs.index(c_dir)), len_nbr) +
                int_base(nbr_files, 254) + "\n")
            x = 0
            for f, start, stop in files:
                fichier.write(f + "\n" + int_base(start, 254) + "\n" +
                              int_base(stop, 254) + "\n")
Пример #8
0
def add_files_in_dir(nom_fuz, noms, start_dir, printer=0):
      #start_dir numero de ligne ou commence le dossier
      fusioned = file(nom_fuz, "rb")
      copy = file(get_path(nom_fuz)+"copy", "wb")
      ligne = 0
      if printer: print "copie du debut du fichier de fusion"
      for i in range(start_dir-3): copy.write(fusioned.readline())
      string = fusioned.readline()[:-1]
      copy.write(int_len(int_base(base_int(string, 254) + len(noms), 254), len(string))+"\n")
      for nom in noms:
            if printer: print nom,"\ncalcule de la taille du fichier"
            ligne = 0
            for i in file(nom, "rb").read_lines(): ligne += 1
            copy.write(get_name(nom)+"\n"+int_base(ligne,254)+"\n")
            if printer: print "copie du fichier"
            for i in file(nom, "rb").read_lines(): copy.write(i)
            copy.write("\n")
      if printer: print "copie de la fin du fichier de fusion"
      for i in fusioned.read_lines(): copy.write(i)
      copy.close()
      remove(nom_fuz)
      rename(get_path(nom_fuz)+"copy", nom_fuz)
      if printer: print "creation de l'index du fichier de fusion"
      create_index_dir(nom_fuz)
Пример #9
0
def add_file_in_file(nom_fuz, nom, index=True, avancement=False):
      fusioned = file(nom_fuz,"ab")
      ligne = 0
      print "calcule de la taille du fichier ."
      for i in file(nom,"rb").read_lines(): ligne += 1
      fusioned.write(get_name(nom)+"\n")
      fusioned.write(int_base(ligne,254)+"\n")
      x = 0.
      name = get_name(nom)
      for l in file(nom,"rb").read_lines():
            if avancement:
                  x += 1
                  system("cls")
                  print name
                  print "avancement :",x/ligne * 100,"% ",x,"/",ligne,"lignes"
            fusioned.write(l)
      fusioned.write("\n")
      fusioned.close()
      if index:
            print "creation de l'index du fichier de fusion."
            create_index_file(nom_fuz)
Пример #10
0
def add_file_in_file(nom_fuz, nom, index=True, avancement=False):
    fusioned = file(nom_fuz, "ab")
    ligne = 0
    print "calcule de la taille du fichier ."
    for i in file(nom, "rb").read_lines():
        ligne += 1
    fusioned.write(get_name(nom) + "\n")
    fusioned.write(int_base(ligne, 254) + "\n")
    x = 0.
    name = get_name(nom)
    for l in file(nom, "rb").read_lines():
        if avancement:
            x += 1
            system("cls")
            print name
            print "avancement :", x / ligne * 100, "% ", x, "/", ligne, "lignes"
        fusioned.write(l)
    fusioned.write("\n")
    fusioned.close()
    if index:
        print "creation de l'index du fichier de fusion."
        create_index_file(nom_fuz)
Пример #11
0
def fusion_dirfile(dirs, files=[], name=""):
    if dirs:
        if not name: name = dirs[0]
        if name[-1] == "/": name = name[:-1]
        len_ext = len(get_ext(name))
        liste = [encode(get_name(name))]
        paths = [encode(name)]
        if get_ext(name) != "fuz": name += ".fuz"

        for dossier in dirs:
            new_paths = get_paths(dossier)
            lim = (len("/".join(new_paths[0][:-1].split("/")[:-1])) + 1) * int(
                bool(new_paths[0][:-1].count("/")))
            for i in new_paths:
                liste.append(encode(liste[0] + "/" + i[lim:-1]))
                paths.append(i[:-1])

        nbr_dir = int_base(len(liste))
        len_nbr = len(nbr_dir)
        i = 0
        while i < len(paths):
            index = len("/".join(liste[i].split("/")[:-1])) + 1
            if not i: index -= 1

            dossier = encode(liste[i].split("/")[-1])
            index_dossier = len(dossier)
            path = liste[i][:index + index_dossier]
            for ind, p in enumerate(liste):
                if p[:index + index_dossier] == path:
                    liste[ind] = p[ : index] +\
                       p[index : index+index_dossier].replace(dossier, int_len(int_base(i), len_nbr)) +\
                       p[index+index_dossier : ]
            i += 1

        liste[0] = encode(liste[0][-len_nbr * 2 - 1:-len_nbr - 1] +
                          (get_name(paths[0]) +
                           ".")[:-len_ext * bool(len_ext) - 1])
        for i, e in enumerate(liste[1:]):
            liste[i + 1] = e[-len_nbr * 2 - 1:-len_nbr - 1] + encode(
                get_name(paths[i + 1]))

        fusioned = file(name, "wb")
        fusioned.write("1" + int_base(len_nbr) + int_len(nbr_dir, len_nbr))

        for i in liste:
            fusioned.write(i + "\n")

        for i, e in enumerate(liste):
            if i:
                fichiers = get_dirfile(paths[i])[1]
                if fichiers:
                    fusioned.write(int_len(int_base(i), len_nbr))
                    fusioned.write(int_base(len(fichiers)) + "\n")
                    print "\n" * 2, paths[i]
                    print
                    fusion_files(fichiers, paths[i], fusioned)
            else:
                fusioned.write("0" * len_nbr)
                if files:
                    fusioned.write(int_base(len(files), 254) + "\n")
                    fusion_files(files, "", fusioned)
                else:
                    fusioned.write("0\n")

        if files == None:
            fusioned.write(int_len(int_base(len(liste)), len_nbr))
            fusioned.write(int_base(len(files), 254) + "\n")
            fusion_files(files, "", fusioned)
        fusioned.close()
        return name
    else:
        return fusion_files(files, file_fuz=name)
Пример #12
0
def fusion_dirfile(dirs, files=[], name=""):
	if dirs:
		if not name: name = dirs[0]
		if name[-1] == "/": name = name[ : -1]
		len_ext = len(get_ext(name))
		liste = [encode(get_name(name))]
		paths = [encode(name)]
		if get_ext(name) != "fuz": name += ".fuz"

		for dossier in dirs:
			new_paths = get_paths(dossier)
			lim = (len("/".join(new_paths[0][:-1].split("/")[:-1]))+1)*int(bool(new_paths[0][:-1].count("/")))
			for i in new_paths :
				liste.append(encode(liste[0] + "/" + i[lim:-1]))
				paths.append(i[:-1])

		nbr_dir = int_base(len(liste))
		len_nbr = len(nbr_dir)
		i=0
		while i < len(paths):
			index = len("/".join(liste[i].split("/")[:-1]))+1
			if not i : index -= 1

			dossier = encode(liste[i].split("/")[-1])
			index_dossier = len(dossier)
			path = liste[i][:index+index_dossier]
			for ind, p in enumerate(liste) :
				if p[ : index+index_dossier] == path:
					liste[ind] = p[ : index] +\
								p[index : index+index_dossier].replace(dossier, int_len(int_base(i), len_nbr)) +\
								p[index+index_dossier : ]
			i+=1
		
		liste[0] = encode(liste[0][-len_nbr*2-1:-len_nbr-1]+(get_name(paths[0])+".")[ : -len_ext *bool(len_ext)-1])
		for i,e in enumerate(liste[1 : ]):
			liste[i+1] = e[-len_nbr*2-1:-len_nbr-1]+encode(get_name(paths[i+1]))

		fusioned = file(name,"wb")
		fusioned.write("1"+int_base(len_nbr)+int_len(nbr_dir, len_nbr))

		for i in liste : fusioned.write(i+"\n")

		for i, e in enumerate(liste):
			if i:
				fichiers = get_dirfile(paths[i])[1]
				if fichiers:
					fusioned.write(int_len(int_base(i),len_nbr))
					fusioned.write(int_base(len(fichiers))+"\n")
					print "\n"*2,paths[i]
					print
					fusion_files(fichiers, paths[i], fusioned)
			else:
				fusioned.write("0"*len_nbr)
				if files:
					fusioned.write(int_base(len(files), 254)+"\n")
					fusion_files(files, "", fusioned)
				else: fusioned.write("0\n")

		if files == None:
			fusioned.write(int_len(int_base(len(liste)),len_nbr))
			fusioned.write(int_base(len(files), 254)+"\n")
			fusion_files(files, "", fusioned)
		fusioned.close()
		return name
	else: return fusion_files(files,file_fuz=name)