-
Notifications
You must be signed in to change notification settings - Fork 1
/
info.py
1303 lines (1049 loc) · 59.6 KB
/
info.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
###############################################################################
# #
# Copyright (C) 2003-2015 Edward d'Auvergne #
# #
# This file is part of the program relax (http://www.nmr-relax.com). #
# #
# This program is free software: you can redistribute it and/or modify #
# 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/>. #
# #
###############################################################################
# Module docstring.
"""Module containing the introductory text container."""
# Dependencies.
import dep_check
# Python module imports.
if dep_check.ctypes_module:
import ctypes
if hasattr(ctypes, 'windll'):
import ctypes.wintypes
else:
ctypes = None
if dep_check.ctypes_structure_module:
from ctypes import Structure
else:
Structure = object
from os import environ, pathsep, waitpid
import platform
from re import search, sub
PIPE, Popen = None, None
if dep_check.subprocess_module:
from subprocess import PIPE, Popen
import sys
from textwrap import wrap
# relax module imports.
from status import Status; status = Status()
from version import repo_revision, repo_url, version, version_full
def print_sys_info():
"""Print out the system information."""
# Initialise the info box.
info = Info_box()
# Print all info.
print(info.sys_info())
class Info_box(object):
"""A container storing information about relax."""
# Class variable for storing the class instance.
instance = None
def __init__(self):
"""Create the program introduction text stings.
This class generates a container with the following objects:
- title: The program title 'relax'
- version: For example 'repository checkout' or '1.3.8'.
- desc: The short program description.
- copyright: A list of copyright statements.
- licence: Text pertaining to the licencing.
- errors: A list of import errors.
"""
# Program name and version.
self.title = "relax"
self.version = version
# The relax website.
self.website = "http://www.nmr-relax.com"
# Program description.
self.desc = "Molecular dynamics by NMR data analysis"
# Long description
self.desc_long = "The program relax is designed for the study of the dynamics of proteins or other macromolecules though the analysis of experimental NMR data. It is a community driven project created by NMR spectroscopists for NMR spectroscopists. It supports exponential curve fitting for the calculation of the R1 and R2 relaxation rates, calculation of the NOE, reduced spectral density mapping, and the Lipari and Szabo model-free analysis."
# Copyright printout.
self.copyright = []
self.copyright.append("Copyright (C) 2001-2006 Edward d'Auvergne")
self.copyright.append("Copyright (C) 2006-2015 the relax development team")
# Program licence and help.
self.licence = "This is free software which you are welcome to modify and redistribute under the conditions of the GNU General Public License (GPL). This program, including all modules, is licensed under the GPL and comes with absolutely no warranty. For details type 'GPL' within the relax prompt."
# ImportErrors, if any.
self.errors = []
if not dep_check.C_module_exp_fn:
self.errors.append(dep_check.C_module_exp_fn_mesg)
# References.
self._setup_references()
def __new__(self, *args, **kargs):
"""Replacement function for implementing the singleton design pattern."""
# First initialisation.
if self.instance is None:
self.instance = object.__new__(self, *args, **kargs)
# Already initialised, so return the instance.
return self.instance
def _setup_references(self):
"""Build a dictionary of all references useful for relax."""
# Initialise the dictionary.
self.bib = {}
# Place the containers into the dictionary.
self.bib['Bieri11'] = Bieri11()
self.bib['Clore90'] = Clore90()
self.bib['dAuvergne06'] = dAuvergne06()
self.bib['dAuvergneGooley03'] = dAuvergneGooley03()
self.bib['dAuvergneGooley06'] = dAuvergneGooley06()
self.bib['dAuvergneGooley07'] = dAuvergneGooley07()
self.bib['dAuvergneGooley08a'] = dAuvergneGooley08a()
self.bib['dAuvergneGooley08b'] = dAuvergneGooley08b()
self.bib['Delaglio95'] = Delaglio95()
self.bib['GoddardKneller'] = GoddardKneller()
self.bib['LipariSzabo82a'] = LipariSzabo82a()
self.bib['LipariSzabo82b'] = LipariSzabo82b()
def centre(self, string, width=100):
"""Format the string to be centred to a certain number of spaces.
@param string: The string to centre.
@type string: str
@keyword width: The number of characters to centre to.
@type width: int
@return: The centred string with leading whitespace added.
@rtype: str
"""
# Calculate the number of spaces needed.
spaces = int((width - len(string)) / 2)
# The new string.
string = spaces * ' ' + string
# Return the new string.
return string
def file_type(self, path):
"""Return a string representation of the file type.
@param path: The full path of the file to return information about.
@type path: str
@return: The single line file type information string.
@rtype: str
"""
# Python 2.3 and earlier.
if Popen == None:
return ''
# MS Windows (has no 'file' command or libmagic, so return nothing).
if hasattr(ctypes, 'windll'):
return ''
# The command.
cmd = "file -b '%s'" % path
# Execute.
pipe = Popen(cmd, shell=True, stdout=PIPE, close_fds=False)
waitpid(pipe.pid, 0)
# The STDOUT data.
data = pipe.stdout.readlines()
# Mac OS X 3-way binary.
if data[0][:-1] == 'Mach-O universal binary with 3 architectures':
# Arch.
arch = [None, None, None]
for i in range(3):
row = data[i+1].split('\t')
arch[i] = row[1][:-1]
arch.sort()
# The full file type printout.
if arch == ['Mach-O 64-bit executable x86_64', 'Mach-O executable i386', 'Mach-O executable ppc']:
file_type = '3-way exec (i386, ppc, x86_64)'
elif arch == ['Mach-O 64-bit bundle x86_64', 'Mach-O bundle i386', 'Mach-O bundle ppc']:
file_type = '3-way bundle (i386, ppc, x86_64)'
elif arch == ['Mach-O 64-bit dynamically linked shared library x86_64', 'Mach-O dynamically linked shared library i386', 'Mach-O dynamically linked shared library ppc']:
file_type = '3-way lib (i386, ppc, x86_64)'
elif arch == ['Mach-O 64-bit object x86_64', 'Mach-O object i386', 'Mach-O object ppc']:
file_type = '3-way obj (i386, ppc, x86_64)'
else:
file_type = '3-way %s' % arch
# Mac OS X 2-way binary.
elif data[0][:-1] == 'Mach-O universal binary with 2 architectures':
# Arch.
arch = [None, None]
for i in range(2):
row = data[i+1].split('\t')
arch[i] = row[1][:-1]
arch.sort()
# The full file type printout.
if arch == ['Mach-O executable i386', 'Mach-O executable ppc']:
file_type = '2-way exec (i386, ppc)'
elif arch == ['Mach-O bundle i386', 'Mach-O bundle ppc']:
file_type = '2-way bundle (i386, ppc)'
elif arch == ['Mach-O dynamically linked shared library i386', 'Mach-O dynamically linked shared library ppc']:
file_type = '2-way lib (i386, ppc)'
elif arch == ['Mach-O object i386', 'Mach-O object ppc']:
file_type = '2-way obj (i386, ppc)'
else:
file_type = '2-way %s' % arch
# Default to all info.
else:
file_type = data[0][:-1]
for i in range(1, len(data)):
row = data[i].split('\t')
arch[i] = row[1][:-1]
file_type += " %s" % arch
# Return the string.
return file_type
def format_max_width(self, data):
"""Return the text formatting width for the given data.
@param data: The list of things to print out.
@type data: list
@return: The maximum width of the elements in the list.
@rtype: int
"""
# Init.
width = 0
# Loop over the data.
for i in range(len(data)):
# The string representation size.
size = len(repr(data[i]))
# Find the max size.
if size > width:
width = size
# Return the max width.
return width
def intro_text(self):
"""Create the introductory string for STDOUT printing.
This text is word-wrapped to a fixed width of 100 characters (or 80 on MS Windows).
@return: The introductory string.
@rtype: str
"""
# Some new lines.
intro_string = '\n\n\n'
# Program name and version - subversion code.
if version == 'repository checkout':
text = "%s %s r%s" % (self.title, self.version, repo_revision)
text2 = "%s" % (repo_url)
intro_string = intro_string + self.centre(text, status.text_width) + '\n' + self.centre(text2, status.text_width) + '\n\n'
# Program name and version - official releases.
else:
text = "%s %s" % (self.title, self.version)
intro_string = intro_string + self.centre(text, status.text_width) + '\n\n'
# Program description.
intro_string = intro_string + self.centre(self.desc, status.text_width) + '\n\n'
# Copyright printout.
for i in range(len(self.copyright)):
intro_string = intro_string + self.centre(self.copyright[i], status.text_width) + '\n'
intro_string = intro_string + '\n'
# Program licence and help (wrapped).
for line in wrap(self.licence, status.text_width):
intro_string = intro_string + line + '\n'
intro_string = intro_string + '\n'
# Help message.
help = "Assistance in using the relax prompt and scripting interface can be accessed by typing 'help' within the prompt."
for line in wrap(help, status.text_width):
intro_string = intro_string + line + '\n'
# ImportErrors, if any.
for i in range(len(self.errors)):
intro_string = intro_string + '\n' + self.errors[i] + '\n'
intro_string = intro_string + '\n'
# The multi-processor message, if it exists.
if hasattr(self, 'multi_processor_string'):
for line in wrap('Processor fabric: %s\n' % self.multi_processor_string, status.text_width):
intro_string = intro_string + line + '\n'
# Return the formatted text.
return intro_string
def package_info(self):
"""Return a string for printing to STDOUT with info from the Python packages used by relax.
@return: The info string.
@rtype: str
"""
# Init.
text = ''
package = []
status = []
version = []
path = []
# Intro.
text = text + ("\nPython packages and modules (most are optional):\n\n")
# Header.
package.append("Name")
status.append("Installed")
version.append("Version")
path.append("Path")
# minfx.
package.append('minfx')
status.append(True)
if hasattr(dep_check.minfx, '__version__'):
version.append(dep_check.minfx.__version__)
else:
version.append('Unknown')
path.append(dep_check.minfx.__path__[0])
# bmrblib.
package.append('bmrblib')
status.append(dep_check.bmrblib_module)
try:
if hasattr(dep_check.bmrblib, '__version__'):
version.append(dep_check.bmrblib.__version__)
else:
version.append('Unknown')
except:
version.append('')
try:
path.append(dep_check.bmrblib.__path__[0])
except:
path.append('')
# numpy.
package.append('numpy')
status.append(True)
try:
version.append(dep_check.numpy.version.version)
path.append(dep_check.numpy.__path__[0])
except:
version.append('')
path.append('')
# scipy.
package.append('scipy')
status.append(dep_check.scipy_module)
try:
version.append(dep_check.scipy.version.version)
path.append(dep_check.scipy.__path__[0])
except:
version.append('')
path.append('')
# wxPython.
package.append('wxPython')
status.append(dep_check.wx_module)
try:
version.append(dep_check.wx.version())
path.append(dep_check.wx.__path__[0])
except:
version.append('')
path.append('')
# matplotlib.
package.append('matplotlib')
status.append(dep_check.matplotlib_module)
try:
version.append(dep_check.matplotlib.__version__)
path.append(dep_check.matplotlib.__path__[0])
except:
version.append('')
path.append('')
# mpi4py.
package.append('mpi4py')
status.append(dep_check.mpi4py_module)
try:
version.append(dep_check.mpi4py.__version__)
path.append(dep_check.mpi4py.__path__[0])
except:
version.append('')
path.append('')
# epydoc.
package.append('epydoc')
status.append(dep_check.epydoc_module)
try:
version.append(dep_check.epydoc.__version__)
path.append(dep_check.epydoc.__path__[0])
except:
version.append('')
path.append('')
# optparse.
package.append('optparse')
status.append(True)
try:
version.append(dep_check.optparse.__version__)
path.append(dep_check.optparse.__file__)
except:
version.append('')
path.append('')
# readline.
package.append('readline')
status.append(dep_check.readline_module)
version.append('')
try:
path.append(dep_check.readline.__file__)
except:
path.append('')
# profile.
package.append('profile')
status.append(dep_check.profile_module)
version.append('')
try:
path.append(dep_check.profile.__file__)
except:
path.append('')
# BZ2.
package.append('bz2')
status.append(dep_check.bz2_module)
version.append('')
try:
path.append(dep_check.bz2.__file__)
except:
path.append('')
# gzip.
package.append('gzip')
status.append(dep_check.gzip_module)
version.append('')
try:
path.append(dep_check.gzip.__file__)
except:
path.append('')
# IO.
package.append('io')
status.append(dep_check.io_module)
version.append('')
try:
path.append(dep_check.io.__file__)
except:
path.append('')
# XML.
package.append('xml')
status.append(dep_check.xml_module)
if dep_check.xml_module:
version.append("%s (%s)" % (dep_check.xml_version, dep_check.xml_type))
path.append(dep_check.xml.__file__)
else:
version.append('')
path.append('')
# XML minidom.
package.append('xml.dom.minidom')
version.append('')
try:
import xml.dom.minidom
status.append(True)
except:
status.append(False)
try:
path.append(xml.dom.minidom.__file__)
except:
path.append('')
# Format the data.
fmt_package = "%%-%ss" % (self.format_max_width(package) + 2)
fmt_status = "%%-%ss" % (self.format_max_width(status) + 2)
fmt_version = "%%-%ss" % (self.format_max_width(version) + 2)
fmt_path = "%%-%ss" % (self.format_max_width(path) + 2)
# Add the text.
for i in range(len(package)):
text += fmt_package % package[i]
text += fmt_status % status[i]
text += fmt_version % version[i]
text += fmt_path % path[i]
text += '\n'
# Return the info string.
return text
def processor_name(self):
"""Return a string for the processor name.
@return: The processor name, in much more detail than platform.processor().
@rtype: str
"""
# Python 2.3 and earlier.
if Popen == None:
return ""
# No subprocess module.
if not dep_check.subprocess_module:
return ""
# The system.
system = platform.system()
# Linux systems.
if system == 'Linux':
# The command to run.
cmd = "cat /proc/cpuinfo"
# Execute the command.
pipe = Popen(cmd, shell=True, stdout=PIPE, close_fds=False)
waitpid(pipe.pid, 0)
# Get the STDOUT data.
data = pipe.stdout.readlines()
# Loop over the lines, returning the first model name with the leading "model name :" text stripped.
for line in data:
# Decode Python 3 byte arrays.
if hasattr(line, 'decode'):
line = line.decode()
# Find the processor name.
if search("model name", line):
# Convert the text.
name = sub(".*model name.*:", "", line, 1)
name = name.strip()
# Return the name.
return name
# Windows systems.
if system == 'Windows' or system == 'Microsoft':
return platform.processor()
# Mac OS X systems.
if system == 'Darwin':
# Add the 'sysctl' path to the environment (if needed).
environ['PATH'] += pathsep + '/usr/sbin'
# The command to run.
cmd = "sysctl -n machdep.cpu.brand_string"
# Execute the command in a fail safe way, return the result or nothing.
try:
# Execute.
pipe = Popen(cmd, shell=True, stdout=PIPE, close_fds=False)
waitpid(pipe.pid, 0)
# Get the STDOUT data.
data = pipe.stdout.readlines()
# Decode Python 3 byte arrays.
string = data[0]
if hasattr(string, 'decode'):
string = string.decode()
# Find the processor name.
# Return the string.
return string.strip()
# Nothing.
except:
return ""
# Unknown.
return ""
def ram_info(self, format=" %-25s%s\n"):
"""Return a string for printing to STDOUT with info from the Python packages used by relax.
@keyword format: The formatting string.
@type format: str
@return: The info string.
@rtype: str
"""
# Python 2.3 and earlier.
if Popen == None:
return ''
# Init.
text = ''
# The system.
system = platform.system()
# Unix and GNU/Linux systems.
if system == 'Linux':
pipe = Popen('free -m', shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE, close_fds=False)
free_lines = pipe.stdout.readlines()
if free_lines:
# Extract the info.
for line in free_lines:
# Split up the line.
row = line.split()
# The RAM size.
if row[0] == 'Mem:':
text += format % ("Total RAM size: ", row[1], "Mb")
# The swap size.
if row[0] == 'Swap:':
text += format % ("Total swap size: ", row[1], "Mb")
# Windows systems (supported by ctypes.windll).
if system == 'Windows' or system == 'Microsoft':
# Initialise the memory info class.
mem = MemoryStatusEx()
# The RAM size.
text += format % ("Total RAM size: ", mem.ullTotalPhys / 1024.**2, "Mb")
# The swap size.
text += format % ("Total swap size: ", mem.ullTotalVirtual / 1024.**2, "Mb")
# Mac OS X systems.
if system == 'Darwin':
# Add the 'sysctl' path to the environment (if needed).
environ['PATH'] += pathsep + '/usr/sbin'
# The commands to run.
cmd = "sysctl -n hw.physmem"
cmd2 = "sysctl -n hw.memsize"
# Execute the command in a fail safe way, return the result or nothing.
try:
# Execute.
pipe = Popen(cmd, shell=True, stdout=PIPE, close_fds=False)
waitpid(pipe.pid, 0)
# Get the STDOUT data.
data = pipe.stdout.readlines()
# Execute.
pipe = Popen(cmd2, shell=True, stdout=PIPE, close_fds=False)
waitpid(pipe.pid, 0)
# Get the STDOUT data.
data2 = pipe.stdout.readlines()
# Convert the values.
ram = int(data[0].strip())
total = int(data2[0].strip())
swap = total - ram
# The RAM size.
text += format % ("Total RAM size: ", ram / 1024.**2, "Mb")
# The swap size.
text += format % ("Total swap size: ", swap / 1024.**2, "Mb")
# Nothing.
except:
pass
# Unknown.
if not text:
text += format % ("Total RAM size: ", "?", "Mb")
text += format % ("Total swap size: ", "?", "Mb")
# Return the info string.
return text
def relax_module_info(self):
"""Return a string with info about the relax modules.
@return: The info string.
@rtype: str
"""
# Init.
text = ''
name = []
status = []
file_type = []
path = []
# Intro.
text = text + ("\nrelax C modules:\n\n")
# Header.
name.append("Module")
status.append("Compiled")
file_type.append("File type")
path.append("Path")
# relaxation curve-fitting.
name.append('target_functions.relax_fit')
status.append(dep_check.C_module_exp_fn)
if hasattr(dep_check, 'relax_fit'):
file_type.append(self.file_type(dep_check.relax_fit.__file__))
path.append(dep_check.relax_fit.__file__)
else:
file_type.append('')
path.append('')
# Format the data.
fmt_name = "%%-%ss" % (self.format_max_width(name) + 2)
fmt_status = "%%-%ss" % (self.format_max_width(status) + 2)
fmt_file_type = "%%-%ss" % (self.format_max_width(file_type) + 2)
fmt_path = "%%-%ss" % (self.format_max_width(path) + 2)
# Add the text.
for i in range(len(name)):
text += fmt_name % name[i]
text += fmt_status % status[i]
text += fmt_file_type % file_type[i]
text += fmt_path % path[i]
text += '\n'
# Return the info string.
return text
def sys_info(self):
"""Return a string for printing to STDOUT with info about the current relax instance.
@return: The info string.
@rtype: str
"""
# Init.
text = ''
# Formatting string.
format = " %-25s%s\n"
format2 = " %-25s%s %s\n"
# Hardware info.
text = text + ("\nHardware information:\n")
if hasattr(platform, 'machine'):
text = text + (format % ("Machine: ", platform.machine()))
if hasattr(platform, 'processor'):
text = text + (format % ("Processor: ", platform.processor()))
text = text + (format % ("Processor name: ", self.processor_name()))
text = text + (format % ("Endianness: ", sys.byteorder))
text = text + self.ram_info(format=format2)
# OS info.
text = text + ("\nOperating system information:\n")
if hasattr(platform, 'system'):
text = text + (format % ("System: ", platform.system()))
if hasattr(platform, 'release'):
text = text + (format % ("Release: ", platform.release()))
if hasattr(platform, 'version'):
text = text + (format % ("Version: ", platform.version()))
if hasattr(platform, 'win32_ver') and platform.win32_ver()[0]:
text = text + (format % ("Win32 version: ", (platform.win32_ver()[0] + " " + platform.win32_ver()[1] + " " + platform.win32_ver()[2] + " " + platform.win32_ver()[3])))
if hasattr(platform, 'linux_distribution') and platform.linux_distribution()[0]:
text = text + (format % ("GNU/Linux version: ", (platform.linux_distribution()[0] + " " + platform.linux_distribution()[1] + " " + platform.linux_distribution()[2])))
if hasattr(platform, 'mac_ver') and platform.mac_ver()[0]:
text = text + (format % ("Mac version: ", (platform.mac_ver()[0] + " (" + platform.mac_ver()[1][0] + ", " + platform.mac_ver()[1][1] + ", " + platform.mac_ver()[1][2] + ") " + platform.mac_ver()[2])))
if hasattr(platform, 'dist'):
text = text + (format % ("Distribution: ", (platform.dist()[0] + " " + platform.dist()[1] + " " + platform.dist()[2])))
if hasattr(platform, 'platform'):
text = text + (format % ("Full platform string: ", (platform.platform())))
if hasattr(ctypes, 'windll'):
text = text + (format % ("Windows architecture: ", (self.win_arch())))
# Python info.
text = text + ("\nPython information:\n")
if hasattr(platform, 'architecture'):
text = text + (format % ("Architecture: ", (platform.architecture()[0] + " " + platform.architecture()[1])))
if hasattr(platform, 'python_version'):
text = text + (format % ("Python version: ", platform.python_version()))
if hasattr(platform, 'python_branch'):
text = text + (format % ("Python branch: ", platform.python_branch()))
if hasattr(platform, 'python_build'):
text = text + ((format[:-1]+', %s\n') % ("Python build: ", platform.python_build()[0], platform.python_build()[1]))
if hasattr(platform, 'python_compiler'):
text = text + (format % ("Python compiler: ", platform.python_compiler()))
if hasattr(platform, 'libc_ver'):
text = text + (format % ("Libc version: ", (platform.libc_ver()[0] + " " + platform.libc_ver()[1])))
if hasattr(platform, 'python_implementation'):
text = text + (format % ("Python implementation: ", platform.python_implementation()))
if hasattr(platform, 'python_revision'):
text = text + (format % ("Python revision: ", platform.python_revision()))
if sys.executable:
text = text + (format % ("Python executable: ", sys.executable))
if hasattr(sys, 'flags'):
text = text + (format % ("Python flags: ", sys.flags))
if hasattr(sys, 'float_info'):
text = text + (format % ("Python float info: ", sys.float_info))
text = text + (format % ("Python module path: ", sys.path))
# Python packages.
text = text + self.package_info()
# relax info:
text = text + "\nrelax information:\n"
text = text + (format % ("Version: ", version_full()))
if hasattr(self, "multi_processor_string"):
text += format % ("Processor fabric: ", self.multi_processor_string)
# relax modules.
text = text + self.relax_module_info()
# End with an empty newline.
text = text + ("\n")
# Return the text.
return text
def win_arch(self):
"""Determine the MS Windows architecture.
@return: The architecture string.
@rtype: str
"""
# 64-bit versions.
if 'PROCESSOR_ARCHITEW6432' in environ:
arch = environ['PROCESSOR_ARCHITEW6432']
# Default 32-bit.
else:
arch = environ['PROCESSOR_ARCHITECTURE']
# Return the architecture.
return arch
class MemoryStatusEx(Structure):
"""Special object for obtaining hardware info in MS Windows."""
if hasattr(ctypes, 'windll'):
_fields_ = [
('dwLength', ctypes.wintypes.DWORD),
('dwMemoryLoad', ctypes.wintypes.DWORD),
('ullTotalPhys', ctypes.c_ulonglong),
('ullAvailPhys', ctypes.c_ulonglong),
('ullTotalPageFile', ctypes.c_ulonglong),
('ullAvailPageFile', ctypes.c_ulonglong),
('ullTotalVirtual', ctypes.c_ulonglong),
('ullAvailVirtual', ctypes.c_ulonglong),
('ullExtendedVirtual', ctypes.c_ulonglong),
]
def __init__(self):
"""Set up the information and handle non MS Windows systems."""
# Get the required info (for MS Windows only).
if hasattr(ctypes, 'windll'):
self.dwLength = ctypes.sizeof(self)
ctypes.windll.kernel32.GlobalMemoryStatusEx(ctypes.byref(self))
class Ref:
"""Reference base class."""
# Initialise all class variables to None.
type = None
author = None
author2 = None
title = None
status = None
journal = None
journal_full = None
volume = None
number = None
doi = None
pubmed_id = None
url = None
pages = None
year = None
def __getattr__(self, name):
"""Generate some variables on the fly.
This is only called for objects not found in the class.
@param name: The name of the object.
@type name: str
@raises AttributeError: If the object cannot be created.
@returns: The generated object.
@rtype: anything
"""
# Page numbers.
if name in ['page_first', 'page_last']:
# No page info.
if not self.pages:
return None
# First split the page range.
vals = self.pages.split('-')
# Single page.
if len(vals) == 1:
return vals[0]
# First page.
if name == 'page_first':
return vals[0]
# Last page.
if name == 'page_last':
return vals[1]
raise AttributeError(name)
def cite_short(self, author=True, title=True, journal=True, volume=True, number=True, pages=True, year=True, doi=True, url=True, status=True):
"""Compile a short citation.
The returned text will have the form of:
- d'Auvergne, E.J. and Gooley, P.R. (2008). Optimisation of NMR dynamic models I. Minimisation algorithms and their performance within the model-free and Brownian rotational diffusion spaces. J. Biomol. NMR, 40(2), 107-119.
@keyword author: The author flag.
@type author: bool
@keyword title: The title flag.
@type title: bool
@keyword journal: The journal flag.
@type journal: bool
@keyword volume: The volume flag.
@type volume: bool
@keyword number: The number flag.
@type number: bool
@keyword pages: The pages flag.
@type pages: bool
@keyword year: The year flag.
@type year: bool
@keyword doi: The doi flag.
@type doi: bool
@keyword url: The url flag.
@type url: bool
@keyword status: The status flag. This will only be shown if not 'published'.
@type status: bool
@return: The full citation.
@rtype: str
"""
# Build the citation.
cite = ''
if author and self.author and hasattr(self, 'author'):
cite = cite + self.author
if year and self.year and hasattr(self, 'year'):
cite = cite + ' (' + repr(self.year) + ').'
if title and self.title and hasattr(self, 'title'):
cite = cite + ' ' + self.title
if journal and self.journal and hasattr(self, 'journal'):
cite = cite + ' ' + self.journal + ','
if volume and self.volume and hasattr(self, 'volume'):
cite = cite + ' ' + self.volume
if number and self.number and hasattr(self, 'number'):
cite = cite + '(' + self.number + '),'
if pages and self.pages and hasattr(self, 'pages'):
cite = cite + ' ' + self.pages