[Bio] / FigKernelPackages / FIG.py Repository:
ViewVC logotype

Diff of /FigKernelPackages/FIG.py

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1, Thu Feb 12 16:00:31 2004 UTC revision 1.8, Wed Apr 28 21:59:32 2004 UTC
# Line 5  Line 5 
5  import re  import re
6  import FIG_Config  import FIG_Config
7    
8    import Clearinghouse
9    
10    def get_clearinghouse(url = None):
11        return Clearinghouse.Clearinghouse(url)
12    
13  def get_local_hostname():  def get_local_hostname():
14      #      #
15        # See if there is a FIGdisk/config/hostname file. If there
16        # is, force the hostname to be that.
17        #
18    
19        try:
20            fh = open(os.path.join(FIG_Config.fig_disk, "config", "hostname"))
21            host = fh.readline()
22            return host.strip()
23        except:
24            pass
25    
26        #
27      # First check to see if we our hostname is correct.      # First check to see if we our hostname is correct.
28      #      #
29      # Map it to an IP address, and try to bind to that ip.      # Map it to an IP address, and try to bind to that ip.
30      #      #
31    
32      hostname = socket.getfqdn()      hostname = socket.getfqdn()
33      hostname = "yips"  
34        #
35        # See if hostname is something.local., which is what
36        # a Mac will return if it didn't get a name via some
37        # other mechanism (DHCP or static config). We have to
38        # check here because otherwise it will pass the fqdn and
39        # local binding test.
40        #
41    
42        if not re.search(r"\.local\.?$", hostname):
43    
44      #      #
45      # First check that hostname is a fqdn, and that we can bind to it.      # First check that hostname is a fqdn, and that we can bind to it.
46      #      #
# Line 131  Line 158 
158      for l in fh:      for l in fh:
159          cols = l.strip().split()          cols = l.strip().split()
160    
161          if cols[0] == "default" or cols[0] == "0.0.0.0":          if len(cols) > 0 and (cols[0] == "default" or cols[0] == "0.0.0.0"):
162              interface_name = cols[-1]              interface_name = cols[-1]
163              break              break
164    
165      fh.close()      fh.close()
166    
167      print "Default route on ", interface_name      # print "Default route on ", interface_name
168    
169      #      #
170      # Find ifconfig.      # Find ifconfig.
# Line 157  Line 184 
184          print >> sys.stderr, "Ifconfig not found"          print >> sys.stderr, "Ifconfig not found"
185          return "localhost"          return "localhost"
186    
187      print >> sys.stderr, "found ifconfig ", ifconfig      # print >> sys.stderr, "found ifconfig ", ifconfig
188    
189      try:      try:
190          fh = os.popen(ifconfig+ " " + interface_name, "r")          fh = os.popen(ifconfig+ " " + interface_name, "r")
# Line 226  Line 253 
253      new_url = urlparse.urlunparse(p)      new_url = urlparse.urlunparse(p)
254      return new_url      return new_url
255    
256    def get_seed_id():
257        #
258        # Retrieve the seed identifer from FIGdisk/config/seed_id.
259        #
260        # If it's not there, create one, and make it readonly.
261        #
262    
263        id_file = os.path.join(FIG_Config.fig_disk, "config", "seed_id")
264        if not os.path.isfile(id_file):
265    
266            fh = os.popen("uuidgen", "r")
267    
268            newid = fh.readline()
269            newid = newid.strip()
270    
271            fh.close()
272    
273            fh = open(id_file, "w")
274            print >>fh, newid
275            fh.close()
276    
277            os.chmod(id_file, 0444)
278    
279        fh = open(id_file)
280        id = fh.readline()
281        fh.close()
282        id = id.strip()
283        return id
284    
285  if __name__ == "__main__":  if __name__ == "__main__":
286    
287      print get_local_hostname()      print get_local_hostname()
288      print cgi_url()      print cgi_url()
289      print temp_url()      print temp_url()
290    
291        print get_seed_id()

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.8

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3