Esempio n. 1
0
def call_7zip(filepath, outdir, fileext):
    """Call 7zip to extract an archive.
       This uses a tempfile and the 'os' methods instead of
       the built-in functions open, close, and remove.
    """
    filepath = filepath.replace('\\', '/')
    prtfile = strip_directory_prefix(filepath)
    print("extract " + prtfile)
    exepath = libastyle.get_7zip_path()
    extract = [exepath, "x", "-r", "-y", "-o" + outdir, filepath]
    if __extract_all_files:
        print("extracting ALL files", )
    else:
        extract.extend(fileext)
        print("extracting " + str(fileext))
    # open a tempfile and access it with the 'os' methods
    fd, filename = tempfile.mkstemp(prefix="extract.",
                                    suffix=".tmp",
                                    dir=libastyle.get_temp_directory(),
                                    text=True)
    #	print(os.path.basename(filename))
    try:
        subprocess.check_call(extract, stdout=fd)
    except subprocess.CalledProcessError as err:
        libastyle.system_exit("Bad 7zip return: " + str(err.returncode))
    except OSError:
        libastyle.system_exit("Cannot find executable: " + exepath)
    os.close(fd)
    os.remove(filename)
Esempio n. 2
0
def call_7zip(filepath, outdir, fileext):
	"""Call 7zip to extract an archive.
	   This uses a tempfile and the 'os' methods instead of
	   the built-in functions open, close, and remove.
	"""
	filepath = filepath.replace('\\', '/')
	prtfile = strip_directory_prefix(filepath)
	print("extract " + prtfile)
	exepath = libastyle.get_7zip_path()
	extract = [exepath, "x", "-ry", "-o" + outdir, filepath]
	if __extract_all_files:
		print("extracting ALL files", )
	else:
		extract.extend(fileext)
		print("extracting " + str(fileext))
	# open a tempfile and access it with the 'os' methods
	fd, filename = tempfile.mkstemp(prefix="extract.", suffix=".tmp",
								dir=libastyle.get_temp_directory(), text=True)
#	print(os.path.basename(filename))
	try:
		subprocess.check_call(extract, stdout=fd)
	except subprocess.CalledProcessError as err:
		libastyle.system_exit("Bad 7zip return: " + str(err.returncode))
	except OSError:
		libastyle.system_exit("Cannot find executable: " + exepath)
	os.close(fd)
	os.remove(filename)
def build_testi18n_executable():
    """Build the Embarcadero AStyleTestI18n debug executable.
    """
    print("Building Embarcadero AStyleTestI18n Debug")
    # Compile the astyle executable for Windows.
    buildpath = "C:/Program Files (x86)/CodeBlocks/codeblocks.exe"
    if platform.architecture()[0] == "32bit":  # if running on a 32-bit system
        buildpath = buildpath.replace("Program Files (x86)", "Program Files")
    if not os.path.isfile(buildpath):
        message = "Cannot find CodeBlocks executable: " + buildpath
        libastyle.system_exit(message)
    print("Close the build window when finished ...")
    arg1 = "--build"
    arg2 = "--target=Debug"
    arg3 = "--no-batch-window-close"
    gmpath = __builddir + "/Bcc GTest Lib.cbp"
    gmbuild = ([buildpath, arg1, arg2, arg3, gmpath])
    cbpath = __builddir + "/Bcc AStyleTestI18n.cbp"
    cbbuild = ([buildpath, arg1, arg2, arg3, cbpath])
    buildfile = libastyle.get_temp_directory() + "/build.txt"
    outfile = open(buildfile, 'w')
    retvalgm = subprocess.call(gmbuild, stdout=outfile)
    if retvalgm:
        libastyle.system_exit("Bad gmbuild return: " + str(retvalgm))
    retvalcb = subprocess.call(cbbuild, stdout=outfile)
    if retvalcb:
        libastyle.system_exit("Bad cbbuild return: " + str(retvalcb))
    outfile.close()
    try:
        os.remove(buildfile)
    except PermissionError as err:
        libastyle.system_exit(str(err))
Esempio n. 4
0
def build_testi18n_executable():
	"""Build the Visual Studio AStyleTestI18n debug executable.
	"""
	print ("Building Visual Studio AStyleTestI18n Debug")
	# Compile the astyle executable for Windows.
	sdk = "v3.5"
	vsdir = "vs2008"
	if builddir.find("vs2010") != -1:
		sdk = "v4.0.30319"
		vsdir = "vs2010"
	# remove the cache file as a precaution
	cachepath = (builddir
			+ "/AStyle.sln.cache")
	if os.path.isfile(cachepath):
		os.remove(cachepath)
	# call MSBuild
	buildpath =  (os.getenv("WINDIR")
			+ "/Microsoft.NET/Framework/"
			+ sdk
			+ "/MSBuild.exe")
	configProp = "/property:Configuration=Debug"
	slnpath = (builddir
			+ "/AStyleTestI18n.sln")
	platform = "/property:Platform=Win32"
	msbuild = ([buildpath, configProp, platform, slnpath])
	buildfile = libastyle.get_temp_directory() + "/build.txt"
	outfile = open(buildfile, 'w')
	retval = subprocess.call(msbuild, stdout=outfile)
	if retval:
		libastyle.system_exit("Bad msbuild return: " + str(retval))
	outfile.close()
	os.remove(buildfile)
