Beispiel #1
0
def walker_test2():
    baseDir = localize("L:\\ostwald\\tomcat")
    try:
        walker = InstanceWalker(baseDir)
    except:
        print sys.exc_type, sys.exc_value
    walker.walk(lambda i: getExportBaseDir(i))
Beispiel #2
0
 def rename(self, newName):
     dst = localize(os.path.join(os.path.dirname(self.path), newName))
     os.rename(self.path, dst)
     if (os.path.exists(dst)):
         self.path = dst
         print "framework_config file renamed as " + dst
     else:
         raise IOError, "framework_config file apparently not renamed to " + dst
Beispiel #3
0
def instance_test():
    path = "L:/ostwald/tomcat/tomcat"
    instancePath = localize(path)
    i = DcsInstance(instancepath)
    if i.isInstance():
        print i.toString()
    else:
        print "not an instance"
Beispiel #4
0
def test():
    # srcbase = "/Users/ostwald/devel/projects/dlese-tools-project/"
    # dstbase = "/Users/ostwald/devel/projects/tmp/dlese-tools-project/"

    #	srcbase = localize ("/devel/ostwald/projects/dlese-tools-project/")
    #   dstbase = localize ("/devel/ostwald/projects/archive/namespaces-051720006/dlese-tools-project/")

    srcbase = localize("/devel/ostwald/projects/roles")
    dstbase = localize("/devel/ostwald/projects/tmp/roles/")

    frag = "src/org/dlese/dpc/schemedit/action"
    src = os.path.join(srcbase, frag)
    dst = os.path.join(dstbase, frag)
    if 0:
        newer = dirCmp(src, dst)
        for path in newer:
            print os.path.split(path)[1]
    if 1:
        dirDiff(src, dst)
def show_users_stuff ():
	instancepath = localize ("/export/services/dcs/dcs.dlese.org/tomcat/noaa")
	instance = DcsInstance (instancepath)
	show_user_stuff (instance)
		
# report on all instances
def tomcat_user_walker (baseDir, fn):	
	"""
	run function on all instances
	"""
	InstanceWalker (baseDir).walk (fn)	
		
## --------------------------------------------------------
	
def show_users_stuff ():
	instancepath = localize ("/export/services/dcs/dcs.dlese.org/tomcat/noaa")
	instance = DcsInstance (instancepath)
	show_user_stuff (instance)

if __name__ == "__main__":
	baseDir = localize ("/export/services/dcs/dcs.dlese.org/tomcat")
	
	## show_users_stuff ()
	
	# report on all users
	# tomcat_user_walker (baseDir, tomcat_user_report)
	
	# report on single users (specified in call_back)
	tomcat_user_walker (baseDir, tomcat_single_user_report)




Beispiel #7
0
        'dlese_anno',
        'news_opps',
        'dlese_collect',
    ]
    for xmlFormat in xmlFormats:
        try:
            tool = FrameworkConfigTool(instance, xmlFormat)
        except IOError:
            print sys.exc_value
            print "\tcontinuing ...."
            continue
        path = tool.path
        tool.delete_file()
        if os.path.exists(path):
            print "file NOT deleted at " + path
        else:
            print "%s.xml deleted" % xmlFormat


## --------------------------------------------------------

if __name__ == "__main__":
    ## instancepath = localize ("L:/ostwald/tomcat/tomcat")
    instancepath = localize("/export/services/dcs/dcs.dlese.org/tomcat/roles")
    instance = DcsInstance(instancepath)
    # delete_configs (instance)

    # baseDir = localize ("L:\\ostwald\\tomcat")
    baseDir = localize("/export/services/dcs/dcs.dlese.org/tomcat")
    delete_framework_config_files(baseDir)
