Diff of /trunk/cforge/cforge/Package/CFORGE/Scripts/pysvn.py [000000] .. [r23]  Maximize  Restore

Switch to unified view

a b/trunk/cforge/cforge/Package/CFORGE/Scripts/pysvn.py
1
#!/usr/bin/python
2
#
3
# This module is a wrapper for a locally installed SVN command line client.
4
# It can be used to find URLs of CODESYS projects within a repository, or to
5
# checkout all files outside of CODESYS projects.
6
#
7
# - svn_list:
8
# a wrapper for the "svn list" command, supporting recursive lists
9
#
10
# - svn_get_directories_with_codesys_projects / svn_get_directories_without_codesys_projects:
11
# return directories with or without CODESYS projects. Can be used to find
12
# CODESYS library URLs in repositories.
13
#
14
# - svn_checkout_non_codesys:
15
# Checkout top-level directory w/o content.
16
# Then update all directories, which are not containing any CODESYS projects.
17
#
18
import subprocess
19
20
21
def svn_list(username, password, url, recursive=False):
22
    args = ""
23
    if recursive:
24
        args += " -R"
25
    cmd="svn list %s --username=%s --password=%s %s" % (args, username, password, url)
26
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
27
    (output, err) = p.communicate()
28
    entries = list()
29
    if "\n" in output.decode(encoding='utf-8', errors='strict'):
30
        entries = output.decode(encoding='utf-8', errors='strict').strip().replace("\r","").split("\n")
31
    return entries
32
33
def svn_get_directories_with_codesys_projects(username, password, url):
34
    allfiles = svn_list(username, password, url, True)
35
    codesys_projects = filter(lambda file: 'meta.profile' in file, allfiles)
36
37
    alldirs=list()
38
    for cp in codesys_projects:
39
        dirname = cp.replace("/meta.profile", "")
40
        alldirs.append(dirname)
41
    return alldirs
42
43
def svn_get_directories_without_codesys_projects(username, password, url):
44
    allfiles = svn_list(username, password, url, True)
45
    codesys_projects = filter(lambda file: 'meta.profile' in file, allfiles)
46
    # filter out all subdirectories of the directory containing 'meta.profile',
47
    # as well as all files (keep only directories)
48
    alldirs=allfiles
49
    for cp in codesys_projects:
50
        dirname = cp.replace("/meta.profile", "")
51
        alldirs = filter(lambda file: not file.startswith(dirname) and file.endswith('/'), alldirs)
52
    return alldirs
53
54
def svn_checkout_non_codesys(username, password, url, destination):
55
    dirs = svn_get_directories_without_codesys_projects(username, password, url)
56
    cmd="svn checkout --depth=empty --username=%s --password=%s %s %s" % (username, password, url, destination)
57
    p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
58
    (output, err) = p.communicate()
59
60
    if not err:
61
        for d in dirs:
62
            cmd="svn update --depth=files --username=%s --password=%s %s/%s" % (username, password, destination, d)
63
            p = subprocess.Popen(cmd, stdout=subprocess.PIPE, shell=True)
64
            (output, err) = p.communicate()
65
66