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