I have diferent versioned zips of a project, for example:
- project_v1.zip
- project_v2.zip
- project_v3.zip
- project_v4.zip
There isn't any .svn
inside them but we know v2 was developed from v1, v3 was developed from v2 and v4 was developed from v3
I am using python
and svn command-line
to unzip each file and create a tag with its content, but I don't sure how recreate a trunk in whichs history you can see how the code is changing from v1 to v4 through v2 and v3.
I need to do this programmatically because of we have the same problem with several projects and we don't have time to manual merging or dealing with comflict, so the script have to be unattended.
I'm trying this:
import os
import subprocess
from shutil import copyfile
import filecmp
def run(cmd):
try:
r = subprocess.check_output(cmd)
except:
print ("\n\n")
print (" ".join(cmd))
raise
return r.decode('cp1252').strip()
def update_svn(zip_content, work_copy, comment):
for root, dirs, files in os.walk(work_copy, topdown=True):
dirs[:] = [d for d in dirs if d !=".svn"]
borrados = set()
for name in files:
filename = os.path.join(root, name)
filename = os.path.relpath(filename, work_copy)
new_file = zip_content+"\\"+filename
if not os.path.exists(new_file):
run(["svn", "delete", work_copy+"\\"+filename, "-m", comment])
for name in dirs:
dirname = os.path.join(root, name)
dirname = os.path.relpath(dirname, work_copy)
new_dir = zip_content+"\\"+dirname
if not os.path.exists(new_dir):
run(["svn", "delete", work_copy+"\\"+dirname, "-m", comment])
borrados.add(name)
dirs[:] = [d for d in dirs if d in borrados]
for root, dirs, files in os.walk(zip_content, topdown=True):
dirs[:] = [d for d in dirs if d !=".svn"]
for name in files:
filename = os.path.join(root, name)
old_file = work_copy+"\\"+os.path.relpath(filename, zip_content)
if not os.path.exists(old_file) or not filecmp.cmp(filename, old_file):
copyfile(filename, old_file)
run(["svn", "-q", "add", destino])
for name in dirs:
dirname = os.path.join(root, name)
dirname = os.path.relpath(dirname, zip_content)
old_dir = work_copy+"\\"+dirname
if not os.path.exists(old_dir):
run(["svn", "mkdir", old_dir])
run(["svn", "commit", work_copy, "-m", comment])
but when I compare in svn the trunk with the last tag I see they have some differences