2
2
import sys
3
3
import os .path
4
4
import yaml
5
+ import pathlib
6
+
5
7
6
8
7
9
def which_path ():
@@ -34,12 +36,12 @@ def which_path():
34
36
35
37
return path
36
38
39
+
37
40
def create_config (path ):
38
41
"""
39
42
this will copy the currently used config file in the standard folder
40
43
"""
41
- cwd = os .getcwd ()
42
- path = os .path .join (cwd , path )
44
+ syspath = which_path () + "/config.yaml"
43
45
shutil .copyfile (path , syspath )
44
46
print (f"New config file created, edit config file at: { syspath } " )
45
47
@@ -49,37 +51,15 @@ def load_config(path):
49
51
"""
50
52
First checking "path" to match minimum length and other requirements.
51
53
52
- Then it opens the specified config file and returns all keys ehich include token and UserId.
54
+ Then it opens the specified config file and returns all keys which include token and UserId.
53
55
"""
54
-
55
- #converts path into string to avoid errors if variable is not supported
56
- path = str (path )
57
- if (len (path )> 2 ):
58
- if (".yaml" in path ):
59
- #if standard directory is not available run create_config
60
- if not os .path .exists (syspath ):
61
- print ("creating new config" )
62
- create_config (path )
63
- #opens specified file to retrieve config tokens
64
- with open (f"{ path } " , 'r' ) as stream :
65
- try :
66
- data = yaml .safe_load (stream )
67
- # return list of dictionaries for all projects
68
- for value in data .values ():
69
- return (value )
70
- except yaml .YAMLError as exc :
71
- print (exc )
72
-
73
- except FileNotFoundError :
74
- print ("Configuration file is not found" )
75
-
76
- #it's not a yaml file. yaml error is raised.
77
- else :
78
- raise yaml .YAMLError
79
-
80
- #filename is too short
56
+ # opens specified file to retrieve config tokens
57
+ if isinstance (path , str ) or isinstance (path , pathlib .Path ):
58
+ assert path
59
+ with open (f"{ path } " , 'r' ) as stream :
60
+ data = yaml .safe_load (stream )
61
+ # return list of dictionaries for all projects
62
+ for value in data .values ():
63
+ return (value )
81
64
else :
82
- print ("Not a valid file name!" )
83
65
raise AssertionError
84
-
85
- syspath = which_path () + "/config.yaml"
0 commit comments