[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.7, Fri Mar 26 21:38:38 2004 UTC
# Line 7  Line 7 
7    
8  def get_local_hostname():  def get_local_hostname():
9      #      #
10        # See if there is a FIGdisk/config/hostname file. If there
11        # is, force the hostname to be that.
12        #
13    
14        try:
15            fh = open(os.path.join(FIG_Config.fig_disk, "config", "hostname"))
16            host = fh.readline()
17            return host.strip()
18        except:
19            pass
20    
21        #
22      # First check to see if we our hostname is correct.      # First check to see if we our hostname is correct.
23      #      #
24      # 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.
25      #      #
26    
27      hostname = socket.getfqdn()      hostname = socket.getfqdn()
28      hostname = "yips"  
29        #
30        # See if hostname is something.local., which is what
31        # a Mac will return if it didn't get a name via some
32        # other mechanism (DHCP or static config). We have to
33        # check here because otherwise it will pass the fqdn and
34        # local binding test.
35        #
36    
37        if not re.search(r"\.local\.?$", hostname):
38    
39      #      #
40      # 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.
41      #      #
# Line 131  Line 153 
153      for l in fh:      for l in fh:
154          cols = l.strip().split()          cols = l.strip().split()
155    
156          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"):
157              interface_name = cols[-1]              interface_name = cols[-1]
158              break              break
159    
160      fh.close()      fh.close()
161    
162      print "Default route on ", interface_name      # print "Default route on ", interface_name
163    
164      #      #
165      # Find ifconfig.      # Find ifconfig.
# Line 157  Line 179 
179          print >> sys.stderr, "Ifconfig not found"          print >> sys.stderr, "Ifconfig not found"
180          return "localhost"          return "localhost"
181    
182      print >> sys.stderr, "found ifconfig ", ifconfig      # print >> sys.stderr, "found ifconfig ", ifconfig
183    
184      try:      try:
185          fh = os.popen(ifconfig+ " " + interface_name, "r")          fh = os.popen(ifconfig+ " " + interface_name, "r")
# Line 226  Line 248 
248      new_url = urlparse.urlunparse(p)      new_url = urlparse.urlunparse(p)
249      return new_url      return new_url
250    
251    def get_seed_id():
252        #
253        # Retrieve the seed identifer from FIGdisk/config/seed_id.
254        #
255        # If it's not there, create one, and make it readonly.
256        #
257    
258        id_file = os.path.join(FIG_Config.fig_disk, "config", "seed_id")
259        if not os.path.isfile(id_file):
260    
261            fh = os.popen("uuidgen", "r")
262    
263            newid = fh.readline()
264            newid = newid.strip()
265    
266            fh.close()
267    
268            fh = open(id_file, "w")
269            print >>fh, newid
270            fh.close()
271    
272            os.chmod(id_file, 0444)
273    
274        fh = open(id_file)
275        id = fh.readline()
276        fh.close()
277        id = id.strip()
278        return id
279    
280  if __name__ == "__main__":  if __name__ == "__main__":
281    
282      print get_local_hostname()      print get_local_hostname()
283      print cgi_url()      print cgi_url()
284      print temp_url()      print temp_url()
285    
286        print get_seed_id()

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

MCS Webmaster
ViewVC Help
Powered by ViewVC 1.0.3