File tree Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Expand file tree Collapse file tree 3 files changed +55
-0
lines changed Original file line number Diff line number Diff line change 4
4
from diffpy .labpdfproc .functions import apply_corr , compute_cve
5
5
from diffpy .labpdfproc .tools import (
6
6
known_sources ,
7
+ load_user_info ,
7
8
load_user_metadata ,
8
9
set_input_lists ,
9
10
set_output_directory ,
@@ -96,6 +97,7 @@ def get_args(override_cli_inputs=None):
96
97
97
98
def main ():
98
99
args = get_args ()
100
+ args = load_user_info (args )
99
101
args = set_input_lists (args )
100
102
args .output_directory = set_output_directory (args )
101
103
args .wavelength = set_wavelength (args )
Original file line number Diff line number Diff line change 1
1
from pathlib import Path
2
2
3
+ from diffpy .labpdfproc .user_config import find_conf_file , read_conf_file , user_info_conf
4
+
3
5
WAVELENGTHS = {"Mo" : 0.71 , "Ag" : 0.59 , "Cu" : 1.54 }
4
6
known_sources = [key for key in WAVELENGTHS .keys ()]
5
7
@@ -171,3 +173,17 @@ def load_user_metadata(args):
171
173
setattr (args , key , value )
172
174
delattr (args , "user_metadata" )
173
175
return args
176
+
177
+
178
+ def load_user_info (args ):
179
+ conf_file_path = find_conf_file ()
180
+ if conf_file_path is not None :
181
+ conf_file = read_conf_file (conf_file_path )
182
+ if "username" in conf_file and "useremail" in conf_file :
183
+ setattr (args , "username" , conf_file ["username" ])
184
+ setattr (args , "useremail" , conf_file ["useremail" ])
185
+ return args
186
+ else :
187
+ return user_info_conf (args )
188
+ else :
189
+ return user_info_conf (args )
Original file line number Diff line number Diff line change
1
+ import json
2
+ import os
3
+ from pathlib import Path
4
+
5
+ CONFIG_FILE = "labpdfprocconfig.json"
6
+
7
+
8
+ def find_conf_file ():
9
+ # Return config file path if such a file exists
10
+ if os .path .exists (CONFIG_FILE ):
11
+ return Path (CONFIG_FILE ).resolve ()
12
+ return None
13
+
14
+
15
+ def read_conf_file (file_path ):
16
+ with open (file_path , "r" ) as f :
17
+ return json .load (f )
18
+
19
+
20
+ def write_conf_file (file_path , username , useremail ):
21
+ config = {"username" : username , "useremail" : useremail }
22
+ with open (file_path , "w" ) as f :
23
+ json .dump (config , f )
24
+
25
+
26
+ def prompt_user_info ():
27
+ username = input ("Please enter your username (or press Enter to skip): " )
28
+ useremail = input ("Please enter your email (or press Enter to skip): " )
29
+ return username , useremail
30
+
31
+
32
+ def user_info_conf (args ):
33
+ username , useremail = prompt_user_info ()
34
+ write_conf_file (CONFIG_FILE , username , useremail )
35
+ setattr (args , "username" , username )
36
+ setattr (args , "useremail" , useremail )
37
+ return args
You can’t perform that action at this time.
0 commit comments