0

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

santos82h
  • 452
  • 5
  • 15
  • Did you try to create a working copy, unzip the first version to the working copy (svn add required), commit the working copy, unzip the next version, copy it to the working copy (maybe svn add required again), commit the working copy, and so on? – royalTS Apr 23 '18 at 13:57
  • it wasn't good enought because when you unzip project_v2.zip over project_v1 you add or overwrite the files that changed between v1 and v2, but you don't delete the files that was deleted between v1 and v2 – santos82h Apr 24 '18 at 16:05

1 Answers1

0

I will not help with python script, but these are steps that should be easy to automate:

  1. Create project directory and unpack files from project_v1.zip into it.
  2. Add everything from directory into svn (svn add *) and commit into trunk.
  3. Create v1 tag from trunk.
  4. Remove everything from project directory except .svn directory and unpack files from project_v2.zip into it.
  5. You need to add all unversioned files and remove all missing files from repository. You can use these commands to do the magic or just browse svn status output and run svn add or svn delete for every file one by one in python (see What do the result codes in SVN mean?).
  6. Commit changes to trunk and create v2 tag.
  7. Go to step 4 and repeat until you add every project version.

Note that steps 2 and 3 are redundant to 4, 5 and 6, so you can skip it - it does not make sense to remove everything from empty directory, but python script should not complain. :)

rob006
  • 21,383
  • 5
  • 53
  • 74