@@ -113,25 +113,7 @@ def init_project():
113113 config ["path" ] = {"base" : os .getcwd ()}
114114 with open (config_file , "w" ) as f :
115115 config .write (f )
116- if "user" not in config or "email" not in config ["user" ]:
117- print (
118- "Please provide your email to be able to download CryoSat-2 data from ESA."
119- )
120- while True :
121- _input = input ("Enter your email" )
122- if re .fullmatch (r"[^@]+@[^@]+\.[a-z]{2,9}" , _input .strip ().lower ()):
123- if "user" not in config :
124- config ["user" ] = {}
125- config ["user" ].update ({"email" : _input })
126- with open (config_file , "w" ) as f : # update/overwrite
127- config .write (f )
128- break
129- else :
130- print (
131- 'Didn\' t match required pattern "[^@]+@[^@]+\\ .[a-z]{2,9}". If' ,
132- "your email indeed doesn't match, file an issue. Your input was:" ,
133- _input ,
134- )
116+ print ("Run cryoswath.misc.update_email() from a python prompt to complete setup." )
135117
136118
137119# Paths ##############################################################
@@ -2214,14 +2196,23 @@ def sandbox_write_to(target: str):
22142196 os .remove (target + "__backup" )
22152197
22162198
2217- def update_email (email ):
2218- config = ConfigParser ()
2219- config .read ("config.ini" )
2220- if "user" not in config :
2221- config ["user" ] = dict ()
2222- config ["user" ].update ({"email" : email })
2223- with open ("config.ini" , "w" ) as f :
2224- config .write (f )
2199+ def update_email (email : str = None ):
2200+ if email is None :
2201+ email = input ("Enter your email" )
2202+ if re .fullmatch (r"[^@]+@[^@]+\.[a-z]{2,9}" , email .strip ().lower ()):
2203+ config = ConfigParser ()
2204+ config .read ("config.ini" )
2205+ if "user" not in config :
2206+ config ["user" ] = dict ()
2207+ config ["user" ].update ({"email" : email })
2208+ with open ("config.ini" , "w" ) as f : # update/overwrite
2209+ config .write (f )
2210+ else :
2211+ print (
2212+ 'Didn\' t match required pattern "[^@]+@[^@]+\\ .[a-z]{2,9}". If' ,
2213+ "your email indeed doesn't match, file an issue. Your input was:" ,
2214+ email ,
2215+ )
22252216
22262217
22272218# CREDIT: mgab https://stackoverflow.com/a/22376126
0 commit comments