00001 from PyQt4.QtGui import *
00002 from PyQt4.QtCore import *
00003 from ost.gui import AdminRights
00004 import ost
00005 import os
00006
00007
00008 usage='''The DNG application bundle contains two shell commands ('ost' and 'dng') that lets you use the OpenStructure command-line interpreter and dng from the terminal. If you want to use these commands, it is recommended that a symbolic link is created.
00009 '''
00010 class TerminalUsageDialog(QDialog):
00011 def __init__(self, parent=None):
00012 QDialog.__init__(self, parent)
00013 self.setWindowTitle('Enhanced Terminal Usage')
00014 self.setFixedSize(QSize(480, 300))
00015 l=QVBoxLayout(self)
00016 title=QLabel('Enhanced Terminal Usage')
00017 font=title.font()
00018 font.setPointSize(20)
00019 title.setFont(font)
00020 l.addWidget(title)
00021 text=QLabel(usage)
00022 l.addWidget(text)
00023 l2=QHBoxLayout()
00024 l2.addWidget(QLabel('If you proceed, the link will be created in: '))
00025 self.path_combo=QComboBox()
00026 self.path_combo.setFixedWidth(150)
00027 for path in os.getenv('PATH').split(':'):
00028 exp_path=os.path.expanduser(path)
00029 if os.path.exists(exp_path) and exp_path.find('DNG.app')==-1:
00030 self.path_combo.addItem(path)
00031 l2.addWidget(self.path_combo)
00032 l.addLayout(l2)
00033 l3=QHBoxLayout()
00034 ab=QPushButton('Create Link')
00035 ab.setDefault(True)
00036 cb=QPushButton('Don\'t Create')
00037 l3.addStretch(1)
00038 l3.addWidget(cb, 0)
00039 l3.addWidget(ab, 0)
00040 l.addLayout(l3)
00041 text.setWordWrap(True)
00042 QObject.connect(cb, SIGNAL('clicked()'), self.reject)
00043 QObject.connect(ab, SIGNAL('clicked()'), self.accept)
00044 def GetSelectedPath(self):
00045 return str(self.path_combo.currentText())
00046
00047 def _CreateLinks(bin_dir, sel_dir):
00048 for bin in ('ost', 'dng','lddt', 'chemdict_tool'):
00049 if os.path.exists(os.path.join(sel_dir, bin)):
00050 os.unlink(os.path.join(sel_dir, bin))
00051 os.system('ln -s "%s" "%s"' % (os.path.join(bin_dir, bin),
00052 os.path.join(sel_dir, bin)))
00053 def InstallTerminalPrograms():
00054 """
00055 Installs symlinks to the 'ost' and 'dng' command line programs into a
00056 user-specified directory in the path.
00057 """
00058 term_use=TerminalUsageDialog()
00059 if term_use.exec_():
00060 prefix=ost.GetPrefixPath()
00061 bin_dir=os.path.join(prefix, 'bin')
00062 sel_path=term_use.GetSelectedPath()
00063 if not os.access(sel_path, os.W_OK):
00064 admin_rights=AdminRights()
00065 if admin_rights.Acquire():
00066 for bin in ('ost', 'dng', 'lddt', 'chemdict_tool'):
00067 admin_rights.CreateLink(os.path.join(bin_dir, bin),
00068 os.path.join(sel_path, bin))
00069 admin_rights.Release()
00070 else:
00071 _CreateLinks(bin_dir, sel_path)