EZFIO/src/ezfio-tail.py

87 lines
2.0 KiB
Python
Raw Normal View History

2014-08-26 15:04:22 +02:00
# EZFIO is an automatic generator of I/O libraries
# Copyright (C) 2009 Anthony SCEMAMA, CNRS
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# Anthony Scemama
# LCPQ - IRSAMC - CNRS
# Universite Paul Sabatier
# 118, route de Narbonne
# 31062 Toulouse Cedex 4
# scemama@irsamc.ups-tlse.fr
ezfio = ezfio_obj()
2015-06-02 12:12:11 +02:00
def main():
import pprint
import sys
import os
try:
EZFIO_FILE = os.environ["EZFIO_FILE"]
except KeyError:
2020-01-27 11:32:17 +01:00
print("EZFIO_FILE not defined")
2015-06-02 12:12:11 +02:00
return 1
ezfio.set_file(EZFIO_FILE)
command = '_'.join(sys.argv[1:]).lower()
try:
f = getattr(ezfio,command)
except AttributeError:
2020-01-27 11:32:17 +01:00
print("{0} not found".format(command))
2015-06-02 12:12:11 +02:00
return 1
if command.startswith('has'):
if f(): return 0
else : return 1
elif command.startswith('get'):
result = f()
pprint.pprint( result, width=60, depth=3, indent=4 )
return 0
elif command.startswith('set'):
2019-01-04 18:16:14 +01:00
text = sys.stdin.read()
true = True
false = False
TRUE = True
FALSE = False
T = True
F = False
2015-06-02 12:12:11 +02:00
try:
2019-01-04 18:16:14 +01:00
data = eval(text)
except NameError:
data = text
2015-06-02 12:12:11 +02:00
except:
2020-01-27 11:32:17 +01:00
print("Syntax Error")
2015-06-02 12:12:11 +02:00
return 1
2019-01-16 18:01:07 +01:00
if data is None:
data = "None"
2015-06-02 12:12:11 +02:00
f(data)
return 0
else:
return 1
if __name__ == '__main__':
rc = main()
sys.exit(rc)