I am creating an API using the python fastapi library. The API is running pick programs off the back of the various endpoints using the u2py library. There is an alias setup to ensure the universe python is being run rather than any other version. We change dir at os level before running u2py commands. This all works fine when the universe account has no menu in the login paragraph, otherwise it's getting stuck in the menu. An example code snippet below works if I run from python prompt at universe level but not if i run python from linux level. I think it's the @TTY I need to somehow set to 'phantom' stop it ending up in the menu, any thoughts how to achieve this?
import u2py
import os
os.chdir('/opt/universe')
f_UV_ACCOUNT = u2py.File('UV.ACCOUNT')
------------------------------
Neil Sherwood
Analyst Programmer
HSBC Global Services (UK) Limited
London GB
------------------------------
Neil,
There is a @variable in Basic called @U2PY to determine if you using python.
@U2PY
A string that returns the number of the Python level at which the current BASIC program is running. Without Python, @U2PY has the value of 0. With Python, @U2PY has the value of a positive integer (1, 2,3, ...).
Currently it does work in a paragraph, so could not be used in a login paragraph as @U2PY is not one of the allowed @ variables in a paragraph.
The reason you think on setting it to phantom, is because a common check in a LOGIN paragraph would be to test @TTY to see if it's set to PHANTOM and then avoid parts of the login paragraph. Such as in the uv account below.
LOGIN
0001 Paragraph
0002 IF @TTY = 'phantom' THEN GO END.OF.LOGIN
0003 MOTIF SYSADM.MENU
0004 END.OF.LOGIN:
Setting @TTY to 'phantom' is not a guarantee though, as other accounts may well have other tests such as the name of the user etc.
Without knowing every LOGIN paragraph that is in use on your system it's hard to give you a definitive answer on how to do what you are asking and of course if you are allowed to change them. I can think of a couple of ways but without knowing a lot more about your accounts I can't give you a one size fits all solution.
It will be interesting to see how others have solved this and it may require changes to LOGIN paragraphs themselves. Also in UniVerse you can programmatically set @TTY but you can't in UniData, so peoples solutions for the two databases may be different. I can think of one way that would be consisent between the two but it would require changes to the LOGIN paragraph.
------------------------------
Jonathan Smith
UniData ATS
Rocket Support
------------------------------
Neil,
There is a @variable in Basic called @U2PY to determine if you using python.
@U2PY
A string that returns the number of the Python level at which the current BASIC program is running. Without Python, @U2PY has the value of 0. With Python, @U2PY has the value of a positive integer (1, 2,3, ...).
Currently it does work in a paragraph, so could not be used in a login paragraph as @U2PY is not one of the allowed @ variables in a paragraph.
The reason you think on setting it to phantom, is because a common check in a LOGIN paragraph would be to test @TTY to see if it's set to PHANTOM and then avoid parts of the login paragraph. Such as in the uv account below.
LOGIN
0001 Paragraph
0002 IF @TTY = 'phantom' THEN GO END.OF.LOGIN
0003 MOTIF SYSADM.MENU
0004 END.OF.LOGIN:
Setting @TTY to 'phantom' is not a guarantee though, as other accounts may well have other tests such as the name of the user etc.
Without knowing every LOGIN paragraph that is in use on your system it's hard to give you a definitive answer on how to do what you are asking and of course if you are allowed to change them. I can think of a couple of ways but without knowing a lot more about your accounts I can't give you a one size fits all solution.
It will be interesting to see how others have solved this and it may require changes to LOGIN paragraphs themselves. Also in UniVerse you can programmatically set @TTY but you can't in UniData, so peoples solutions for the two databases may be different. I can think of one way that would be consisent between the two but it would require changes to the LOGIN paragraph.
------------------------------
Jonathan Smith
UniData ATS
Rocket Support
------------------------------
We have a universal menu program that is run from most of our accounts and I've just noticed there's already a check at the top of that program to see if the process has been kicked off by various types of non-user processes. It's checking the output of 'ps -lf' for various text, such as 'ansible' before exiting if found. I've added 'python' into the check list which seems a way round it. I tried using @U2PY in the basic program but didn't seem to be available regardless of where called from. We're using Universe 11.3.4
------------------------------
Neil Sherwood
Analyst Programmer
HSBC Global Services (UK) Limited
London GB
------------------------------