Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
gajim
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
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
Peter Shkenev
gajim
Commits
875a875a
Commit
875a875a
authored
19 years ago
by
dkirov
Browse files
Options
Downloads
Patches
Plain Diff
show error for missing argument in gajim-remote
parent
929d565b
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
scripts/gajim-remote.py
+47
-23
47 additions, 23 deletions
scripts/gajim-remote.py
src/remote_control.py
+2
-1
2 additions, 1 deletion
src/remote_control.py
with
49 additions
and
24 deletions
scripts/gajim-remote.py
+
47
−
23
View file @
875a875a
...
...
@@ -5,6 +5,7 @@
## - Yann Le Boulanger <asterix@lagaule.org>
## - Vincent Hanquez <tab@snarc.org>
## - Nikos Kouremenos <kourem@gmail.com>
## - Dimitur Kirov <dkirov@gmail.com>
##
## This file was initially written by Dimitur Kirov
##
...
...
@@ -57,7 +58,14 @@ def send_error(error_message):
INTERFACE
=
'
org.gajim.dbus.RemoteInterface
'
SERVICE
=
'
org.gajim.dbus
'
# define commands dict. Prototype :
# {
# 'command': [comment, [list of arguments] ]
# }
#
# each argument is defined as a tuple:
# (argument name, help on argument, is mandatory)
#
commands
=
{
'
help
'
:[
_
(
'
show a help on specific command
'
),
...
...
@@ -125,6 +133,8 @@ def send_error(error_message):
def
make_arguments_row
(
args
):
'''
return arguments list. Mandatory arguments are enclosed with:
'
<
'
,
'
>
'
, optional arguments - with
'
[
'
,
'
]
'
'''
str
=
''
for
argument
in
args
:
str
+=
'
'
...
...
@@ -138,7 +148,9 @@ def make_arguments_row(args):
else
:
str
+=
'
]
'
return
str
def
help_on_command
(
command
):
'''
return help message for a given command
'''
if
command
in
commands
:
str
=
_
(
'
Usage: %s %s %s
\n\t
'
)
%
(
sys
.
argv
[
0
],
command
,
make_arguments_row
(
commands
[
command
][
1
]))
str
+=
commands
[
command
][
0
]
+
'
\n\n
Arguments:
\n
'
...
...
@@ -148,6 +160,7 @@ def help_on_command(command):
send_error
(
_
(
'
%s not found
'
)
%
command
)
def
compose_help
():
'''
print usage, and list available commands
'''
str
=
_
(
'
Usage: %s command [arguments]
\n
Command is one of:
\n
'
)
%
sys
.
argv
[
0
]
for
command
in
commands
.
keys
():
str
+=
'
'
+
command
...
...
@@ -166,7 +179,7 @@ def compose_help():
return
str
def
show_vcard_info
(
*
args
,
**
keyword
):
# more cleaner output
#
FIXME:
more cleaner output
if
_version
[
1
]
>=
30
:
print
args
[
0
]
else
:
...
...
@@ -181,12 +194,40 @@ def show_vcard_info(*args, **keyword):
gtk
.
main_quit
()
def
check_arguments
(
command
):
'''
Make check if all necessary arguments are given
'''
argv_len
=
len
(
sys
.
argv
)
-
2
args
=
commands
[
command
][
1
]
if
len
(
args
)
>
argv_len
:
if
args
[
argv_len
][
2
]:
send_error
(
_
(
'
Argument <%s> is not specified.
\n\
Type
\'
%s help %s
\'
for more info
'
)
%
\
(
args
[
argv_len
][
0
],
sys
.
argv
[
0
],
command
))
def
gtk_quit
():
if
_version
[
1
]
>=
41
:
sbus
.
remove_signal_receiver
(
show_vcard_info
,
'
VcardInfo
'
,
INTERFACE
,
SERVICE
,
OBJ_PATH
)
gtk
.
main_quit
()
#FIXME - didn't find more clever way for the below 8 lines of code.
# method(sys.argv[2:]) doesn't work, cos sys.argv[2:] is a tuple
def
call_remote_method
(
method
):
argv_len
=
len
(
sys
.
argv
)
try
:
if
argv_len
==
2
:
res
=
method
()
elif
argv_len
==
3
:
res
=
method
(
sys
.
argv
[
2
])
elif
argv_len
==
4
:
res
=
method
(
sys
.
argv
[
2
],
sys
.
argv
[
3
])
elif
argv_len
==
5
:
res
=
method
(
sys
.
argv
[
2
],
sys
.
argv
[
3
],
sys
.
argv
[
4
])
return
res
except
:
send_error
(
_
(
'
Service not available
'
))
return
None
argv_len
=
len
(
sys
.
argv
)
...
...
@@ -205,7 +246,7 @@ def gtk_quit():
try
:
sbus
=
dbus
.
SessionBus
()
except
:
send_error
(
'
Session bus is not available.
\n
'
)
send_error
(
_
(
'
Session bus is not available.
\n
'
)
)
if
_version
[
1
]
>=
30
and
_version
[
1
]
<=
42
:
...
...
@@ -215,36 +256,19 @@ def gtk_quit():
service
=
sbus
.
get_service
(
SERVICE
)
interface
=
service
.
get_object
(
OBJ_PATH
,
INTERFACE
)
else
:
send_error
(
'
Unknow dbus version:
'
+
_version
)
send_error
(
_
(
'
Unknow dbus version:
%s
'
)
%
_version
)
method
=
interface
.
__getattr__
(
sys
.
argv
[
1
])
# get the function asked
check_arguments
(
command
)
if
command
==
'
contact_info
'
:
if
argv_len
<
3
:
send_error
(
'
Missing argument
\'
contact_jid
\'
'
)
send_error
(
_
(
'
Missing argument
\'
contact_jid
\'
'
)
)
try
:
id
=
sbus
.
add_signal_receiver
(
show_vcard_info
,
'
VcardInfo
'
,
INTERFACE
,
SERVICE
,
OBJ_PATH
)
except
:
send_error
(
'
Service not available
'
)
#FIXME - didn't find more clever way for the below 8 lines of code.
# method(sys.argv[2:]) doesn't work, cos sys.argv[2:] is a tuple
def
call_remote_method
(
method
):
argv_len
=
len
(
sys
.
argv
)
try
:
if
argv_len
==
2
:
res
=
method
()
elif
argv_len
==
3
:
res
=
method
(
sys
.
argv
[
2
])
elif
argv_len
==
4
:
res
=
method
(
sys
.
argv
[
2
],
sys
.
argv
[
3
])
elif
argv_len
==
5
:
res
=
method
(
sys
.
argv
[
2
],
sys
.
argv
[
3
],
sys
.
argv
[
4
])
return
res
except
:
send_error
(
_
(
'
Service not available
'
))
return
None
res
=
call_remote_method
(
method
)
...
...
This diff is collapsed.
Click to expand it.
src/remote_control.py
+
2
−
1
View file @
875a875a
...
...
@@ -229,7 +229,8 @@ def contact_info(self, *args):
You have to register the
'
VcardInfo
'
signal to get the real vcard.
'''
if
self
.
disabled
:
return
jid
=
self
.
_get_real_arguments
(
args
,
1
)
[
jid
]
=
self
.
_get_real_arguments
(
args
,
1
)
if
not
jid
:
# FIXME: raise exception for missing argument (0.3+)
return
None
...
...
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