예제 #1
0
def update(paths, year):
    copyright_replacements = {
        f"(\\s*[*#]\\s+Copyright \\(c\\) 20\\d\\d-)(?!{year})20\\d\\d( Inviwo Foundation\\s*)":
        f"\\g<1>{year}\\g<2>",
        f"(\\s*[*#]\\s+Copyright \\(c\\) )((?!{year})20\\d\\d)( Inviwo Foundation\\s*)":
        f"\\g<1>\\g<2>-{year}\\g<3>"
    }

    files = refactoring.find_files(paths, ['*'], excludes=excludespatterns)
    print("Looking in {} files".format(len(files)))

    summary = ""
    for pattern, replacement in copyright_replacements.items():
        print("Matches: {}".format(pattern))
        matches = refactoring.find_matches(files, pattern)

        print("\nReplacing:")
        refactoring.replace_matches(matches, pattern, replacement)
        summary += "Replaced {} matches of {}\n".format(len(matches), pattern)

    print("\n")
    print(summary)
예제 #2
0
import sys
import os
import subprocess
import colorama
colorama.init()

import refactoring  # Note: refactoring.py need to be in the current working directory

paths = ["C:/Users/petst55.AD/Documents/Inviwo/inviwo"]

excludespatterns = [
    "*/ext/*", "*/templates/*", "*/tools/codegen/*", "*moc_*", "*cmake*"
]

files = refactoring.find_files(paths, ['*.h', '*.hpp', '*.cpp'],
                               excludes=excludespatterns)

for file in files:
    print("check " + file)
    with subprocess.Popen(["clang-format.exe", "-i", file],
                          stdout=subprocess.PIPE,
                          stderr=subprocess.STDOUT,
                          universal_newlines=True) as proc:
        for line in proc.stdout:
            print(line, end='', flush=True)
예제 #3
0
    "*.otf", "*.exe", "*.fbx", "*.svg", "*.itf", "*.qrc", "*.md", "*/.git*",
    "*/.clang-format", "*/LICENSE", ".git", "Jenkinsfile", ".gitattributes",
    "*/AUTHORS", ""
    "*/tools/meta/templates/*", "*.natvis", "*/depends.cmake",
    "*moduledefine.h", "*moduledefine.hpp", "*/config.json", "*.js",
    "*/CMakeLists.txt"
]

copyright_replacements = {
    r"(\s*[*#]\s+Copyright \(c\) 201\d-)201[12345678]( Inviwo Foundation\s*)":
    r"\g<1>2019\g<2>",
    r"(\s*[*#]\s+Copyright \(c\) )(201[12345678])( Inviwo Foundation\s*)":
    r"\g<1>\g<2>-2019\g<3>"
}

files = refactoring.find_files(paths, ['*'], excludes=excludespatterns)


def replace(pattern, replacement):
    print("Matches:")
    matches = refactoring.find_matches(files, pattern)

    print("\n")
    print("Replacing:")
    refactoring.replace_matches(matches, pattern, replacement)


print("Looking in " + str(len(files)) + " files")

for k, v in copyright_replacements.items():
    replace(k, v)
예제 #4
0
colorama.init()

import refactoring  # Note: refactoring.py need to be in the current working directory

paths = ["C:/inviwo-dev", "C:/inviwo-research/modules"]

# Step 1:
# replace:
# 	InviwoProcessorInfo();
# with:
# 	virtual const ProcessorInfo getProcessorInfo() const override;
# 	static const ProcessorInfo processorInfo_;

n = refactoring.find_files(paths, ['*.h'],
                           excludes=[
                               "*/ext/*", "*moc_*", "*cmake*",
                               "*/proteindocking/*", "*/proteindocking2/*",
                               "*/genetree/*"
                           ])

err = refactoring.check_file_type(n, "UTF-8")
if len(err) > 0: sys.exit("Encoding errors")

n2 = refactoring.find_files(paths, ['*.cpp'],
                            excludes=[
                                "*/ext/*", "*moc_*", "*cmake*",
                                "*/proteindocking/*", "*/proteindocking2/*",
                                "*/genetree/*"
                            ])

err2 = refactoring.check_file_type(n2, "UTF-8")
if len(err2) > 0: sys.exit("Encoding errors")
예제 #5
0
import sys 
import os
import re
import colorama
colorama.init()

import refactoring # Note: refactoring.py need to be in the current working directory

paths = ["C:/Users/petst55/Work/Inviwo/Inviwo-dev", "C:/Users/petst55/Work/Inviwo/Inviwo-research"]
excludespatterns = ["*/ext/*", "*moc_*", "*cmake*", "*/proteindocking/*", "*/proteindocking2/*", "*/genetree/*", "*/vrnbase/*"];

