File tree Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Expand file tree Collapse file tree 2 files changed +28
-1
lines changed Original file line number Diff line number Diff line change
1
+ import re
1
2
import resource
3
+ import unicodedata
2
4
3
5
4
6
def get_open_fd_limit () -> int :
@@ -7,3 +9,17 @@ def get_open_fd_limit() -> int:
7
9
"""
8
10
soft_limit , hard_limit = resource .getrlimit (resource .RLIMIT_NOFILE )
9
11
return soft_limit
12
+
13
+
14
+ def friendly_filename_or_url (value : str ) -> str :
15
+ """
16
+ Normalize any string to be file name and URL friendly.
17
+ Convert to lowercase, remove non-alpha characters,
18
+ and convert spaces to hyphens.
19
+ """
20
+ # Taken from:
21
+ # https://stackoverflow.com/questions/295135/turn-a-string-into-a-valid-filename/295466#295466
22
+ value = str (unicodedata .normalize ('NFKD' , value ).encode ('ascii' , 'ignore' ))
23
+ value = str (re .sub ('[^\w\s-]' , '' , value ).strip ().lower ())
24
+ value = str (re .sub ('[-\s]+' , '-' , value ))
25
+ return value
Original file line number Diff line number Diff line change 50
50
from trinity ._utils .logging import (
51
51
setup_queue_logging ,
52
52
)
53
+ from trinity ._utils .os import (
54
+ friendly_filename_or_url ,
55
+ )
53
56
54
57
55
58
class PluginStatus (Enum ):
@@ -135,6 +138,13 @@ def name(self) -> str:
135
138
"""
136
139
pass
137
140
141
+ @property
142
+ def normalized_name (self ) -> str :
143
+ """
144
+ The normalized (computer readable) name of the plugin
145
+ """
146
+ return friendly_filename_or_url (self .name )
147
+
138
148
@property
139
149
def logger (self ) -> logging .Logger :
140
150
"""
@@ -296,7 +306,8 @@ def _prepare_start(self) -> None:
296
306
self .event_bus .broadcast (
297
307
PluginStartedEvent (type (self ))
298
308
)
299
- self .do_start ()
309
+ with self .context .trinity_config .process_id_file (self .normalized_name ):
310
+ self .do_start ()
300
311
301
312
def stop (self ) -> None :
302
313
"""
You can’t perform that action at this time.
0 commit comments