Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
Diffstat (limited to 'releng/toolkit/cleaner.py')
-rwxr-xr-xreleng/toolkit/cleaner.py243
1 files changed, 135 insertions, 108 deletions
diff --git a/releng/toolkit/cleaner.py b/releng/toolkit/cleaner.py
index 0b6be0a45eb..e2768d11f38 100755
--- a/releng/toolkit/cleaner.py
+++ b/releng/toolkit/cleaner.py
@@ -1,4 +1,4 @@
-################################################################################
+# ###############################################################################
# Copyright (c) 2013 CEA LIST.
#
# All rights reserved. This program and the accompanying materials
@@ -9,112 +9,139 @@
# Contributors:
# Laurent Wouters laurent.wouters@cea.fr - Initial API and implementation
#
-################################################################################
-
-import os # File handling
-import os.path # File path handling
-import re # Regular expressions
-import shutil # File handling
-import sys # System
-import subprocess # Process handling
-import xml.dom.minidom # Minimal XML
-
-import console # Console pretty printing
-import eclipse # Eclipse API
-import xmlutils # XML utilities
-
-
-# Print how to use this script
-def printUsage():
- print("Usage:")
- print(" python cleaner.py [-h | --help] [--color] <targets>")
- print(" <targets> is the list of files and directories to clean")
- print("Options:")
- print(" -h, --help: print this screen")
- print(" --color: activate console color")
-
-
-# Cleanup the given bundle
-def cleanup(bundle):
- cleanupClasspath(bundle)
- cleanupBuildProperties(bundle)
-
-# Cleanup the bundle's class path
-def cleanupClasspath(bundle):
- subs = os.listdir(bundle.location)
- if not ".classpath" in subs:
- return
- doc = xml.dom.minidom.parse(os.path.join(bundle.location, ".classpath"))
- dirty = False
- for entry in doc.getElementsByTagName("classpathentry"):
- data = entry.getAttribute("excluding")
- folder = entry.getAttribute("path")
- if data is not None and len(data)>0:
- files = data.split("|")
- for file in files:
- if file is not None and len(file)>0:
- dirty = True
- full = os.path.join(bundle.location, os.path.join(folder, os.path.join(file)))
- print("Found " + full)
- if full.endswith("/"):
- subprocess.call(["git", "rm", "-r", full])
- else:
- subprocess.call(["git", "rm", full])
- entry.parentNode.removeChild(entry)
- if dirty:
- xmlutils.output(doc, os.path.join(bundle.location, ".classpath"))
- console.log("Bundle " + bundle.name + " => Fixed .classpath to remove excluded sources")
-
-# Cleanup the bundle's build properties
-def cleanupBuildProperties(bundle):
- subs = os.listdir(bundle.location)
- if not "build.properties" in subs:
- return
- properties = open(os.path.join(bundle.location, "build.properties"), "r")
- found = False
- for line in properties:
- if line.find("src.includes") != -1:
- found = True
- break
- properties.close()
- if not found:
- if not "about.html" in subs:
- shutil.copy("about.html", os.path.join(bundle.location, "about.html"))
- properties = open(os.path.join(bundle.location, "build.properties"), "a")
- properties.write("src.includes = about.html\n")
- properties.close()
- console.log("Bundle " + bundle.name + " => Fixed build.properties to add src.includes")
-
-# Execute the cleanup
-def execute(targets):
- # Build the repo
- repo = eclipse.Repository()
- for target in targets:
- repo.load(target)
- # Do the cleanup
- for name in repo.plugins:
- cleanup(repo.plugins[name])
- for name in repo.features:
- cleanup(repo.features[name])
+# ###############################################################################
+
+"""
+This script cleans up a repository of Eclipse features and plugins
+in order to improve their Tycho compatibility
+"""
+
+import os # File handling
+import os.path # File path handling
+import shutil # File handling
+import sys # System
+import subprocess # Process handling
+import xml.dom.minidom # Minimal XML
+
+import console # Console pretty printing
+import eclipse # Eclipse API
+import xmlutils # XML utilities
+
+
+def print_usage():
+ """
+ Print how to use this script
+ :return: None
+ """
+ print("Usage:")
+ print(" python cleaner.py [-h | --help] [--color] <targets>")
+ print(" <targets> is the list of files and directories to clean")
+ print("Options:")
+ print(" -h, --help: print this screen")
+ print(" --color: activate console color")
+
+
+def cleanup_bundle(bundle):
+ """
+ Cleanup the specified Eclipse bundle
+ :param bundle: An Eclipse bundle
+ :return: None
+ """
+ __cleanup_classpath(bundle)
+ __cleanup_build_properties(bundle)
+
+
+def __cleanup_classpath(bundle):
+ """
+ Cleanup the classpath of the specified Eclipse bundle
+ :param bundle: An Eclipse bundle
+ :return: None
+ """
+ subs = os.listdir(bundle.location)
+ if not ".classpath" in subs:
+ return
+ doc = xml.dom.minidom.parse(os.path.join(bundle.location, ".classpath"))
+ dirty = False
+ for entry in doc.getElementsByTagName("classpathentry"):
+ data = entry.getAttribute("excluding")
+ folder = entry.getAttribute("path")
+ if data is not None and len(data) > 0:
+ files = data.split("|")
+ for file in files:
+ if file is not None and len(file) > 0:
+ dirty = True
+ full = os.path.join(bundle.location, os.path.join(folder, os.path.join(file)))
+ print("Found " + full)
+ if full.endswith("/"):
+ subprocess.call(["git", "rm", "-r", full])
+ else:
+ subprocess.call(["git", "rm", full])
+ entry.parentNode.removeChild(entry)
+ if dirty:
+ xmlutils.output(doc, os.path.join(bundle.location, ".classpath"))
+ console.log("Bundle " + bundle.name + " => Fixed .classpath to remove excluded sources")
+
+
+def __cleanup_build_properties(bundle):
+ """
+ Cleanup the build properties of the specified Eclipse bunle
+ :param bundle: An Eclipse bundle
+ :return: None
+ """
+ subs = os.listdir(bundle.location)
+ if not "build.properties" in subs:
+ return
+ properties = open(os.path.join(bundle.location, "build.properties"), "r")
+ found = False
+ for line in properties:
+ if line.find("src.includes") != -1:
+ found = True
+ break
+ properties.close()
+ if not found:
+ if not "about.html" in subs:
+ shutil.copy("about.html", os.path.join(bundle.location, "about.html"))
+ properties = open(os.path.join(bundle.location, "build.properties"), "a")
+ properties.write("src.includes = about.html\n")
+ properties.close()
+ console.log("Bundle " + bundle.name + " => Fixed build.properties to add src.includes")
+
+
+def cleanup(directories):
+ """
+ Cleanup the Eclipse bundles in the specified directories
+ :param directories: A collection of directories
+ :return: None
+ """
+ # Build the repo
+ repo = eclipse.Repository()
+ for directory in directories:
+ repo.load(directory)
+ # Do the cleanup
+ for name in repo.plugins:
+ cleanup_bundle(repo.plugins[name])
+ for name in repo.features:
+ cleanup_bundle(repo.features[name])
+
# Main script
-if __name__=="__main__":
- # Checks the arguments
- nb = len(sys.argv)
- if nb <= 1:
- printUsage()
- sys.exit(1)
-
- targets = []
- # Parse the arguments
- for arg in sys.argv[1:]:
- if arg == "-h" or arg == "--help":
- printUsage()
- sys.exit(0)
- elif arg == console.CLI_COLOR:
- console.USE_COLOR = True
- else:
- targets.append(arg)
- # Execute
- code = execute(targets)
- sys.exit(code) \ No newline at end of file
+if __name__ == "__main__":
+ # Checks the arguments
+ nb = len(sys.argv)
+ if nb <= 1:
+ print_usage()
+ sys.exit(1)
+
+ targets = []
+ # Parse the arguments
+ for arg in sys.argv[1:]:
+ if arg == "-h" or arg == "--help":
+ print_usage()
+ sys.exit(0)
+ elif arg == console.CLI_COLOR:
+ console.USE_COLOR = True
+ else:
+ targets.append(arg)
+ # Execute
+ cleanup(targets)
+ sys.exit(0) \ No newline at end of file

Back to the top