Exemplo n.º 1
0
    def initVersions(self):
        """Get and store versions.

        Initialize attributes that store the Webware and WebKit versions as
        both tuples and strings. These are stored in the Properties.py files.
        """
        from MiscUtils.PropertiesObject import PropertiesObject
        props = PropertiesObject(
            os.path.join(self.webwarePath(), 'Properties.py'))
        self._webwareVersion = props['version']
        self._webwareVersionString = props['versionString']
        props = PropertiesObject(
            os.path.join(self.webKitPath(), 'Properties.py'))
        self._webKitVersion = props['version']
        self._webKitVersionString = props['versionString']
Exemplo n.º 2
0
    def load(self):
        """ Loads the plug-in into memory, but does not yet install it. Will return None on success, otherwise a message (string) that says why the plug-in could not be loaded. """
        print 'Loading plug-in: %s at %s' % (self._name, self._path)

        assert os.path.exists(self._path)

        # Grab the Properties.py
        self._properties = PropertiesObject(
            self.serverSidePath('Properties.py'))
        if not self._properties['willRun']:
            return self._properties['willNotRunReason']

        # Update sys.path
        if not self._dir in sys.path:
            sys.path.append(self._dir)

        # Import the package
        self._module = __import__(self._name, globals(), [], [])

        # Inspect it and verify some required conventions
        if not hasattr(self._module, 'InstallInWebKit'):
            raise PlugInError, "Plug-in '%s' in '%s' has no InstallInWebKit() function." % (
                self._name, self._dir)

        # Give the module a pointer back to us
        setattr(self._module, 'plugIn', self)

        # Make a directory for it in Cache/
        cacheDir = os.path.join(self._appServer.serverSidePath(), 'Cache',
                                self._name)
        if not os.path.exists(cacheDir):
            os.mkdir(cacheDir)

        self.setUpExamplePages()
Exemplo n.º 3
0
 def version(self):
     """Return WebKit version."""
     if not hasattr(self, '_webKitVersionString'):
         from MiscUtils.PropertiesObject import PropertiesObject
         props = PropertiesObject(os.path.join(self.webKitPath(), 'Properties.py'))
         self._webKitVersionString = props['versionString']
     return self._webKitVersionString
Exemplo n.º 4
0
 def detectComponents(self):
     print 'Scanning for components...'
     filenames = os.listdir('.')
     maxLen = max(
         filter(
             None,
             map(lambda name: os.path.isdir(name) and len(name),
                 filenames)))
     count = 0
     needPrint = 0
     for filename in os.listdir('.'):
         if os.path.isdir(filename):
             propName = os.path.join(filename, 'Properties.py')
             displayName = string.ljust(filename, maxLen)
             if os.path.exists(propName):
                 comp = PropertiesObject(propName)
                 comp['filename'] = filename
                 self._comps.append(comp)
                 print '  yes', displayName,
             else:
                 print '   no', displayName,
             if count % 2 == 1:
                 print
                 needPrint = 0
             else:
                 needPrint = 1
             count = count + 1
     if needPrint:
         print
     print
     self._comps.sort(lambda a, b: cmp(a['name'], b['name']))
Exemplo n.º 5
0
 def __init__(self):
     self._props = PropertiesObject('Properties.py')
     self._props['dirname'] = '.'
     self._comps = []
     self._htHeader, self._htFooter = self.htHeaderAndFooter()
     from DocSupport.pytp import PyTP
     self._pytp = PyTP()
     from DocSupport.autotoc import AutoToC
     self._autotoc = AutoToC()
Exemplo n.º 6
0
    def initVersions(self):
        """Get and store versions.

        Initialize attributes that stores the Webware version as
        both tuple and string. These are stored in the Properties.py files.
        """
        from MiscUtils.PropertiesObject import PropertiesObject
        props = PropertiesObject(
            os.path.join(self.webwarePath(), 'Properties.py'))
        self._webwareVersion = props['version']
        self._webwareVersionString = props['versionString']
        if tuple(sys.version_info) < tuple(props['requiredPyVersion']):
            pythonVersion = '.'.join(map(str, sys.version_info))
            requiredVersion = props['requiredPyVersionString']
            raise RuntimeError(
                f' Required Python version is {requiredVersion},'
                f' but actual version is {pythonVersion}.')
