rename some variables to remove some pylint warning

This commit is contained in:
Yann Leboulanger 2010-02-10 14:00:28 +01:00
parent fcada2f98d
commit c887a92b3a
1 changed files with 28 additions and 35 deletions

View File

@ -70,15 +70,15 @@ import getopt
from common import i18n from common import i18n
def parseOpts(): def parseOpts():
profile = '' profile_ = ''
config_path = None config_path_ = None
try: try:
shortargs = 'hqvl:p:c:' shortargs = 'hqvl:p:c:'
longargs = 'help quiet verbose loglevel= profile= config_path=' longargs = 'help quiet verbose loglevel= profile= config_path='
opts = getopt.getopt(sys.argv[1:], shortargs, longargs.split())[0] opts = getopt.getopt(sys.argv[1:], shortargs, longargs.split())[0]
except getopt.error, msg: except getopt.error, msg1:
print msg print msg1
print 'for help use --help' print 'for help use --help'
sys.exit(2) sys.exit(2)
for o, a in opts: for o, a in opts:
@ -92,12 +92,12 @@ def parseOpts():
elif o in ('-v', '--verbose'): elif o in ('-v', '--verbose'):
logging_helpers.set_verbose() logging_helpers.set_verbose()
elif o in ('-p', '--profile'): # gajim --profile name elif o in ('-p', '--profile'): # gajim --profile name
profile = a profile_ = a
elif o in ('-l', '--loglevel'): elif o in ('-l', '--loglevel'):
logging_helpers.set_loglevels(a) logging_helpers.set_loglevels(a)
elif o in ('-c', '--config-path'): elif o in ('-c', '--config-path'):
config_path = a config_path_ = a
return profile, config_path return profile_, config_path_
profile, config_path = parseOpts() profile, config_path = parseOpts()
del parseOpts del parseOpts
@ -136,11 +136,11 @@ if os.name == 'nt':
warnings.filterwarnings('error', module='gtk') warnings.filterwarnings('error', module='gtk')
try: try:
import gtk import gtk
except Warning, msg: except Warning, msg2:
if str(msg) == 'could not open display': if str(msg2) == 'could not open display':
print >> sys.stderr, _('Gajim needs X server to run. Quiting...') print >> sys.stderr, _('Gajim needs X server to run. Quiting...')
else: else:
print >> sys.stderr, _('importing PyGTK failed: %s') % str(msg) print >> sys.stderr, _('importing PyGTK failed: %s') % str(msg2)
sys.exit() sys.exit()
warnings.resetwarnings() warnings.resetwarnings()
@ -268,7 +268,7 @@ def pid_alive():
('szExeFile', c_char*512, ), ('szExeFile', c_char*512, ),
] ]
def __init__(self): def __init__(self):
Structure.__init__(self, 512+9*4) super(PROCESSENTRY32, self).__init__(self, 512+9*4)
k = windll.kernel32 k = windll.kernel32
k.CreateToolhelp32Snapshot.argtypes = c_ulong, c_ulong, k.CreateToolhelp32Snapshot.argtypes = c_ulong, c_ulong,
@ -278,15 +278,15 @@ def pid_alive():
k.Process32Next.argtypes = c_int, POINTER(PROCESSENTRY32), k.Process32Next.argtypes = c_int, POINTER(PROCESSENTRY32),
k.Process32Next.restype = c_int k.Process32Next.restype = c_int
def get_p(p): def get_p(pid_):
h = k.CreateToolhelp32Snapshot(2, 0) # TH32CS_SNAPPROCESS h = k.CreateToolhelp32Snapshot(2, 0) # TH32CS_SNAPPROCESS
assert h > 0, 'CreateToolhelp32Snapshot failed' assert h > 0, 'CreateToolhelp32Snapshot failed'
b = pointer(PROCESSENTRY32()) b = pointer(PROCESSENTRY32())
f = k.Process32First(h, b) f3 = k.Process32First(h, b)
while f: while f3:
if b.contents.th32ProcessID == p: if b.contents.th32ProcessID == pid_:
return b.contents.szExeFile return b.contents.szExeFile
f = k.Process32Next(h, b) f3 = k.Process32Next(h, b)
if get_p(pid) in ('python.exe', 'gajim.exe'): if get_p(pid) in ('python.exe', 'gajim.exe'):
return True return True
@ -296,14 +296,14 @@ def pid_alive():
return True # no /proc, assume Gajim is running return True # no /proc, assume Gajim is running
try: try:
f = open('/proc/%d/cmdline'% pid) f1 = open('/proc/%d/cmdline'% pid)
except IOError, e: except IOError, e1:
if e.errno == errno.ENOENT: if e1.errno == errno.ENOENT:
return False # file/pid does not exist return False # file/pid does not exist
raise raise
n = f.read().lower() n = f1.read().lower()
f.close() f1.close()
if n.find('gajim') < 0: if n.find('gajim') < 0:
return False return False
return True # Running Gajim found at pid return True # Running Gajim found at pid
@ -338,16 +338,15 @@ if not os.path.exists(pid_dir):
check_paths.create_path(pid_dir) check_paths.create_path(pid_dir)
# Create pid file # Create pid file
try: try:
f = open(pid_filename, 'w') f2 = open(pid_filename, 'w')
f.write(str(os.getpid())) f2.write(str(os.getpid()))
f.close() f2.close()
except IOError, e: except IOError, e2:
dlg = dialogs.ErrorDialog(_('Disk Write Error'), str(e)) dlg = dialogs.ErrorDialog(_('Disk Write Error'), str(e2))
dlg.run() dlg.run()
dlg.destroy() dlg.destroy()
sys.exit() sys.exit()
del pid_dir del pid_dir
del f
def on_exit(): def on_exit():
# delete pid file on normal exit # delete pid file on normal exit
@ -379,7 +378,7 @@ if __name__ == '__main__':
except ImportError: except ImportError:
pass pass
else: else:
def die_cb(cli): def die_cb(dummy):
gajim.interface.roster.quit_gtkgui_interface() gajim.interface.roster.quit_gtkgui_interface()
gnome.program_init('gajim', gajim.version) gnome.program_init('gajim', gajim.version)
cli = gnome.ui.master_client() cli = gnome.ui.master_client()
@ -390,13 +389,7 @@ if __name__ == '__main__':
if path_to_gajim_script: if path_to_gajim_script:
argv = [path_to_gajim_script] argv = [path_to_gajim_script]
# FIXME: remove this typeerror catch when gnome python is old cli.set_restart_command(len(argv), argv)
# and not bad patched by distro men [2.12.0 + should not need
# all that NORMALLY]
try:
cli.set_restart_command(argv)
except AttributeError:
cli.set_restart_command(len(argv), argv)
check_paths.check_and_possibly_create_paths() check_paths.check_and_possibly_create_paths()