2008-07-23 08:20:49 +07:00
|
|
|
#!/usr/bin/env python
|
2009-02-26 07:18:02 +07:00
|
|
|
# -*- coding: utf-8 -*-
|
2008-07-24 10:08:55 +07:00
|
|
|
# coding=UTF-8
|
|
|
|
# Relational
|
|
|
|
# Copyright (C) 2008 Salvo "LtWorf" Tomaselli
|
|
|
|
#
|
2010-02-23 18:46:58 +07:00
|
|
|
# Relational is free software: you can redistribute it and/or modify
|
2008-07-24 10:08:55 +07:00
|
|
|
# it under the terms of the GNU General Public License as published by
|
|
|
|
# the Free Software Foundation, either version 3 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, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
# author Salvo "LtWorf" Tomaselli <tiposchi@tiscali.it>
|
2008-07-23 08:20:49 +07:00
|
|
|
|
|
|
|
import sys
|
2009-07-05 17:26:51 +07:00
|
|
|
import os
|
2010-06-21 07:33:43 +07:00
|
|
|
import os.path
|
2010-03-21 07:55:32 +07:00
|
|
|
import getopt
|
2009-02-26 07:18:02 +07:00
|
|
|
from relational import relation, parser
|
2011-03-22 15:54:55 +07:00
|
|
|
version="1.1"
|
2010-03-21 07:55:32 +07:00
|
|
|
|
|
|
|
|
2010-06-21 16:02:47 +07:00
|
|
|
def printver(exit=True):
|
|
|
|
print "Relational %s" % version
|
|
|
|
print "Copyright (C) 2008 Salvo 'LtWorf' Tomaselli."
|
|
|
|
print
|
2010-03-21 07:55:32 +07:00
|
|
|
print "This program comes with ABSOLUTELY NO WARRANTY."
|
|
|
|
print "This is free software, and you are welcome to redistribute it"
|
|
|
|
print "under certain conditions."
|
|
|
|
print "For details see the GPLv3 Licese."
|
|
|
|
print
|
2010-06-21 16:02:47 +07:00
|
|
|
print "Written by Salvo 'LtWorf' Tomaselli <tiposchi@tiscali.it>"
|
|
|
|
print
|
2011-03-04 06:18:22 +07:00
|
|
|
print "http://galileo.dmi.unict.it/wiki/relational/"
|
2010-06-21 16:02:47 +07:00
|
|
|
if exit:
|
|
|
|
sys.exit(0)
|
2010-03-21 07:55:32 +07:00
|
|
|
|
|
|
|
def printhelp(code=0):
|
|
|
|
print "Relational"
|
|
|
|
print
|
|
|
|
print "Usage: %s [options] [files]" % sys.argv[0]
|
|
|
|
print
|
|
|
|
print " -v Print version and exits"
|
|
|
|
print " -h Print this help and exits"
|
2011-03-04 06:18:22 +07:00
|
|
|
|
|
|
|
if sys.argv[0].endswith('relational-cli'):
|
|
|
|
print " -q Uses QT user interface"
|
|
|
|
print " -r Uses readline user interface (default)"
|
|
|
|
else:
|
|
|
|
print " -q Uses QT user interface (default)"
|
|
|
|
print " -r Uses readline user interface"
|
2010-03-21 07:55:32 +07:00
|
|
|
sys.exit(code)
|
2008-07-24 10:08:55 +07:00
|
|
|
|
2008-07-23 08:20:49 +07:00
|
|
|
if __name__ == "__main__":
|
2011-03-04 06:18:22 +07:00
|
|
|
if sys.argv[0].endswith('relational-cli'):
|
|
|
|
x11=False
|
|
|
|
else:
|
|
|
|
x11=True #Will try to use the x11 interface
|
2010-03-21 07:55:32 +07:00
|
|
|
|
|
|
|
#Getting command line
|
|
|
|
try:
|
2010-06-21 09:30:27 +07:00
|
|
|
switches,files=getopt.getopt(sys.argv[1:],"vhqr")
|
2010-03-21 07:55:32 +07:00
|
|
|
except:
|
|
|
|
printhelp(1)
|
|
|
|
|
|
|
|
for i in switches:
|
|
|
|
if i[0]=='-v':
|
|
|
|
printver()
|
|
|
|
elif i[0]=='-h':
|
|
|
|
printhelp()
|
|
|
|
elif i[0]=='-q':
|
|
|
|
x11=True
|
2010-06-21 09:30:27 +07:00
|
|
|
elif i[0]=='-r':
|
2010-03-21 07:55:32 +07:00
|
|
|
x11=False
|
2009-05-25 12:04:24 +07:00
|
|
|
|
2010-03-21 07:55:32 +07:00
|
|
|
if x11:
|
2011-10-08 12:05:07 +07:00
|
|
|
|
|
|
|
pyqt=True
|
|
|
|
|
2011-03-21 02:43:57 +07:00
|
|
|
try:
|
2011-10-08 12:05:07 +07:00
|
|
|
from PyQt4 import QtGui
|
2011-03-21 02:43:57 +07:00
|
|
|
except:
|
2011-10-08 12:05:07 +07:00
|
|
|
print >> sys.stderr, "PyQt seems to be missing, trying to use Pyside"
|
|
|
|
from PySide import QtCore, QtGui
|
|
|
|
pyqt=False
|
|
|
|
|
|
|
|
|
|
|
|
if pyqt:
|
|
|
|
try:
|
|
|
|
from relational_gui import maingui,guihandler, about, surveyForm
|
|
|
|
except:
|
|
|
|
print >> sys.stderr, "Module relational_gui is missing.\nPlease install relational package."
|
|
|
|
sys.exit(3)
|
|
|
|
else:
|
|
|
|
try:
|
|
|
|
from relational_pyside import maingui,guihandler, about, surveyForm
|
|
|
|
except:
|
|
|
|
print >> sys.stderr, "Module relational_pyside is missing.\nPlease install relational package."
|
|
|
|
sys.exit(3)
|
2011-05-18 03:17:05 +07:00
|
|
|
|
2011-03-21 02:43:57 +07:00
|
|
|
|
2010-03-21 07:55:32 +07:00
|
|
|
about.version=version
|
2011-01-10 11:51:19 +07:00
|
|
|
surveyForm.version=version
|
2011-06-14 11:21:15 +07:00
|
|
|
guihandler.version=version
|
2009-08-18 06:52:33 +07:00
|
|
|
|
2010-03-21 07:55:32 +07:00
|
|
|
app = QtGui.QApplication(sys.argv)
|
2011-03-20 14:31:50 +07:00
|
|
|
|
|
|
|
ui = maingui.Ui_MainWindow()
|
|
|
|
Form = guihandler.relForm(ui)
|
2010-03-21 07:55:32 +07:00
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
#if os.name=='nt':
|
|
|
|
Form.setFont(QtGui.QFont("Dejavu Sans Bold"))
|
|
|
|
|
2010-03-21 07:55:32 +07:00
|
|
|
ui.setupUi(Form)
|
2008-11-15 07:15:26 +07:00
|
|
|
|
2010-03-21 07:55:32 +07:00
|
|
|
for i in range(len(files)):
|
2010-06-21 07:33:43 +07:00
|
|
|
if not os.path.isfile(files[i]):
|
|
|
|
print >> sys.stderr, "%s is not a file" % files[i]
|
|
|
|
printhelp(12)
|
2010-03-21 07:55:32 +07:00
|
|
|
f=files[i].split('/')
|
|
|
|
defname=f[len(f)-1].lower()
|
2011-03-04 06:18:22 +07:00
|
|
|
if defname.endswith(".csv"): #removes the extension
|
2010-03-21 07:55:32 +07:00
|
|
|
defname=defname[:-4]
|
|
|
|
print 'Loading file "%s" with name "%s"' % (files[i],defname)
|
2011-03-20 14:31:50 +07:00
|
|
|
Form.loadRelation(files[i],defname)
|
2010-03-21 07:55:32 +07:00
|
|
|
|
|
|
|
Form.show()
|
|
|
|
sys.exit(app.exec_())
|
2010-06-21 12:05:31 +07:00
|
|
|
else:
|
2010-06-21 16:02:47 +07:00
|
|
|
printver(False)
|
2011-03-21 02:43:57 +07:00
|
|
|
try:
|
|
|
|
import relational_readline.linegui
|
|
|
|
except:
|
|
|
|
print >> sys.stderr, "Module relational_readline is missing.\nPlease install relational-cli package."
|
|
|
|
sys.exit(3)
|
2011-06-14 11:21:15 +07:00
|
|
|
relational_readline.linegui.version=version
|
2010-06-21 09:30:27 +07:00
|
|
|
relational_readline.linegui.main(files)
|
2010-06-21 12:05:31 +07:00
|
|
|
|