Exemplo n.º 7
0
 def detectComponents(self):
     print
     print 'Scanning for components...'
     dirNames = [
         dir for dir in os.listdir(os.curdir)
         if not dir.startswith('.') and os.path.isdir(dir)
     ]
     self._maxCompLen = max(map(len, dirNames))
     oldPyVersion = False
     column = 0
     for dirName in sorted(dirNames):
         propName = dirName + '/Properties.py'
         try:
             print dirName.ljust(self._maxCompLen, '.'),
         except TypeError:
             print dirName.ljust(self._maxCompLen),
         if os.path.exists(propName):
             comp = PropertiesObject(propName)
             comp['dirname'] = dirName
             for key in self._props:
                 if key not in comp:
                     comp[key] = self._props[key]
             if sys.version_info[:3] < comp['requiredPyVersion']:
                 oldPyVersion = True
                 print 'no*',
             else:
                 self._comps.append(comp)
                 print 'yes',
         else:
             print 'no ',
         if column < 2 and not self._verbose:
             print '   ',
             column += 1
         else:
             print
             column = 0
     if column:
         print
     if oldPyVersion:
         print "* some components require a newer Python version"
     self._comps.sort(key=itemgetter('name'))
Exemplo n.º 8
0
	def release_current(self):

		progPath = os.path.join(os.getcwd(), sys.argv[0])  # the location of this script
		webwarePath = os.path.dirname(os.path.dirname(progPath))  # because we're in Webware/bin/
		parentPath = os.path.dirname(webwarePath)  # where the tarball will land

		self.chdir(webwarePath)

		if os.path.exists('_installed'):
			self.error('This Webware has already been installed.')

		from MiscUtils.PropertiesObject import PropertiesObject
		props = PropertiesObject(os.path.join(webwarePath, 'Properties.py'))
		ver = props['versionString']
		print 'Webware version is:', ver

		self.run('cvs update -dP')  # get new directories; prune empty ones

		try:
			tempName = os.tmpnam()
			os.mkdir(tempName)
			self.run('cp -pr %s %s' % (webwarePath, tempName))

			# Get rid of CVS files
			self.run("find %s -name '.cvs*' -exec rm {} \;" % tempName)
			self.run("rm -rf `find %s -name CVS -print`" % tempName)

			self.chdir(tempName)
			pkgName = 'Webware-%s.tar.gz' % ver
			self.run('tar czf %s Webware' % pkgName)

			# Put the results next to the Webware directory
			self.run('cp %s %s' % (pkgName, parentPath))

			assert os.path.exists(os.path.join(parentPath, pkgName))

		finally:
			# Clean up
			self.run('rm -rf %s' % tempName)

		self.writeGoodBye(locals())
Exemplo n.º 9
0
 def __init__(self, path=None, settings=None, development=None):
     ConfigurableForServerSidePath.__init__(self)
     if path is None:
         path = os.getcwd()
     self._serverSidePath = os.path.abspath(path)
     self._webwarePath = os.path.abspath(os.path.dirname(__file__))
     if development is None:
         development = bool(os.environ.get('WEBWARE_DEVELOPMENT'))
     self._development = development
     appConfig = self.config()
     if settings:
         appConfig.update(settings)
     self._cacheDir = self.serverSidePath(
         self.setting('CacheDir') or 'Cache')
     from MiscUtils.PropertiesObject import PropertiesObject
     props = PropertiesObject(
         os.path.join(self._webwarePath, 'Properties.py'))
     self._webwareVersion = props['version']
     self._webwareVersionString = props['versionString']
     self._imp = MockImportManager()
     for path in (self._cacheDir, ):
         if path and not os.path.exists(path):
             os.makedirs(path)
