2015-02-19 05:42:41 +07:00
|
|
|
#!/usr/bin/env python3
|
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
|
2013-12-26 17:31:43 +07:00
|
|
|
#
|
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.
|
2013-12-26 17:31:43 +07:00
|
|
|
#
|
2008-07-24 10:08:55 +07:00
|
|
|
# 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.
|
2013-12-26 17:31:43 +07:00
|
|
|
#
|
2008-07-24 10:08:55 +07:00
|
|
|
# You should have received a copy of the GNU General Public License
|
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2013-12-26 17:31:43 +07:00
|
|
|
#
|
2008-07-24 10:08:55 +07:00
|
|
|
# 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
|
2014-01-11 05:21:41 +07:00
|
|
|
version = "1.3"
|
2010-03-21 07:55:32 +07:00
|
|
|
|
|
|
|
|
2010-06-21 16:02:47 +07:00
|
|
|
def printver(exit=True):
|
2015-02-19 05:42:41 +07:00
|
|
|
print ("Relational %s" % version)
|
|
|
|
print ("Copyright (C) 2008 Salvo 'LtWorf' Tomaselli.")
|
|
|
|
print ()
|
|
|
|
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 ()
|
|
|
|
print ("Written by Salvo 'LtWorf' Tomaselli <tiposchi@tiscali.it>")
|
|
|
|
print ()
|
|
|
|
print ("http://ltworf.github.io/relational/")
|
2010-06-21 16:02:47 +07:00
|
|
|
if exit:
|
|
|
|
sys.exit(0)
|
2010-03-21 07:55:32 +07:00
|
|
|
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2010-03-21 07:55:32 +07:00
|
|
|
def printhelp(code=0):
|
2015-02-19 05:42:41 +07:00
|
|
|
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")
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2011-03-04 06:18:22 +07:00
|
|
|
if sys.argv[0].endswith('relational-cli'):
|
2015-02-19 05:42:41 +07:00
|
|
|
print (" -q Uses QT user interface")
|
|
|
|
print (" -r Uses readline user interface (default)")
|
2011-03-04 06:18:22 +07:00
|
|
|
else:
|
2015-02-19 05:42:41 +07:00
|
|
|
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'):
|
2013-12-26 17:31:43 +07:00
|
|
|
x11 = False
|
2011-03-04 06:18:22 +07:00
|
|
|
else:
|
2013-12-26 17:31:43 +07:00
|
|
|
x11 = True # Will try to use the x11 interface
|
|
|
|
|
|
|
|
# Getting command line
|
2010-03-21 07:55:32 +07:00
|
|
|
try:
|
2013-12-26 17:31:43 +07:00
|
|
|
switches, files = getopt.getopt(sys.argv[1:], "vhqr")
|
2010-03-21 07:55:32 +07:00
|
|
|
except:
|
|
|
|
printhelp(1)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2010-03-21 07:55:32 +07:00
|
|
|
for i in switches:
|
2013-12-26 17:31:43 +07:00
|
|
|
if i[0] == '-v':
|
2010-03-21 07:55:32 +07:00
|
|
|
printver()
|
2013-12-26 17:31:43 +07:00
|
|
|
elif i[0] == '-h':
|
2010-03-21 07:55:32 +07:00
|
|
|
printhelp()
|
2013-12-26 17:31:43 +07:00
|
|
|
elif i[0] == '-q':
|
|
|
|
x11 = True
|
|
|
|
elif i[0] == '-r':
|
|
|
|
x11 = False
|
|
|
|
|
2010-03-21 07:55:32 +07:00
|
|
|
if x11:
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2013-12-26 17:56:57 +07:00
|
|
|
import sip # needed on windows
|
2013-12-26 18:05:04 +07:00
|
|
|
from PyQt4 import QtGui
|
2011-03-21 02:43:57 +07:00
|
|
|
try:
|
2013-12-26 17:56:57 +07:00
|
|
|
from relational_gui import maingui, guihandler, about, surveyForm
|
2011-03-21 02:43:57 +07:00
|
|
|
except:
|
2013-12-26 17:56:57 +07:00
|
|
|
print >> sys.stderr, "Module relational_gui is missing.\nPlease install relational package."
|
|
|
|
sys.exit(3)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
|
|
|
about.version = version
|
|
|
|
surveyForm.version = version
|
|
|
|
guihandler.version = version
|
2009-08-18 06:52:33 +07:00
|
|
|
|
2010-03-21 07:55:32 +07:00
|
|
|
app = QtGui.QApplication(sys.argv)
|
2013-12-26 17:31:43 +07:00
|
|
|
app.setOrganizationName('None')
|
|
|
|
app.setApplicationName('relational')
|
|
|
|
|
2011-03-20 14:31:50 +07:00
|
|
|
ui = maingui.Ui_MainWindow()
|
|
|
|
Form = guihandler.relForm(ui)
|
2013-12-26 17:31:43 +07:00
|
|
|
|
|
|
|
# if os.name=='nt':
|
2011-03-20 14:31:50 +07:00
|
|
|
Form.setFont(QtGui.QFont("Dejavu Sans Bold"))
|
2013-12-26 17:31:43 +07:00
|
|
|
|
2010-03-21 07:55:32 +07:00
|
|
|
ui.setupUi(Form)
|
2013-12-26 17:16:12 +07:00
|
|
|
Form.restore_settings()
|
2013-12-26 17:31:43 +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)
|
2013-12-26 17:31:43 +07:00
|
|
|
f = files[i].split('/')
|
|
|
|
defname = f[len(f) - 1].lower()
|
|
|
|
if defname.endswith(".csv"): # removes the extension
|
|
|
|
defname = defname[:-4]
|
2015-02-19 05:42:41 +07:00
|
|
|
print ('Loading file "%s" with name "%s"' % (files[i], defname))
|
2013-12-26 17:31:43 +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)
|
2013-12-26 17:31:43 +07:00
|
|
|
relational_readline.linegui.version = version
|
2010-06-21 09:30:27 +07:00
|
|
|
relational_readline.linegui.main(files)
|