Esempio n. 1
0
def check(ip):
    svn_url = "svn://{0}".format(ip)

    etalon = []
    with open(ETALON_FILENAME) as fn:
        for line in fn:
            etalon.append(json.loads(line))

    svn = Svn(svn_url)
    rev = svn.info()["rev"]

    if rev != len(etalon) - 1:
        print "Wrong revisions number"
        sys.exit(STATUS_NOT_OK)

    for _ in xrange(ITERATIONS):
        et = random.choice(etalon)
        rev = et["rev"]
        files = et["files"]

        for r_file in svn.ls(rev=rev):
            #logging.info("Checking rev: %d, file '%s', size %d", rev, r_file["name"], r_file["size"])
            if r_file["name"] not in files:
                print "File '{0}' in rev {1} should be deleted".format(r_file["name"], rev)
                sys.exit(STATUS_NOT_OK)

            e_file = files[r_file["name"]]
            if e_file["deleted"]:
                print "File '{0}' should be deleted in rev {1}".format(e_file["name"], rev)
                sys.exit(STATUS_NOT_OK)
Esempio n. 2
0
    def __init__(self):
        self.svn = Svn(svn_utils.find_svn_root_path())

        self.trunk_dir = "trunk"
        self.tags_dir = "tags"
        self.branches_dir = "branches"
        self.develop_branch = os.path.join(self.branches_dir, "develop")
        self.feature_dir = os.path.join(self.branches_dir, "feature")
        self.release_dir = os.path.join(self.branches_dir, "release")
        self.hotfix_dir = os.path.join(self.branches_dir, "hotfix")

        self.branch_dir_by_type = {"feature" : self.feature_dir, \
         "release" : self.release_dir, \
         "hotfix" : self.hotfix_dir}
Esempio n. 3
0
 def get_backend(self, module):
         if module.source == fetch.LOCAL:
             return Local()
         else:
             logging.info("Investigating module: " + str(module) +
                          "[parent: " + str(module.parent) + "]")
             if module.source == fetch.SVN:
                 return Svn()
             if module.source == fetch.GIT:
                 return Git()
             if module.source == fetch.GITSUBMODULE:
                 return GitSubmodule()
Esempio n. 4
0
def main():
    logging.basicConfig(format="%(asctime)-15s:%(levelname)s:%(message)s", level=logging.INFO)
    if len(sys.argv) < 2:
        print >>sys.stderr, "Usage: {0} ip".format(sys.argv[0])
        sys.exit(1)

    svn_url = sys.argv[1]

    svn = Svn(svn_url)
    max_rev = svn.info()["rev"]

    deleted_files = set()
    for rev in xrange(max_rev + 1):
        info = {}
        info["rev"] = rev
        files = {}
        for f in svn.ls(rev=rev):
            f["deleted"] = False
            if f["name"] in deleted_files or f["size"] > MAX_FILE_SIZE:
                deleted_files.add(f["name"])
                f["deleted"] = True
            files[f["name"]] = f
        info["files"] = files
        print json.dumps(info)