Exemplo n.º 10
0
    def load(self, verbose=True):
        """Loads the plug-in into memory, but does not yet install it.

        Will return None on success, otherwise a message (string) that says
        why the plug-in could not be loaded.
        """
        if verbose:
            print(f'Loading plug-in: {self._name} at {self._path}')

        # Grab the Properties.py
        self._properties = PropertiesObject(
            self.serverSidePath('Properties.py'))

        if self._builtin and 'version' not in self._properties:
            self._properties['version'] = self._app._webwareVersion
            self._properties['versionString'] = self._app._webwareVersionString

        if not self._properties['willRun']:
            return self._properties['willNotRunReason']

        # Update sys.path
        if self._dir not in sys.path:
            sys.path.append(self._dir)

        # Inspect it and verify some required conventions
        if not hasattr(self._module, 'installInWebware'):
            raise PlugInError(f"Plug-in '{self._name!r}' in {self._dir!r}"
                              " has no installInWebware() function.")

        # Give the module a pointer back to us
        setattr(self._module, 'plugIn', self)

        # Make a subdirectory for it in the Cache directory:
        if not os.path.exists(self._cacheDir):
            os.mkdir(self._cacheDir)

        self.setUpExamplePages()
Exemplo n.º 11
0
    def buildRelease(self):
        """Prepare a release by extracting files from the repository.

        You can specify a tag name on the command line, like

          > bin/ReleaseHelper.py tag=1.1.2

        This will extract the files tagged with 1.1.2 and build the
        tarball Webware-1.1.2.tar.gz in your parent directory.

        This means the release will match exactly what is in the repository,
        and reduces the risk of local changes, modified files, or new
        files which are not in the repository from showing up in the release.
        """

        tag = self._args.get('tag')
        pkg = self._args.get('pkg')
        pkgType = 'zip archive' if pkg == 'zip' else 'tarball'
        if tag:
            print "Creating %s from tag %s ..." % (pkgType, tag)
        else:
            print "Creating %s from current workspace..." % pkgType

        # the location of this script:
        progPath = os.path.join(os.getcwd(), sys.argv[0])
        # we assume this script is located in Webware/bin/
        webwarePath = os.path.dirname(os.path.dirname(progPath))
        # make the Webware directory our current directory
        self.chdir(webwarePath)
        # the tarball will land in its parent directory:
        tarDir = os.pardir

        if webwarePath not in sys.path:
            sys.path.insert(1, webwarePath)
        from MiscUtils.PropertiesObject import PropertiesObject

        target = 'Release'
        try:
            os.mkdir(target)
        except OSError:
            print "Staging directory already exists:", target
            print "Please remove this directory."
            return

        cleanup = [target]

        source = 'tags/%s' % tag if tag else 'HEAD'

        try:
            self.run('git archive %s | tar -x -C %s' % (source, target))
            if not os.path.exists(target):
                print "Unable to extract from %r" % source
                if tag:
                    print "Perhaps the tag %r does not exist." % tag
                self.error()
            propertiesFile = os.path.join(target, 'Properties.py')
            if not os.path.exists(propertiesFile):
                self.error('Properties.py not found.')
            props = PropertiesObject(propertiesFile)
            if props.get('name') != 'Webware for Python':
                self.error('This is not a Webware package.')
            ver = props['versionString']

            print "Webware version is:", ver

            if not tag:
                # timestamp for time of release used to in versioning the file
                year, month, day = time.localtime(time.time())[:3]
                datestamp = "%04d%02d%02d" % (year, month, day)
                # drop leading 2 digits from year. (Ok, itn's not Y2K but it
                # is short and unique in a narrow time range of 100 years.)
                datestamp = datestamp[2:]
                ver += "-" + datestamp
                print "Packaged release will be:", ver

            pkgDir = "Webware-%s" % ver

            if os.path.exists(pkgDir):
                self.error("%s is in the way, please remove it." % pkgDir)

            # rename the target to the pkgDir so the extracted parent
            # directory from the tarball will be unique to this package.
            self.run("mv %s %s" % (target, pkgDir))

            cleanup.append(pkgDir)

            pkgExt = '.zip' if pkg == 'zip' else '.tar.gz'
            pkgName = os.path.join(pkgDir + pkgExt)

            # cleanup .git files
            self.run("find %s -name '.git*' -exec rm {} \;" % pkgDir)

            # We could cleanup any other files not part of this release here.
            # (For instance, we could create releases without documentation).

            # We could also create additional files to be part of this release
            # without being part of the repository, for instance documentation
            # that is automatically created from markup.

            pkgPath = os.path.join(tarDir, pkgName)

            if os.path.exists(pkgPath):
                self.error("%s is in the way, please remove it." % pkgPath)

            tarCmd = 'zip -qr' if pkg == 'zip' else 'tar -czf'
            self.run('%s %s %s' % (tarCmd, pkgPath, pkgDir))

            if not os.path.exists(pkgPath):
                self.error('Could not create %s.' % pkgType)

        finally:  # Clean up
            for path in cleanup:
                if os.path.exists(path):
                    self.run('rm -rf ' + path)

        print
        print "file:", pkgName
        print "dir:", os.path.abspath(tarDir)
        print "size:", os.path.getsize(pkgPath), 'Bytes'
        print
        print 'Success.'
        print
