Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
irker
Manage
Activity
Members
Labels
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
iDB
irker
Commits
8cadf32b
Commit
8cadf32b
authored
12 years ago
by
Eric S. Raymond
Browse files
Options
Downloads
Patches
Plain Diff
Add a name suffix argument so nicks won't be ambiguous.
parent
d72ffd60
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
irker.py
+11
-9
11 additions, 9 deletions
irker.py
with
11 additions
and
9 deletions
irker.py
+
11
−
9
View file @
8cadf32b
...
...
@@ -13,7 +13,6 @@ Requires Python 2.6.
TO-DO: Is there any way to cope if servers drop connections?
TO-DO: Round-robin as in http://code.google.com/p/cia-vc/source/browse/trunk/cia/LibCIA/IRC/Network.py
TO-DO: Cope with nick collision?
TO-DO: Register the port?
"""
# These things might need tuning
...
...
@@ -97,8 +96,9 @@ class Session():
class
Irker
:
"
Persistent IRC multiplexer.
"
def
__init__
(
self
,
debuglevel
=
0
):
def
__init__
(
self
,
debuglevel
=
0
,
namesuffix
=
None
):
self
.
debuglevel
=
debuglevel
self
.
namesuffix
=
namesuffix
or
socket
.
getfqdn
().
replace
(
"
.
"
,
"
-
"
)
self
.
irc
=
irclib
.
IRC
(
debuglevel
=
self
.
debuglevel
-
1
)
thread
=
threading
.
Thread
(
target
=
self
.
irc
.
process_forever
)
self
.
irc
.
_thread
=
thread
...
...
@@ -107,7 +107,6 @@ class Irker:
self
.
sessions
=
{}
self
.
countmap
=
{}
self
.
servercount
=
0
self
.
hostname
=
socket
.
getfqdn
()
def
logerr
(
self
,
errmsg
):
"
Log a processing error.
"
sys
.
stderr
.
write
(
"
irker:
"
+
errmsg
+
"
\n
"
)
...
...
@@ -117,10 +116,10 @@ class Irker:
sys
.
stderr
.
write
(
"
irker[%d]: %s
\n
"
%
(
self
.
debuglevel
,
errmsg
))
def
nickname
(
self
,
n
):
"
Return a name for the nth server connection.
"
# The purpose of including the
FQDN is to ensure that the nicks
#
of bots managed by instances running on different hos
ts
c
an
# never collide.
return
(
NAMESTYLE
%
n
)
+
"
-
"
+
self
.
hostname
.
replace
(
"
.
"
,
"
-
"
)
# The purpose of including the
namme suffix (defaulting to the
#
host's FQDN) is to ensure that the nicks of bo
ts
m
an
aged by
#
instances running on different hosts can
never collide.
return
(
NAMESTYLE
%
n
)
+
"
-
"
+
self
.
namesuffix
def
open
(
self
,
servername
,
port
):
"
Allocate a new server instance.
"
if
not
(
servername
,
port
)
in
self
.
countmap
:
...
...
@@ -168,14 +167,17 @@ class MyTCPHandler(SocketServer.StreamRequestHandler):
if
__name__
==
'
__main__
'
:
host
=
HOST
port
=
PORT
namesuffix
=
None
debuglevel
=
0
(
options
,
arguments
)
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"
d:p:
"
)
(
options
,
arguments
)
=
getopt
.
getopt
(
sys
.
argv
[
1
:],
"
d:p:
n:
"
)
for
(
opt
,
val
)
in
options
:
if
opt
==
'
-d
'
:
debuglevel
=
int
(
val
)
elif
opt
==
'
-p
'
:
port
=
int
(
val
)
irker
=
Irker
(
debuglevel
=
debuglevel
)
elif
opt
==
'
-n
'
:
namesuffix
=
val
irker
=
Irker
(
debuglevel
=
debuglevel
,
namesuffix
=
namesuffix
)
server
=
SocketServer
.
TCPServer
((
host
,
port
),
MyTCPHandler
)
try
:
server
.
serve_forever
()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment