@@ -15,8 +15,10 @@ class FolderKnowledgeRepository(KnowledgeRepository):
1515 _registry_keys = ['' , 'file' ]
1616
1717 TEMPLATES = {
18- 'README.md' : get_path (__file__ , '../templates' , 'repository_readme.md' ),
19- '.knowledge_repo_config.yml' : get_path (__file__ , '../templates' , 'repository_config.yml' ),
18+ 'README.md' : get_path (
19+ __file__ , '../templates' , 'repository_readme.md' ),
20+ '.knowledge_repo_config.yml' : get_path (
21+ __file__ , '../templates' , 'repository_config.yml' ),
2022 }
2123
2224 @classmethod
@@ -40,8 +42,8 @@ def create(cls, uri, embed_tooling=False):
4042 def from_uri (cls , uri , * args , ** kwargs ):
4143 """
4244 If this folder is actually a git repository, a `GitKnowledgeRepository`
43- is returned instead, unless the folder knowledge repository is explicitly
44- requested via the 'file://' protocol.
45+ is returned instead, unless the folder knowledge repository is
46+ explicitly requested via the 'file://' protocol.
4547 """
4648 check_for_git = True
4749 if uri .startswith ('file://' ):
@@ -73,7 +75,7 @@ def path(self, path):
7375 raise ValueError (f"Provided path '{ path } ' does not exist." )
7476 self ._path = path
7577
76- # ----------- Repository actions / state ------------------------------------
78+ # ----------- Repository actions / state ----------------------------------
7779 @property
7880 def revision (self ):
7981 return time .time ()
@@ -93,7 +95,8 @@ def _dir(self, prefix, statuses):
9395
9496 if self .PostStatus .PUBLISHED in statuses :
9597
96- for path , folders , files in os .walk (os .path .join (self .path , prefix or '' )):
98+ for path , folders , files in os .walk (
99+ os .path .join (self .path , prefix or '' )):
97100
98101 # Do not visit hidden folders
99102 for folder in folders :
@@ -110,7 +113,8 @@ def _dir(self, prefix, statuses):
110113 for file in files if file .endswith ('.kp' )
111114 )
112115
113- for post in sorted ([post [2 :] if post .startswith ('./' ) else post for post in posts ]):
116+ for post in sorted ([post [2 :] if post .startswith ('./' )
117+ else post for post in posts ]):
114118 yield post
115119
116120 # ------------- Post submission / addition user flow ----------------------
@@ -135,16 +139,18 @@ def _accept(self, path): # Approve to publish a post for general perusal
135139 def _remove (self , path , all = False ):
136140 shutil .rmtree (os .path .join (self .path , path ))
137141
138- # ------------ Knowledge Post Data Retrieval Methods -------------------------
142+ # ------------ Knowledge Post Data Retrieval Methods ----------------------
139143
140144 def _kp_uuid (self , path ):
141145 try :
142146 return self ._kp_read_ref (path , 'UUID' )
143- except :
147+ except Exception as e :
148+ print (f'Exception encountered: { e } ' )
144149 return None
145150
146151 def _kp_path (self , path , rel = None ):
147- return KnowledgeRepository ._kp_path (self , os .path .expanduser (path ), rel = rel or self .path )
152+ return KnowledgeRepository ._kp_path (
153+ self , os .path .expanduser (path ), rel = rel or self .path )
148154
149155 def _kp_exists (self , path , revision = None ):
150156 return os .path .exists (os .path .join (self .path , path ))
@@ -153,11 +159,12 @@ def _kp_status(self, path, revision=None, detailed=False, branch=None):
153159 return self .PostStatus .PUBLISHED
154160
155161 def _kp_get_revision (self , path ):
156- # We use a 'REVISION' file in the knowledge post folder rather than using git
157- # revisions because using git rev-parse is slow.
162+ # We use a 'REVISION' file in the knowledge post folder rather than
163+ # using git revisions because using git rev-parse is slow.
158164 try :
159165 return int (self ._kp_read_ref (path , 'REVISION' ))
160- except :
166+ except Exception as e :
167+ print (f'Exception encountered: { e } ' )
161168 return 0
162169
163170 def _kp_get_revisions (self , path ):
@@ -176,22 +183,26 @@ def _kp_write_ref(self, path, reference, data, uuid=None, revision=None):
176183 os .makedirs (ref_dir )
177184 write_binary (ref_path , data )
178185
179- def _kp_dir (self , path , parent = None , revision = None ): # TODO: Account for revision
186+ # TODO: Account for revision
187+ def _kp_dir (self , path , parent = None , revision = None ):
180188 path = os .path .join (self .path , path )
181189 if os .path .isdir (path ):
182190 if parent :
183191 path = os .path .join (path , parent )
184- for dirpath , dirnames , filenames in os .walk (os .path .join (self .path , path )):
192+ for dirpath , dirnames , filenames in os .walk (
193+ os .path .join (self .path , path )):
185194 for filename in filenames :
186195 if dirpath == '' and filename == 'REVISION' :
187196 continue
188- yield os .path .relpath (os .path .join (dirpath , filename ), os .path .join (self .path , path ))
197+ yield os .path .relpath (os .path .join (
198+ dirpath , filename ), os .path .join (self .path , path ))
189199 else :
190200 kp = KnowledgePost .from_file (path , format = 'kp' )
191201 for reference in kp ._dir (parent = parent ):
192202 yield reference
193203
194- def _kp_has_ref (self , path , reference , revision = None ): # TODO: Account for revision
204+ # TODO: Account for revision
205+ def _kp_has_ref (self , path , reference , revision = None ):
195206 path = os .path .join (self .path , path )
196207 if os .path .isdir (path ):
197208 return os .path .isfile (os .path .join (path , reference ))
0 commit comments