Esempio n. 5
0
def build_testi18n_executable():
    """Build the Embarcadero AStyleTestI18n debug executable.
    """
    print("Building Embarcadero AStyleTestI18n Debug")
    # Compile the astyle executable for Windows.
    buildpath = "C:/Program Files (x86)/CodeBlocks/codeblocks.exe"
    if not os.path.isfile(buildpath):
        message = "Cannot find CodeBlocks executable: " + buildpath
        libastyle.system_exit(message)
    print("Close the build window when finished ...")
    arg1 = "--build"
    arg2 = "--target=Debug"
    arg3 = "--no-batch-window-close"
    gmpath = __builddir + "/Bcc GTest Lib.cbp"
    gmbuild = ([buildpath, arg1, arg2, arg3, gmpath])
    cbpath = __builddir + "/Bcc AStyleTestI18n.cbp"
    cbbuild = ([buildpath, arg1, arg2, arg3, cbpath])
    buildfile = libastyle.get_temp_directory() + "/build.txt"
    outfile = open(buildfile, 'w')
    retvalgm = subprocess.call(gmbuild, stdout=outfile)
    if retvalgm:
        libastyle.system_exit("Bad gmbuild return: " + str(retval))
    retvalcb = subprocess.call(cbbuild, stdout=outfile)
    if retvalcb:
        libastyle.system_exit("Bad cbbuild return: " + str(retval))
    outfile.close()
    try:
        os.remove(buildfile)
    except PermissionError as err:
        libastyle.system_exit(str(err))
def build_testi18n_executable():
    """Build the Visual Studio AStyleTestI18n debug executable.
	"""
    print("Building Visual Studio AStyleTestI18n Debug")
    # Compile the astyle executable for Windows.
    sdk = "v3.5"
    vsdir = "vs2008"
    if "vs2010" in __builddir:
        sdk = "v4.0.30319"
        vsdir = "vs2010"
    # remove the cache file as a precaution
    cachepath = (__builddir + "/AStyle.sln.cache")
    if os.path.isfile(cachepath):
        os.remove(cachepath)
    # call MSBuild
    buildpath = (os.getenv("WINDIR") + "/Microsoft.NET/Framework/" + sdk +
                 "/MSBuild.exe")
    if not os.path.isfile(buildpath):
        message = "Cannot find MSBuild executable: " + buildpath
        libastyle.system_exit(message)
    configProp = "/property:Configuration=Debug"
    slnpath = (__builddir + "/AStyleTestI18n.sln")
    platform = "/property:Platform=Win32"
    msbuild = ([buildpath, configProp, platform, slnpath])
    buildfile = libastyle.get_temp_directory() + "/build.txt"
    outfile = open(buildfile, 'w')
    retval = subprocess.call(msbuild, stdout=outfile)
    if retval:
        libastyle.system_exit("Bad msbuild return: " + str(retval))
    outfile.close()
    os.remove(buildfile)
def compare_formatted_files(filepaths, num_excludes):
    """Walk thru the top-level directory tree
       and diff the files in the current and OLD directories.
       Returns a list of the files with a diff.
    """
    # process the filepaths
    totfiles = 0
    totdiffs = 0
    diffs = []
    print()
    if num_excludes > 0:
        print("Compare includes excluded files")
    fcfile = libastyle.get_temp_directory() + "/filecompare.txt"
    fcout = open(fcfile, 'w')
    testfile = "test-diff.txt"
    testout = open(testfile, 'w')
    for filepath in filepaths:
        testdir = libastyle.get_test_directory(True)
        print("Compare " + filepath[len(testdir):])
        dirname, unused = os.path.split(filepath)
        # get the extensions as a list (os.path.splitext doesn't work)
        sep = filepath.rfind('/')
        ext_text = filepath[sep + 1:]
        ext_text = ext_text.replace(';', ',')
        ext_text = ext_text.replace('*', '')
        ext_text = ext_text.replace(' ', '')
        extensions = ext_text.split(',')
        # walk thru the directory tree
        for dirpath, dirnames, filenames in os.walk(dirname):
            # Linux needs to be sorted to compare to Windows
            dirnames.sort()  # (key=str.lower) for case insensitive
            filenames.sort()
            # process each file in the directory
            for filename in filenames:
                unused, ext = os.path.splitext(filename)
                for pathext in extensions:
                    # compare only for the file extension requested
                    if ext == pathext:
                        totfiles += 1
                        filepath = os.path.join(dirpath, filename)
                        filepath = filepath.replace('\\', '/')
                        retval = call_file_compare_program(
                            filepath, testout, fcout)
                        if retval:
                            diffs.append(filepath)
                            totdiffs += 1
                        if totfiles % 100 == 0:
                            print("{0} files  {1} diffs".format(
                                totfiles, totdiffs))
                        break
        # print a total for each filepath
        print("{0} files  {1} diffs".format(totfiles, totdiffs))
    fcout.close()
    # files may not be removed due to an active process from a previous run
    try:
        os.remove(fcfile)
    except WindowsError as err:
        print(err)  # print error and continue
    testout.close()
    return diffs
