~maddevelopers/mg5amcnlo/2.7.1.3

« back to all changes in this revision

Viewing changes to madgraph/various/misc.py

  • Committer: olivier-mattelaer
  • Date: 2017-03-08 22:47:41 UTC
  • mfrom: (269.1.40 2.5.3)
  • Revision ID: olivier-mattelaer-20170308224741-vvle7s0u2541viuw
pass to 2.5.3

Show diffs side-by-side

added added

removed removed

Lines of Context:
107
107
        return f_with_no_logger
108
108
    return control_logger
109
109
 
 
110
PACKAGE_INFO = {}
110
111
#===============================================================================
111
112
# get_pkg_info
112
113
#===============================================================================
116
117
    a dictionary with empty values is returned. As an option, an info
117
118
    string can be passed to be read instead of the file content.
118
119
    """
 
120
    global PACKAGE_INFO
119
121
 
120
122
    if info_str:
121
123
        info_dict = parse_info_str(StringIO.StringIO(info_str))
125
127
        info_dict['version'] = open(pjoin(internal.__path__[0],'..','..','MGMEVersion.txt')).read().strip()
126
128
        info_dict['date'] = '20xx-xx-xx'                        
127
129
    else:
 
130
        if PACKAGE_INFO:
 
131
            return PACKAGE_INFO
128
132
        info_dict = files.read_from_file(os.path.join(madgraph.__path__[0],
129
133
                                                  "VERSION"),
130
134
                                                  parse_info_str, 
131
135
                                                  print_error=False)
 
136
        PACKAGE_INFO = info_dict
132
137
        
133
138
    return info_dict
134
139
 
1545
1550
#      pass
1546
1551
 
1547
1552
## Define apple_notify (in a way which is system independent
1548
 
try:
1549
 
    import Foundation
1550
 
    import objc
1551
 
    NSUserNotification = objc.lookUpClass('NSUserNotification')
1552
 
    NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
1553
 
 
1554
 
    def apple_notify(subtitle, info_text, userInfo={}):
1555
 
        try:
1556
 
            notification = NSUserNotification.alloc().init()
 
1553
class Applenotification(object):
 
1554
 
 
1555
    def __init__(self):
 
1556
        self.init = False
 
1557
        self.working = True
 
1558
 
 
1559
    def load_notification(self):        
 
1560
        try:
 
1561
            import Foundation
 
1562
            import objc
 
1563
            self.NSUserNotification = objc.lookUpClass('NSUserNotification')
 
1564
            self.NSUserNotificationCenter = objc.lookUpClass('NSUserNotificationCenter')
 
1565
        except:
 
1566
            self.working=False
 
1567
        self.working=True
 
1568
 
 
1569
    def __call__(self,subtitle, info_text, userInfo={}):
 
1570
        
 
1571
        if not self.init:
 
1572
            self.load_notification()
 
1573
        if not self.working:
 
1574
            return
 
1575
        try:
 
1576
            notification = self.NSUserNotification.alloc().init()
1557
1577
            notification.setTitle_('MadGraph5_aMC@NLO')
1558
1578
            notification.setSubtitle_(subtitle)
1559
1579
            notification.setInformativeText_(info_text)
1560
 
            notification.setUserInfo_(userInfo)
1561
 
            NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
 
1580
            try:
 
1581
                notification.setUserInfo_(userInfo)
 
1582
            except:
 
1583
                pass
 
1584
            self.NSUserNotificationCenter.defaultUserNotificationCenter().scheduleNotification_(notification)
1562
1585
        except:
1563
 
            pass
1564
 
except:
1565
 
    def apple_notify(subtitle, info_text, userInfo={}):
1566
 
        return
1567
 
## End apple notify
 
1586
            pass        
 
1587
        
 
1588
 
 
1589
 
 
1590
apple_notify = Applenotification()
 
1591
 
1568
1592
 
1569
1593
 
1570
1594
def get_older_version(v1, v2):
1736
1760
    else:
1737
1761
        python_lhapdf = None
1738
1762
    return python_lhapdf
 
1763
 
 
1764
############################### TRACQER FOR OPEN FILE
 
1765
#openfiles = set()
 
1766
#oldfile = __builtin__.file
 
1767
#
 
1768
#class newfile(oldfile):
 
1769
#    done = 0
 
1770
#    def __init__(self, *args):
 
1771
#        self.x = args[0]
 
1772
#        if 'matplotlib' in self.x:
 
1773
#            raise Exception
 
1774
#        print "### OPENING %s ### %s " % (str(self.x) , time.time()-start)
 
1775
#        oldfile.__init__(self, *args)
 
1776
#        openfiles.add(self)
 
1777
#
 
1778
#    def close(self):
 
1779
#        print "### CLOSING %s ### %s" % (str(self.x), time.time()-start)
 
1780
#        oldfile.close(self)
 
1781
#        openfiles.remove(self)
 
1782
#oldopen = __builtin__.open
 
1783
#def newopen(*args):
 
1784
#    return newfile(*args)
 
1785
#__builtin__.file = newfile
 
1786
#__builtin__.open = newopen