Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improved module dependencies #36

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
O.*/
*~
*.swp
*.pyc
*BAK.adl
cdCommands
envPaths
Expand Down
9 changes: 7 additions & 2 deletions configure/RULES_BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,21 @@ ifdef IOCADMIN

INSTALL_IOCRELEASE_DBS=$(IOCRELEASE_DB:%=$(INSTALL_DB)/%)

PYTHON=$(shell which python2)
ifneq ("python2","$(notdir $(PYTHON))")
PYTHON=python
endif

#--------------------------------------------------
# Rules

build : $(IOCRELEASE_DB)
buildInstall : $(INSTALL_IOCRELEASE_DBS)

# Create database for module version PVs
$(IOCRELEASE_DB) : $(TOP)/configure/RELEASE $(TOP)/RELEASE_SITE
$(IOCRELEASE_DB) : $(TOP)/configure/RELEASE
$(RM) $@
$(IOCADMIN)/bin/$(EPICS_HOST_ARCH)/iocReleaseCreateDb.py $^ >$@
$(PYTHON) $(IOCADMIN)/bin/$(EPICS_HOST_ARCH)/iocReleaseCreateDb.py $^ > $@

$(INSTALL_DB)/%: %
@echo "Installing db file $@"
Expand Down
2 changes: 2 additions & 0 deletions iocAdmin/src/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ DBD += iocAdmin.dbd
#=============================

SCRIPTS_HOST += iocReleaseCreateDb.py
SCRIPTS_HOST += pkgNamesToMacroNames.py
SCRIPTS_HOST += version_utils.py

#LIBRARY = iocAdmin

Expand Down
117 changes: 26 additions & 91 deletions iocAdmin/src/iocReleaseCreateDb.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,33 +1,35 @@
#!/usr/bin/env python
#!/usr/bin/python2

import sys
import os
import subprocess
import optparse
from pkgNamesToMacroNames import *
from version_utils import *

__all__ = ['export_db_file', 'process_options']

__all__ = ['export_db_file', 'module_versions', 'process_options']


def export_db_file(module_versions, path=None):
def export_db_file( module_versions, path=None):
"""
Use the contents of a dictionary of module versions to create a database
of module release stringin PVs. The database
of module release stringin PVs. The database
is written to stdout if path is not provided or is None.
"""

out_file = sys.stdout
idx = 0
idxMax = 20
idxMax = 30

if path:
try:
out_file = open(path, 'w')
except IOError, e:
sys.stderr.write('Could not open "%s": %s\n' % (path, e.strerror))
return None

sorted_module_versions = [(key, module_versions[key]) for key in sorted(module_versions.keys())]
# Create a sorted list of versions
sorted_module_versions = [(key, module_versions[key]) for key in sorted(module_versions.keys())]

print >> out_file, '#=============================================================================='
print >> out_file, '#'
Expand All @@ -43,15 +45,16 @@ def export_db_file(module_versions, path=None):
strip off the _MODULE_VERSION from key for PV NAME
"""
x = key.replace("_MODULE_VERSION","",1)
if idx >= idxMax: break
if idx >= idxMax:
break
print >> out_file, 'record(stringin, "$(IOC):RELEASE%02d") {' % idx
print >> out_file, ' field(DESC, "%s")' % x
print >> out_file, ' field(PINI, "YES")'
print >> out_file, ' field(VAL, "%s")' % module_version
print >> out_file, ' #field(ASG, "some read only grp")'
print >> out_file, '}'
idx = idx + 1

while idx < idxMax:
print >> out_file, 'record(stringin, "$(IOC):RELEASE%02d") {' % idx
print >> out_file, ' field(DESC, "Not Applicable")'
Expand All @@ -60,79 +63,9 @@ def export_db_file(module_versions, path=None):
print >> out_file, ' #field(ASG, "some read only grp")'
print >> out_file, '}'
idx = idx + 1

if out_file != sys.stdout:
out_file.close()


def module_versions(release_path, site_path):
"""
Return a dictionary containing module names and versions.
"""

# first grab EPICS_BASE_VER from RELEASE_SITE file, if it's there
siteBaseVer = "Nada"
openSiteFile = 1

try:
site_file = open(site_path, 'r')
except IOError, e:
#sys.stderr.write('Could not open "%s": %s\n' % (site_path, e.strerror))
openSiteFile = 0

if openSiteFile:
for line in site_file:
# Remove comments
line = line.partition('#')[0]

# Turn 'a = b' into a key/value pair and remove leading and trailing whitespace
(key, sep, value) = line.partition('=')
key = key.strip()
value = value.strip()

# save EPICS_BASE_VER, if it's in there
if key.startswith('EPICS_BASE_VER'):
siteBaseVer = value
break

site_file.close()

# now get all the modules
try:
release_file = open(release_path, 'r')
except IOError, e:
sys.stderr.write('Could not open "%s": %s\n' % (release_path, e.strerror))
return None

release_file_dict = {}

for line in release_file:
# Remove comments
line = line.partition('#')[0]

# Turn 'a = b' into a key/value pair and remove leading and trailing whitespace
(key, sep, value) = line.partition('=')
key = key.strip()
value = value.strip()

# Add the key/value pair to the dictionary if the key ends with _MODULE_VERSION
if key.endswith('_MODULE_VERSION'):
# if BASE_MODULE_VERSION is set to EPICS_BASE_VER macro from RELEASE_SITE,
# capture it here
if key == "BASE_MODULE_VERSION" and value == "$(EPICS_BASE_VER)":
if siteBaseVer != "Nada":
release_file_dict[key] = siteBaseVer
else:
# don't set BASE at all
pass
else:
release_file_dict[key] = value

release_file.close()


return release_file_dict


def process_options(argv):
"""
Expand All @@ -143,9 +76,8 @@ def process_options(argv):
if argv is None:
argv = sys.argv[1:]

# usage = 'Usage: %prog RELEASE_FILE [options]'
usage = 'Usage: %prog RELEASE_FILE RELEASE_SITE_FILE [options]'
version = '%prog 0.1'
usage = 'Usage: %prog RELEASE_FILE [options]'
version = '%prog 0.2'
parser = optparse.OptionParser(usage=usage, version=version)

parser.add_option('-v', '--verbose', action='store_true', dest='verbose', help='print verbose output')
Expand All @@ -156,22 +88,25 @@ def process_options(argv):

(options, args) = parser.parse_args(argv)

if len(args) != 2:
if len(args) != 1:
parser.error("incorrect number of arguments")

options.release_file_path = os.path.normcase(args[0])
options.release_site_file_path = os.path.normcase(args[1])

return options

return options

def main(argv=None):
options = process_options(argv)
versions = module_versions(options.release_file_path, options.release_site_file_path)
export_db_file(versions, options.db_file)

# get the IOC dependents
topDir = os.path.abspath( os.path.dirname( os.path.dirname(options.release_file_path) ) )
dependents = getEpicsPkgDependents( topDir )

# export the iocRelease.db file
export_db_file( dependents, options.db_file)

return 0


if __name__ == '__main__':
status = main()
Expand Down
Loading