Esempio n. 8
0
def compare_formatted_files(filepaths, num_excludes):
    """Walk thru the top-level directory tree
       and diff the files in the current and OLD directories.
       Returns a list of the files with a diff.
    """
    # process the filepaths
    totfiles = 0
    totdiffs = 0
    diffs = []
    print()
    if num_excludes > 0:
        print("Compare includes excluded files")
    fcfile = libastyle.get_temp_directory() + "/filecompare.txt"
    fcout = open(fcfile, 'w')
    testfile = "test-diff.txt"
    testout = open(testfile, 'w')
    for filepath in filepaths:
        testdir = libastyle.get_test_directory(True)
        print("Compare " + filepath[len(testdir):])
        dirname, unused = os.path.split(filepath)
        # get the extensions as a list (os.path.splitext doesn't work)
        sep = filepath.rfind('/')
        ext_text = filepath[sep + 1:]
        ext_text = ext_text.replace(';', ',')
        ext_text = ext_text.replace('*', '')
        ext_text = ext_text.replace(' ', '')
        extensions = ext_text.split(',')
        # walk thru the directory tree
        for dirpath, dirnames, filenames in os.walk(dirname):
            # Linux needs to be sorted to compare to Windows
            dirnames.sort()			# (key=str.lower) for case insensitive
            filenames .sort()
            # process each file in the directory
            for filename in filenames:
                unused, ext = os.path.splitext(filename)
                for pathext in extensions:
                    # compare only for the file extension requested
                    if ext == pathext:
                        totfiles += 1
                        filepath = os.path.join(dirpath, filename)
                        filepath = filepath.replace('\\', '/')
                        retval = call_file_compare_program(filepath, testout, fcout)
                        if retval:
                            diffs.append(filepath)
                            totdiffs += 1
                        if totfiles % 100 == 0:
                            print("{0} files  {1} diffs".format(totfiles, totdiffs))
                        break
        # print a total for each filepath
        print("{0} files  {1} diffs".format(totfiles, totdiffs))
    fcout.close()
    # files may not be removed due to an active process from a previous run
    try:
        os.remove(fcfile)
    except WindowsError as err:
        print(err)		# print error and continue
    testout.close()
    return diffs
Esempio n. 9
0
def call_7zip(filepath, outdir, fileext):
    """Call 7zip to extract an archive.
	"""
    filepath = filepath.replace('\\', '/')
    prtfile = strip_directory_prefix(filepath)
    print "extract " + prtfile
    exepath = libastyle.get_7zip_path()
    extract = [exepath, "x", "-ry", "-o" + outdir, filepath]
    if extract_all_files:
        extract.extend(fileext)
    filename = libastyle.get_temp_directory() + "/extract.txt"
    outfile = open(filename, 'w')
    retval = subprocess.call(extract, stdout=outfile)
    if retval:
        libastyle.system_exit("Bad 7zip return: " + str(retval))
    outfile.close()
    os.remove(filename)
Esempio n. 10
0
def test_all_functions():
    """Test all functions for syntax.
       This must be run from a console to test the 'diff' functions.
    """
    # write test file
    os.chdir(libastyle.get_file_py_directory())
    testfile = libastyle.get_temp_directory() + "libtest.txt"
    test_file_write(testfile)
    # begin tests -----------------------------------------
    files = get_formatted_files(testfile)
        # calls extract_directory_from_line()
    print("No files will be displayed in the comparison program.")
    diff_formatted_files(files)
        # calls call_diff_program()
        # calls strip_test_directory_prefix()
    get_astyle_totals(testfile)
    # end tests -------------------------------------------
    os.remove(testfile)