files = refactoring.find_files(paths, ['*.h', '*.cpp'], excludes=excludespatterns)

def replace(pattern, replacement) :
	print("Matches:")
	matches = refactoring.find_matches(files, pattern)
	
	print("\n")
	print("Replacing:")
	refactoring.replace_matches(matches, pattern, replacement)



serializerReplacements = {
	"IvwSerializeConstants::XML_VERSION" : "SerializeConstants::XmlVersion",
	"IvwSerializeConstants::INVIWO_TREEDATA" : "SerializeConstants::InviwoTreedata",
	"IvwSerializeConstants::INVIWO_VERSION" : "SerializeConstants::InviwoVersion",
	"IvwSerializeConstants::NETWORK_VERSION" : "SerializeConstants::NetworkVersion",
	"IvwSerializeConstants::VERSION" : "SerializeConstants::Version",
	"IvwSerializeConstants::EDIT_COMMENT" : "SerializeConstants::EditComment",
	"IvwSerializeConstants::ID_ATTRIBUTE" : "SerializeConstants::IDAttribute",
예제 #6
0
    "C:/Users/petst55.AD/Documents/Inviwo/inviwo-stage/modules"
    #  "C:/Users/petst55/Work/Inviwo/Inviwo-research",
    #  "C:/Users/petst55/Work/Inviwo/Inviwo-modules"
]
excludespatterns = ["*/ext/*", "*moc_*", "*/proteindocking/*", "*/proteindocking2/*",
                    "*/genetree/*", "*.DS_Store", "*DS_mapp", ".md", "*.suo", "*.h5",
                    "*.jpg", "*.JPG", "*.jpeg", "*.lib", "*.dll", "*.inv", "*.dat", "*.ivf",
                    "*.tiff", "*.png", "*.ttf", "*.tif", "*.pyc", "*.raw", "*.bmp", "*.wav",
                    "*.xcf", "*.ico", "*.icns", "*.qch", "*.qhc", "*.exr", "*.pwm", "*.pvm",
                    "*.pdf", "*.otf", "*.exe", "*.fbx", "*.svg", "*.itf", "*.qrc", "*.md",
                    "*/.git*", "*/.clang-format", "*/LICENSE", ".git", "Jenkinsfile",
                    ".gitattributes", "*/AUTHORS", "" "*/tools/meta/templates/*", "*.natvis",
                    "*/depends.cmake", "*moduledefine.h", "*moduledefine.hpp", "*/config.json",
                    "*.js", "*/CMakeLists.txt"]

files = refactoring.find_files(paths, extensions=['*.h', '*.hpp'],
                               excludes=excludespatterns)

copyright = r"^(?P<p1>\/[*]{81}\r?\n(?: [*].*?\r?\n){26} [*]{81}\/\r?\n)"
guard1 = r"\s*#ifndef (?P<guard>IVW_[A-Z0-9_]+)\r?\n#define (?P=guard)\r?\n"
code = r"(?P<p2>(?:.|\r?\n)+?)"
guard2 = r"\r?\n#endif\s+// (?P<end>[A-Z0-9_]+)\r?\n?$"

full = re.compile(copyright + guard1 + code + guard2, re.MULTILINE)
begin = re.compile(copyright + guard1, re.MULTILINE)
end = re.compile(guard2, re.MULTILINE)

haspragma = re.compile(r"#pragma once", re.MULTILINE)

for file in files:
    with codecs.open(file, 'r', encoding="UTF-8") as f:
        try:
예제 #7
0
import re
import colorama
colorama.init()

import refactoring # Note: refactoring.py need to be in the current working directory

paths = ["C:/inviwo-dev", "C:/inviwo-research/modules"]

# Step 1:
# replace:
# 	InviwoProcessorInfo();
# with:
# 	virtual const ProcessorInfo getProcessorInfo() const override;
# 	static const ProcessorInfo processorInfo_;

n = refactoring.find_files(paths, ['*.h'], excludes=["*/ext/*", "*moc_*", "*cmake*", "*/proteindocking/*", "*/proteindocking2/*", "*/genetree/*"])

err = refactoring.check_file_type(n, "UTF-8")
if len(err)>0: sys.exit("Encoding errors")

n2 = refactoring.find_files(paths, ['*.cpp'], excludes=["*/ext/*", "*moc_*", "*cmake*", "*/proteindocking/*", "*/proteindocking2/*", "*/genetree/*"])

err2 = refactoring.check_file_type(n2, "UTF-8")
if len(err2)>0: sys.exit("Encoding errors")

pattern = r"(\s*)InviwoProcessorInfo\(\);"
replacement = r"\1virtual const ProcessorInfo getProcessorInfo() const override;\n\1static const ProcessorInfo processorInfo_;"

print("Matches:")
matches = refactoring.find_matches(n, pattern)