Exemplo n.º 12
0
	def release_export(self):
		"""
		Prepare a release by using the cvs export approach.  This means the release will
		match exactly what is in CVS, and reduces the risk of local changes, modified
		files, or new files which are not in CVS from showing up in the release.

		Furthermore, this takes the version number from the checked out information.
		This means it is possible to specify a tag=cvstag on the command line and
		build a release associated with that tag.

		    > ReleaseHelper.py [tag=cvstag]

	        So specifying a CVS tag such as Release-0_7 will export the CVS files tagged
		with Release-0_7 and build Webware-0.7.tar.gz
		"""
		
		self.writeHello()
		self.checkPlatform()
		self.readArgs()

		progPath = os.path.join(os.getcwd(), sys.argv[0])  # the location of this script
		webwarePath = os.path.dirname(os.path.dirname(progPath))  # because we're in Webware/bin/
		parentPath = os.path.dirname(webwarePath)  # where the tarball will land
		if webwarePath not in sys.path:
			# insert in the path but ahead of anything that PYTHONPATH might
			# have created.
			sys.path.insert(1,webwarePath)

		self.chdir(webwarePath)
		from MiscUtils.PropertiesObject import PropertiesObject

		if self.args.has_key('tag'):
			dtag = '-r ' + self.args['tag']
			datestamp = ''
		else:
			# timestamp for tomorrow to insure we get latest data off
			# of the trunk.  Is this needed?
			year,month,day = time.gmtime(time.time()+3600*24)[:3]  
			dtag = '-D %04d-%02d-%02d' % (year,month,day)

			# timestamp for time of release used to in versioning the file.
			year,month,day = time.localtime(time.time())[:3]  
			datestamp = "%04d%02d%02d" % (year,month,day)

			# drop leading 2 digits from year. (Ok, itn's not Y2K but it is short
			# and unique in a narrow time range of 100 years.)
			datestamp = datestamp[2:]
			
			print "No cvs tag specified, assuming snapshot of CVS."
			
		tempName = "ReleaseHelper-Export"
		if os.path.exists( tempName ):
			print "There is incomplete ReleaseHelper data in:", tempName
			print "Please remove this directory."
			return 1
		
		cleanup = [ tempName ]
		
		try:
			self.run('cvs -z3 export %s -d %s Webware' % (dtag, tempName))
			if not os.path.exists( tempName ):
				print "** Unable to find the exported package.  Perhaps the tag %s does not exist." % \
				      self.args['tag']
				return 1
			props = PropertiesObject(os.path.join(webwarePath, tempName, 'Properties.py'))
			ver = props['versionString']

			print "Webware version is:", ver
			if datestamp:
				ver = ver + "-" + datestamp
				print "Packaged release will be:", ver

			pkgDir = "Webware-%s" % ver
			
			if os.path.exists(pkgDir):
				print "** %s is in the way, please remove it." % pkgDir
				return

			# rename the tempName to the pkgDir so the extracted parent
			# directory from the tarball will be unique to this package.
			self.run("mv %s %s" % (tempName, pkgDir))
			
			cleanup.append( pkgDir )
			
			pkgName = os.path.join(parentPath, pkgDir + ".tar.gz")

			# cleanup .cvs files
			self.run("find %s -name '.cvs*' -exec rm {} \;" % pkgDir)

			# cleanup any other files not part of this release. (ie: documentation?)

			# build any internal documentation for release.
			
			self.run('tar czf %s %s' % (pkgName, pkgDir))

			assert os.path.exists(os.path.join(parentPath, pkgName))

		finally:
			# Clean up
			for path in cleanup:
				if os.path.exists(path):
					self.run('rm -rf %s' % os.path.join(webwarePath, path))
			 
		self.writeGoodBye(locals())