Esempio n. 11
0
def build_testi18n_executable():
    """Build the MinGW AStyleTestI18n debug executable.
	"""
    print "Building MinGW AStyleTestI18n Debug"
    print "Close the build window to continue ..."
    # Compile the astyle executable for Windows.
    buildpath = "C:/Program Files (x86)/CodeBlocks/codeblocks.exe"
    arg1 = "--build"
    arg2 = "--target=Debug"
    arg3 = "--no-batch-window-close"
    cbpath = testdir + "/MinGW AStyleTestI18n.workspace"
    cbbuild = ([buildpath, arg1, arg2, arg3, cbpath])
    buildfile = libastyle.get_temp_directory() + "/build.txt"
    outfile = open(buildfile, 'w')
    retval = subprocess.call(cbbuild, stdout=outfile)
    if retval:
        libastyle.system_exit("Bad cbbuild return: " + str(retval))
    outfile.close()
    os.remove(buildfile)
Esempio n. 12
0
def build_testi18n_executable():
	"""Build the Embarcadero AStyleTestI18n debug executable.
	"""
	print ("Building Embarcadero AStyleTestI18n Debug")
	print ("Close the build window to continue ...")
	# Compile the astyle executable for Windows.
	buildpath =  "C:/Program Files (x86)/CodeBlocks/codeblocks.exe"
	arg1 = "--build"
	arg2 = "--target=Debug"
	arg3 = "--no-batch-window-close"
	cbpath = builddir + "/EC AStyleTestI18n.workspace"
	cbbuild = ([buildpath, arg1, arg2, arg3, cbpath])
	buildfile = libastyle.get_temp_directory() + "/build.txt"
	outfile = open(buildfile, 'w')
	retval = subprocess.call(cbbuild, stdout=outfile)
	if retval:
		libastyle.system_exit("Bad cbbuild return: " + str(retval))
	outfile.close()
	os.remove(buildfile)
Esempio n. 13
0
def call_7zip(filepath, outdir, fileext):
	"""Call 7zip to extract an archive.
	"""
	filepath = filepath.replace('\\', '/')
	prtfile = strip_directory_prefix(filepath)
	print ("extract " + prtfile)
	exepath = libastyle.get_7zip_path()
	extract = [exepath, "x", "-ry", "-o" + outdir, filepath]
	if extract_all_files:
		print ("extracting ALL files")
	else:
		extract.extend(fileext)
		print ("extracting " + str(fileext))
	filename = libastyle.get_temp_directory() + "/extract.txt"
	outfile = open(filename, 'w')
	retval = subprocess.call(extract, stdout=outfile)
	if retval:
		libastyle.system_exit("Bad 7zip return: " + str(retval))
	outfile.close()
	os.remove(filename)
Esempio n. 14
0
def build_testi18n_executable():
    """Build the MinGW AStyleTestI18n debug executable.
	"""
    print("Building MinGW AStyleTestI18n Debug")
    # Compile the astyle executable for Windows.
    buildpath = "C:/Program Files/CodeBlocks/codeblocks.exe"
    if not os.path.isfile(buildpath):
        message = "Cannot find CodeBlocks executable: " + buildpath
        libastyle.system_exit(message)
    print("Close the build window when finished ...")
    arg1 = "--build"
    arg2 = "--target=Debug"
    arg3 = "--no-batch-window-close"
    cbpath = __builddir + "/MinGW AStyleTestI18n.workspace"
    cbbuild = ([buildpath, arg1, arg2, arg3, cbpath])
    buildfile = libastyle.get_temp_directory() + "/build.txt"
    outfile = open(buildfile, 'w')
    retval = subprocess.call(cbbuild, stdout=outfile)
    if retval:
        libastyle.system_exit("Bad cbbuild return: " + str(retval))
    outfile.close()
    os.remove(buildfile)
Esempio n. 15
0
def build_testi18n_executable():
	"""Build the MinGW AStyleTestI18n debug executable.
	"""
	print("Building MinGW AStyleTestI18n Debug")
	# Compile the astyle executable for Windows.
	buildpath =  "C:/Program Files/CodeBlocks/codeblocks.exe"
	if not os.path.isfile(buildpath):
		message = "Cannot find CodeBlocks executable: " + buildpath
		libastyle.system_exit(message)
	print("Close the build window when finished ...")
	arg1 = "--build"
	arg2 = "--target=Debug"
	arg3 = "--no-batch-window-close"
	cbpath = __builddir + "/MinGW AStyleTestI18n.workspace"
	cbbuild = ([buildpath, arg1, arg2, arg3, cbpath])
	buildfile = libastyle.get_temp_directory() + "/build.txt"
	outfile = open(buildfile, 'w')
	retval = subprocess.call(cbbuild, stdout=outfile)
	if retval:
		libastyle.system_exit("Bad cbbuild return: " + str(retval))
	outfile.close()
	os.remove(buildfile)