OpenStructure
termuse.py
Go to the documentation of this file.
1 from PyQt5 import QtGui, QtCore, QtWidgets
2 from ost.gui import AdminRights
3 import ost
4 import os
5 #from ost.gui import AdminRights
6 
7 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.
8 '''
9 class TerminalUsageDialog(QtWidgets.QDialog):
10  def __init__(self, parent=None):
11  QtWidgets.QDialog.__init__(self, parent)
12  self.setWindowTitle('Enhanced Terminal Usage')
13  self.setFixedSize(QSize(480, 300))
14  l=QVBoxLayout(self)
15  title=QLabel('Enhanced Terminal Usage')
16  font=title.font()
17  font.setPointSize(20)
18  title.setFont(font)
19  l.addWidget(title)
20  text=QLabel(usage)
21  l.addWidget(text)
22  l2=QHBoxLayout()
23  l2.addWidget(QLabel('If you proceed, the link will be created in: '))
24  self.path_combopath_combo=QComboBox()
25  self.path_combopath_combo.setFixedWidth(150)
26  for path in os.getenv('PATH').split(':'):
27  exp_path=os.path.expanduser(path)
28  if os.path.exists(exp_path) and exp_path.find('DNG.app')==-1:
29  self.path_combopath_combo.addItem(path)
30  l2.addWidget(self.path_combopath_combo)
31  l.addLayout(l2)
32  l3=QHBoxLayout()
33  ab=QPushButton('Create Link')
34  ab.setDefault(True)
35  cb=QPushButton('Don\'t Create')
36  l3.addStretch(1)
37  l3.addWidget(cb, 0)
38  l3.addWidget(ab, 0)
39  l.addLayout(l3)
40  text.setWordWrap(True)
41  QObject.connect(cb, SIGNAL('clicked()'), self.reject)
42  QObject.connect(ab, SIGNAL('clicked()'), self.accept)
43  def GetSelectedPath(self):
44  return str(self.path_combopath_combo.currentText())
45 
46 def _CreateLinks(bin_dir, sel_dir):
47  for bin in ('ost', 'dng','lddt', 'chemdict_tool'):
48  if os.path.exists(os.path.join(sel_dir, bin)):
49  os.unlink(os.path.join(sel_dir, bin))
50  os.system('ln -s "%s" "%s"' % (os.path.join(bin_dir, bin),
51  os.path.join(sel_dir, bin)))
53  """
54  Installs symlinks to the 'ost' and 'dng' command line programs into a
55  user-specified directory in the path.
56  """
57  term_use=TerminalUsageDialog()
58  if term_use.exec_():
59  prefix=ost.GetPrefixPath()
60  bin_dir=os.path.join(prefix, 'bin')
61  sel_path=term_use.GetSelectedPath()
62  if not os.access(sel_path, os.W_OK):
63  admin_rights=AdminRights()
64  if admin_rights.Acquire():
65  for bin in ('ost', 'dng', 'lddt', 'chemdict_tool'):
66  admin_rights.CreateLink(os.path.join(bin_dir, bin),
67  os.path.join(sel_path, bin))
68  admin_rights.Release()
69  else:
70  _CreateLinks(bin_dir, sel_path)
def __init__(self, parent=None)
Definition: termuse.py:10
def InstallTerminalPrograms()
Definition: termuse.py:52
String DLLEXPORT_OST_BASE GetPrefixPath()
get the path prefix