Exemplo n.º 13
0
def main():
    po = PropertiesObject()
    po.loadValues(version=version, releaseDate=releaseDate)
    po.createVersionString()

    if po['versionString'] == 'X.Y':
        print "Please set the version."
        sys.exit(1)
    elif po['releaseDate'] == '@@/@@/@@':
        print "Please set the release Date."
        sys.exit(1)

    propReplace = Replacer()
    propReplace.add(r"(version\s*=)\s*.*", r"\g<1> %s" % repr(version))
    propReplace.add(r"(releaseDate\s*=)\s*.*", r"\g<1> %s" % repr(releaseDate))

    htmlReplace = Replacer()
    htmlReplace.add(
        r"<!--\s*version\s*-->[^<]*<!--\s*/version\s*-->",
        r"<!-- version --> %s <!-- /version -->" % po['versionString'])
    htmlReplace.add(
        r"<!--\s*relDate\s*-->[^<]*<!--\s*/relDate\s*-->",
        r"<!-- relDate --> %s <!-- /relDate -->" % po['releaseDate'])

    rstReplace = Replacer()
    rstReplace.add(r"^:Version:.*$", ":Version: %s" % po['versionString'])
    rstReplace.add(r"^:Released:.*$", ":Released: %s" % po['releaseDate'])

    phtmlReplace = Replacer()
    phtmlReplace.add(r"(<%.*)' \+ versionString \+ '(.*%>)",
                     r"\g<1>%s\g<2>" % po['versionString'])
    phtmlReplace.add(r"<% versionString %>", po['versionString'])
    phtmlReplace.add(r"<% releaseDate %>", po['releaseDate'])

    twillReplace = Replacer()
    twillReplace.add(r"^setglobal version .*$",
                     r"setglobal version %s" % po['versionString'])
    twillReplace.add(r"^setglobal date .*$",
                     r"setglobal date %s" % po['releaseDate'])
    twillReplace.add(r"^# if release ", '')

    if setVersion:

        # Replace in Properties files:
        propReplace.replaceGlob('Properties.py')
        propReplace.replaceGlob('*/Properties.py')

        # Replace in existing HTML:
        htmlReplace.replaceGlob('*/Docs/*.html')
        htmlReplace.replaceGlob('Docs/*.html')

        # Replace in reStructuredText files:
        rstReplace.replaceGlob('*/Docs/*.txt')
        rstReplace.replaceGlob('Docs/*.txt')

        # Replace in global README file:
        rstReplace.replaceGlob('_README')

        # Replace in twill test scripts:
        twillReplace.replaceGlob('WebKit/Tests/twill/*.twill')

    # Process release notes:

    if setVersion or newRelease:
        template = open('DocSupport/RelNotesTemplate.phtml', 'rb').read()
        infile = 'RelNotes-X.Y.phtml'
        outfile = infile.replace('X.Y', po['versionString'])
        for filename in ['Docs/' + infile] + glob('*/Docs/' + infile):
            if verbose:
                print "Processing " + filename
            current = open(filename, 'rb').read()
            if current == template:
                if newRelease:
                    print "Kept empty " + filename
                    continue
                else:
                    print "Removing empty " + filename
                    if os.system('git rm ' + filename):
                        print "git rm not possible."
                        os.remove(filename)
            else:
                if newRelease:
                    phtmlReplace.replaceInFile(filename)
                newName = os.path.join(os.path.split(filename)[0], outfile)
                print "Renaming %s to %s" % (filename, outfile)
                if os.system('git mv -f %s %s' % (filename, newName)):
                    print "git mv not possible."
                    os.rename(filename, newName)
                if newRelease:
                    print "Creating empty " + filename
                    open(filename, 'wb').write(template)
                    if os.system('git add ' + filename):
                        print "git add not possible."
Exemplo n.º 14
0
 def __init__(self):
     self._props = PropertiesObject('Properties.py')
     self._htHeader = self.htFragment('Header')
     self._htFooter = self.htFragment('Footer')
     self._comps = []