Question

I am using Redhawk 1.9. I have created a Redhawk Device from the 1.8.4 IDE.

I import the default 1.8.4 device into the 1.9 IDE. I am able to run and build the 1.8.4 device in the 1.9 IDE. When I try to regenerate the code for 1.8.4 device, the IDE ask me if I want to upgrade to 1.9. The popup says "ConversionTestDevice uses deprecated code generators. Would you like to upgrade this project?". I decided to do an upgrade. I then get the following error message:

/usr/local/redhawk/core/bin/update_project returned with error code 1

Traceback (most recent call last): File "/usr/local/redhawk/core/bin/update_project", line 222, in ? if check_bulkio_input(compCpp): File "/usr/local/redhawk/core/bin/update_project", line 105, in check_bulkio_input for line in strip_comments(open(filename, 'r')): File "/usr/local/redhawk/core/bin/update_project", line 86, in strip_comments ch += safe_next(chars) File "/usr/local/redhawk/core/bin/update_project", line 56, in safe_next return next(item) NameError: global name 'next' is not defined

I would appreciate suggestions on how to convert 1.8.4 device to 1.9 device.

Was it helpful?

Solution

Based on your error message "NameError: global name 'next' is not defined" and the contents of the 1.9.0 release of update_project python script, I am assuming that you are running a version of python less than 2.6. The next function is a python builtin that was introduced in Python 2.6 (http://docs.python.org/2/library/functions.html#next). This is a known bug in the upgrade script as it should be compatible with Python 2.4 as well as Python 2.6 (The default python installations in CentOS 5 and 6 respectively). To fix this, you may modify the update_project script located in $OSSIEHOME/bin/update_project and define the following function:

if not hasattr(__builtins__, 'next'):
    # Python 2.4 does not have a free-standing next() function
    def next(iterator, default):
        """
        Backwards compatibility next() equivalent for Python 2.4.
        """
        try:
            return iterator.next()
        except StopIteration:
            return default

You should then remove the previously defined "safe_next" function.

Lastly, you need to replace the two calls to "safe_next" with a call to the newly implement next function and add a second argument of empty string ''

For clarity, a diff of update_project with these changes is below:

@@ -46,16 +46,16 @@ Options:

 _bulkio_re = re.compile('BULKIO_data[A-Za-z]+_In_i')

-def safe_next(item):
-    """
-    Returns the next value of the iterator, or an empty string if the end of
-    iteration has been reached. Allows string processing to gracefully handle
-    the end of a line without explicit catch statements.
-    """
-    try:
-        return next(item)
-    except StopIteration:
-        return ''
+if not hasattr(__builtins__, 'next'):
+    # Python 2.4 does not have a free-standing next() function
+    def next(iterator, default):
+        """
+        Backwards compatibility next() equivalent for Python 2.4.
+        """
+        try:
+            return iterator.next()
+        except StopIteration:
+            return default

 def strip_comments(source):
     """
@@ -75,7 +75,7 @@ def strip_comments(source):
                 # Look for end comment token; if the end of the line is reached
                 # ch will be an empty string
                 while ch == '*':
-                    ch = safe_next(chars)
+                    ch = next(chars, '')
                     if ch == '/':
                         inComment = False
                         break
@@ -83,7 +83,7 @@ def strip_comments(source):
             if ch == '/':
                 # Read the next character to see if it matches a comment token
                 # (if it does not, both characters will be added to the output)
-                ch += safe_next(chars)
+                ch += next(chars, '')
                 if ch == '/*':
                     # Comment, start discarding
                     inComment = True
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top