Beispiel #8
0
class DirectoryDiffer:
    """
	compares files in one "projects" directory against their counter parts in a parallel directory.
		projectsDir -- the working files
		cmpProjectsDir -- the files against which the working files are compared
	"""

    default_workingProjectsDir = localize(
        "/dpc/tremor/devel/ostwald/projects/tmp")
    # cvsProjectsDir = localize ("/dpc/tremor/devel/ostwald/projects/archive/namespaces-051720006")
    default_referenceProjectsDir = localize(
        "/dpc/tremor/devel/ostwald/projects")

    extensions = [
        ".java", ".jsp", ".jspf", ".tag", ".css", ".js", ".xml", ".html"
    ]

    def __init__(self,
                 path,
                 workingProjectsDir=None,
                 refProjectsDir=None,
                 verbose=0,
                 update=0,
                 recursive=0):
        self.path = path
        self.verbose = verbose
        self.update = update
        self.recursive = recursive
        if workingProjectsDir is None:
            self.workingProjectsDir = self.default_workingProjectsDir
        else:
            self.workingProjectsDir = workingProjectsDir

        if refProjectsDir is None:
            self.refProjectsDir = self.default_referenceProjectsDir
        else:
            self.refProjectsDir = refProjectsDir

        self.relative_path = self._get_relative_path()

        ## print "\npyDiffer\n\tworkDir: %s\n\trefDir: %s\n" % (self.workingProjectsDir, self.refProjectsDir)

        if update:
            self.updater()
        else:
            self.diff()

    def _get_relative_path(self):
        # check that the srcPath is within the projectsDir
        if self.path.find(self.workingProjectsDir) != 0:
            raise "illegal path: \n\t%s\nmust be within\n\t%s" % (
                self.path, self.workingProjectsDir)

        # calculate the delta path from projectsDir to srcPath
        return self.path[len(self.workingProjectsDir) + 1:]

    def diff(self):

        # print "\npath: %s\n" % frag

        workPath = self.path
        refPath = os.path.join(self.refProjectsDir, self.relative_path)
        # print "diff\n\t%s\n\t%s\n" % (workPath, refPath)
        if os.path.isdir(self.path):
            # print "Directory: ", path
            self.dir_diff(workPath, refPath)
        else:
            # filename = os.path.split (self.path)[1]
            # print "File: ", filename
            self.file_diff(workPath, refPath)

    def file_diff(self, workPath, refPath):
        """
		changes necessary to make srcPath like cmpPath
		"""
        os.system("diff %s %s" % (workPath, refPath))

    def dir_diff(self, workDir, refDir, verbose=0):
        """
		do a diff on all files in refDir that are different than the counterpart in workDir
		"""
        # print "comparing directories"
        print "\n------------------------\nDIFF %s\n----" % workDir
        changed = self.changed_files(workDir, refDir)
        if changed:
            print "Files with Differences"
            for filename in changed:
                if self.verbose:
                    print "\n%s\n%s" % ("-" * 50, filename)
                    self.file_diff(os.path.join(workDir, filename),
                                   os.path.join(refDir, filename))
                    ## os.system ("diff %s %s" % (workPath, refPath))
                else:
                    print "\t%s" % (filename)

        missing_files = self.missing_files(workDir, refDir)
        missing_dirs = self.missing_directories(workDir, refDir)
        if missing_files or missing_dirs:
            print "\nPresent in workDir but not in refDir"
            if missing_files:
                print "\tFiles"
                for f in missing_files:
                    print "\t\t" + f
            if missing_dirs:
                print "\tDirectories"
                for f in missing_dirs:
                    print "\t\t" + f

        missing_files = self.missing_files(refDir, workDir)
        missing_dirs = self.missing_directories(refDir, workDir)
        if missing_files or missing_dirs:
            print "\nPresent in refDir but not workDir"
            if missing_files:
                print "\tFiles"
                for f in missing_files:
                    print "\t\t" + f
            if missing_dirs:
                print "\tDirectories"
                for f in missing_dirs:
                    print "\t\t" + f

        if self.recursive:
            #recursively call updater on all directories
            for filename in os.listdir(refDir):
                if filename.upper() == "CVS": continue
                path = os.path.join(refDir, filename)
                workPath = os.path.join(workDir, filename)
                if os.path.isdir(path) and os.path.exists(workPath):
                    DirectoryDiffer(workPath,
                                    verbose=self.verbose,
                                    update=self.update,
                                    recursive=self.recursive)

    def updater(self):

        workDir = self.path
        refDir = os.path.join(self.refProjectsDir, self.relative_path)

        print "\n------------------------\nUPDATER - %s\n----" % workDir
        print "updating changed files in work directory"
        changed = self.changed_files(workDir, refDir)
        if changed:
            for filename in changed:
                copyfile(os.path.join(refDir, filename),
                         os.path.join(workDir, filename))
                print "\t%s" % filename
        else:
            print "\tno changed files found"

        print "inserting missing files into work directory"
        missing = self.missing_files(refDir, workDir)
        if missing:
            for filename in missing:
                copyfile(os.path.join(refDir, filename),
                         os.path.join(workDir, filename))
                print "\t%s" % filename
        else:
            print "\tthere are no missing files"

        if self.recursive:
            # get missing directory trees
            for filename in self.missing_directories(refDir, workDir):
                copytree(os.path.join(refDir, filename),
                         os.path.join(workDir, filename))
                print "\n\tcopied tree to ", filename

            #recursively call updater on all directories
            for filename in os.listdir(workDir):
                if filename.upper() == "CVS": continue
                path = os.path.join(workDir, filename)
                if os.path.isdir(path):
                    DirectoryDiffer(path,
                                    verbose=self.verbose,
                                    update=self.update,
                                    recursive=self.recursive)

    def changed_files(self, dir1, dir2):
        changed = []
        for filename in os.listdir(dir1):
            # print "\t", filename
            path1 = os.path.join(dir1, filename)
            root, ext = os.path.splitext(filename)
            if os.path.isdir (path1) or \
               filename[0] in ['.', '#'] or \
               filename[-1] in ['~']  or \
               ext not in self.extensions:
                continue
            path2 = os.path.join(dir2, filename)

            if os.path.exists (path2) and \
             open (path1, 'r').read() !=  open(path2, 'r').read():
                changed.append(filename)
        return changed

    def missing_files(self, dir1, dir2):
        """
		return list of files that are present in dir1 but missing in dir2
		"""
        missing = []
        if not os.path.exists(dir1): return missing
        for filename in os.listdir(dir1):
            # print "\t", filename
            path = os.path.join(dir1, filename)
            root, ext = os.path.splitext(filename)
            if os.path.isdir (path) or \
               filename[0] in ['.', '#'] or \
               filename[-1] in ['~']  or \
               ext not in self.extensions:
                continue

            if not os.path.exists(os.path.join(dir2, filename)):
                missing.append(filename)
        return missing

    def missing_directories(self, dir1, dir2):
        """
		return list of files that are present in dir1 but missing in dir2
		"""
        missing = []
        if not os.path.exists(dir1): return missing
        for filename in os.listdir(dir1):
            if filename.upper() == "CVS": continue
            # print "\t", filename
            path = os.path.join(dir1, filename)
            root, ext = os.path.splitext(filename)
            if not os.path.isdir(path): continue

            if not os.path.exists(os.path.join(dir2, filename)):
                missing.append(filename)
        return missing
