[user_data] do not create any file to read user_data, open it directly with urllib2
authorPaul Tonelli <paul.tonelli@logilab.fr>
Thu, 05 Dec 2013 16:20:04 +0100
changeset 186 2b3c7010e3ae
parent 185 ca037e9e657c
child 187 e115bc7c3d86
[user_data] do not create any file to read user_data, open it directly with urllib2
others/user_data_parser.py
--- a/others/user_data_parser.py	Tue Dec 03 11:25:25 2013 +0100
+++ b/others/user_data_parser.py	Thu Dec 05 16:20:04 2013 +0100
@@ -2,7 +2,8 @@
 # -*- coding: utf-8 -*-
 # author: Paul Tonelli <ptonelli@logilab.fr>
 
-import urllib, os
+import os
+import urllib2
 from time import sleep
 from salt import grains
 from sys import argv
@@ -35,11 +36,10 @@
      else: return self.fp.readline()
 
 if __name__ == "__main__":
-    os.chdir('/tmp')
     if len(argv)>1: #we have a filename, no need to download it
         myfile = open(argv[1],'r')
     else:
-        myfile = open(urllib.urlretrieve(url)[0],'r')
+        myfile = urllib2.urlopen(url)
     found_flag = False
     while found_flag == False:
         line = myfile.readline()