Esempio n. 5
0
class SvnFlow:
    def __init__(self):
        self.svn = Svn(svn_utils.find_svn_root_path())

        self.trunk_dir = "trunk"
        self.tags_dir = "tags"
        self.branches_dir = "branches"
        self.develop_branch = os.path.join(self.branches_dir, "develop")
        self.feature_dir = os.path.join(self.branches_dir, "feature")
        self.release_dir = os.path.join(self.branches_dir, "release")
        self.hotfix_dir = os.path.join(self.branches_dir, "hotfix")

        self.branch_dir_by_type = {"feature" : self.feature_dir, \
         "release" : self.release_dir, \
         "hotfix" : self.hotfix_dir}

    def init(self):
        self.__create_dir(self.trunk_dir)
        self.__create_dir(self.branches_dir)
        self.__create_dir(self.tags_dir)

        self.__create_develop_branch()

        self.__create_dir(self.feature_dir)
        self.__create_dir(self.release_dir)
        self.__create_dir(self.hotfix_dir)

        self.svn.update_all()

    #
    # Returns 0 if no errors were encountered. Otherwise 1 is returned.
    #
    def test(self):
        retval = 0

        retval = self.__test_dir("trunk") or retval
        retval = self.__test_dir("tags") or retval

        retval = self.__test_dir(self.branches_dir) or retval

        retval = self.__test_dir(self.feature_dir) or retval
        retval = self.__test_dir(self.release_dir) or retval
        retval = self.__test_dir(self.hotfix_dir) or retval

        return retval

    def feature_start(self, name):
        self.__branch_start(name, "feature", self.develop_branch)

    def feature_finish(self, name):
        feature_branch = os.path.join(self.feature_dir, name)
        self.__raise_if_dir_invalid(feature_branch)

        self.svn.update_all()
        self.svn.merge(feature_branch, self.develop_branch, reintegrate=True)
        self.__commit_and_log("Merged feature '" + name + "' to develop.")

        self.svn.remove(feature_branch)
        self.__commit_and_log("Removed feature '" + name + "' branch.")
        self.svn.update_all()

    def feature_list(self):
        self.__branch_list("feature")

    def release_start(self, version):
        self.__branch_start(version, "release", self.develop_branch)

    def release_finish(self, version):
        release_branch = os.path.join(self.release_dir, version)
        self.__raise_if_dir_invalid(release_branch)

        self.svn.update_all()
        self.svn.merge(release_branch, self.trunk_dir)
        self.__commit_and_log("Merged release '" + version \
         + "' to trunk.")

        self.svn.update_all()
        tag_branch = os.path.join(self.tags_dir, version)
        tag_message = self.__get_tag_message()
        self.svn.tag(self.trunk_dir, tag_branch, tag_message)

        self.svn.update_all()
        self.svn.merge(release_branch, self.develop_branch, reintegrate=True)
        self.__commit_and_log("Merged release '" + version \
         + "' to develop.")

        self.svn.remove(release_branch)
        self.__commit_and_log("Removed release '" + version \
         + "' branch.")
        self.svn.update_all()

    def release_list(self):
        self.__branch_list("release")

    def hotfix_start(self, version):
        self.__branch_start(version, "hotfix", self.trunk_dir)

    def hotfix_finish(self, version):
        hotfix_branch = os.path.join(self.hotfix_dir, version)
        self.__raise_if_dir_invalid(hotfix_branch)

        self.svn.update_all()
        self.svn.merge(hotfix_branch, self.develop_branch)
        self.__commit_and_log("Merged hotfix '" + version \
         + "' to develop.")

        self.svn.update_all()
        self.svn.merge(hotfix_branch, self.trunk_dir, reintegrate=True)
        self.__commit_and_log("Merged hotfix '" + version + "' to trunk.")

        self.svn.update_all()
        tag_branch = os.path.join(self.tags_dir, version)
        tag_message = self.__get_tag_message()
        self.svn.tag(self.trunk_dir, tag_branch, tag_message)

        self.svn.remove(hotfix_branch)
        self.__commit_and_log("Removed hotfix '" + version + "' branch.")
        self.svn.update_all()

    def hotfix_list(self):
        self.__branch_list("hotfix")

    def __branch_list(self, branch_type):
        branches = self.svn.list(self.branch_dir_by_type[branch_type])
        if len(branches) < 1:
            print "No " + branch_type + " branches are present."
        else:
            print branch_type + " branches:"
            for b in branches:
                print "\t" + b[:-1]

    def __branch_start(self, name, branch_type, branch_off):
        branch_dir = self.branch_dir_by_type[branch_type]
        branch = os.path.join(branch_dir, name)
        if os.path.exists(self.svn.full_path(branch)):
            raise Exception(branch_type + " branch '" + branch \
             + "' already exists.")

        self.svn.update_all()
        self.svn.branch(branch_off, branch)
        self.__commit_and_log("Created " + branch_type + " branch '" \
         + name + "'.")
        self.svn.update_all()

    #
    # Reads tag message from stdin and returns the result.
    #
    def __get_tag_message(self):
        stdout.write("Tag message: ")
        return stdin.readline()[:-1]

    def __test_dir(self, dir_path):
        retval = 0

        try:
            self.__raise_if_dir_invalid(dir_path)
            self.__raise_if_not_exists(dir_path)

            log(dir_path + " [" + console_utils.text_green("OK") \
             + "]")
        except Exception, e:
            log(dir_path + " [" + console_utils.text_red("FAIL") \
             + "]")
            console_utils.print_error(str(e))
            retval = 1

        return retval