def testGetSchemaLocation():
    path = localize(
        "L:\\ostwald\\tmp\\portableDCS\\records\\oai_dc\\1160751502837\\ES-000-000-000-056.xml"
    )
    record = XmlRecord(path)
    getSchemaLocation(record)
    for filename in os.listdir(dir):
        path = os.path.join(dir, filename)
        if os.path.isdir(path):
            print "dir: %s" % path
            walk(path)
        else:
            root, ext = os.path.splitext(filename)
            if not ext.upper() == ".XML":
                continue
            # print "file: %s" % path
            rec = XmlRecord(path=path)
            addSchemaLoc(getSchemaLocation(rec))


def testGetSchemaLocation():
    path = localize(
        "L:\\ostwald\\tmp\\portableDCS\\records\\oai_dc\\1160751502837\\ES-000-000-000-056.xml"
    )
    record = XmlRecord(path)
    getSchemaLocation(record)


if __name__ == "__main__":
    # path = localize ("L:\\ostwald\\tmp\\portableDCS\\records")
    # path = localize ("/devel/ostwald/SchemEdit/DCS_Installer/records")
    path = localize("/home/ostwald/tmp/records")
    walk(path)
    print "All Schema Locations"
    for loc in allSchemaLocs:
        print "\t", loc
Beispiel #11
0
def update_config_files():
    baseDir = localize("/export/services/dcs/dcs.dlese.org/tomcat")
    update_fn = show_anno_stuff
    walk_framework_config_files(baseDir, update_fn)
Beispiel #12
0
def show_roles_stuff():
    instancepath = localize("/export/services/dcs/dcs.dlese.org/tomcat/roles")
    instance = DcsInstance(instancepath)
    show_anno_stuff(instance)