Imrao commited on
Commit
e4f17c6
·
1 Parent(s): 174e53c

ui fetch and gen

Browse files
Files changed (1) hide show
  1. app.py +30 -14
app.py CHANGED
@@ -59,22 +59,38 @@ async def get_rpk_info(filename: str):
59
  attrs_info = pyprt.get_rpk_attributes_info(rpk_path)
60
 
61
  formatted_attrs = []
62
- for attr in attrs_info:
63
- if hasattr(attr, 'get_name'):
64
- formatted_attrs.append({
65
- "name": attr.get_name(),
66
- "type": str(attr.get_type()),
67
- "defaultValue": attr.get_default_value(),
68
- })
69
- else:
70
- # Fallback implementation if specific attribute object not returned
71
- # This often happens if the RPK doesn't have exposed attributes or version mismatch
72
  formatted_attrs.append({
73
- "name": str(attr),
74
- "type": "string",
75
- "defaultValue": ""
76
  })
77
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
78
  return {"attributes": formatted_attrs}
79
  except Exception as e:
80
  logger.error(f"Error inspecting RPK: {e}")
 
59
  attrs_info = pyprt.get_rpk_attributes_info(rpk_path)
60
 
61
  formatted_attrs = []
62
+
63
+ # Handle Dictionary return type (common in some PyPRT versions)
64
+ if isinstance(attrs_info, dict):
65
+ for name, value in attrs_info.items():
66
+ # Determine type from value
67
+ attr_type = "string"
68
+ if isinstance(value, bool): attr_type = "bool"
69
+ elif isinstance(value, float): attr_type = "float"
70
+ elif isinstance(value, int): attr_type = "float" # Convert int to float for consistency
71
+
72
  formatted_attrs.append({
73
+ "name": name,
74
+ "type": attr_type,
75
+ "defaultValue": value
76
  })
77
+ # Handle List of Objects return type (standard PyPRT)
78
+ elif hasattr(attrs_info, '__iter__'):
79
+ for attr in attrs_info:
80
+ if hasattr(attr, 'get_name'):
81
+ formatted_attrs.append({
82
+ "name": attr.get_name(),
83
+ "type": str(attr.get_type()),
84
+ "defaultValue": attr.get_default_value(),
85
+ })
86
+ elif isinstance(attr, str):
87
+ # Fallback if list of strings
88
+ formatted_attrs.append({
89
+ "name": attr,
90
+ "type": "string",
91
+ "defaultValue": ""
92
+ })
93
+
94
  return {"attributes": formatted_attrs}
95
  except Exception as e:
96
  logger.error(f"Error inspecting RPK: {e}")