@@ -1302,6 +1302,21 @@ def config_unset(self, args):
13021302 else :
13031303 raise ResponseError (response )
13041304
1305+ def _read_config_from_path (self , path ):
1306+ env_dict = {}
1307+ with open (path , 'r' ) as f :
1308+ for line in f :
1309+ line = line .strip ()
1310+ if not line :
1311+ continue
1312+ if re .match (r'.+=.+' , line ) is None :
1313+ self ._logger .warning ('could not parse config line: "%s"' , line )
1314+ continue
1315+ k , v = line .split ('=' , 1 )
1316+ env_dict [k ] = v
1317+
1318+ return env_dict
1319+
13051320 def config_pull (self , args ):
13061321 """
13071322 Extract all environment variables from an application for local use.
@@ -1327,10 +1342,7 @@ def config_pull(self, args):
13271342 app = self ._session .app
13281343 try :
13291344 # load env_dict from existing .env, if it exists
1330- with open ('.env' ) as f :
1331- for line in f .readlines ():
1332- k , v = line .split ('=' , 1 )[0 ], line .split ('=' , 1 )[1 ].strip ('\n ' )
1333- env_dict [k ] = v
1345+ env_dict = self ._read_config_from_path ('.env' )
13341346 except IOError :
13351347 pass
13361348 response = self ._dispatch ('get' , "/v1/apps/{}/config" .format (app ))
@@ -1374,8 +1386,8 @@ def config_push(self, args):
13741386
13751387 # read from .env
13761388 try :
1377- with open (args .get ('--path' ), 'r' ) as f :
1378- self ._config_set (app , dictify ([ line . strip () for line in f ]) )
1389+ env_dict = self . _read_config_from_path (args .get ('--path' ))
1390+ self ._config_set (app , env_dict )
13791391 except IOError :
13801392 self ._logger .error ('could not read env from ' + args .get ('--path' ))
13811393 sys .exit (1 )
0 commit comments