Skip to content

Commit 1e627dd

Browse files
committed
prepare for py3 by replacing obsoleted string.letters with backwardscompatible string.ascii_letters. Fix codegrep etc. to work on files relative to 'mig' code root dir again
git-svn-id: svn+ssh://svn.code.sf.net/p/migrid/code/trunk@4898 b75ad72c-e7d7-11dd-a971-7dbc132099af
1 parent 1a43ff8 commit 1e627dd

7 files changed

+64
-46
lines changed

addheader.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@
3535
import os
3636
import sys
3737

38-
from mig.shared.projcode import py_code_files, sh_code_files, js_code_files
38+
from mig.shared.projcode import code_root, py_code_files, sh_code_files, \
39+
js_code_files
3940

4041
# Modify these to fit actual project
4142
proj_vars = {}
@@ -185,7 +186,7 @@ def add_header(path, var_dict, explicit_border=True, block_wrap=False):
185186
else:
186187
needs_block = False
187188

188-
pattern = os.path.join(mig_code_base, pattern)
189+
pattern = os.path.join(mig_code_base, code_root, pattern)
189190

190191
# print "Testing %s against %s" % (src_path, pattern)
191192

bugweed.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@
3131
from __future__ import absolute_import
3232

3333
import glob
34+
import os
3435
import sys
3536

36-
from mig.shared.projcode import py_code_files
37+
from mig.shared.projcode import code_root, py_code_files
3738
from mig.shared.safeeval import subprocess_call
3839

3940
if '__main__' == __name__:
@@ -42,9 +43,11 @@
4243
print('Grep for obvious errors in all code files')
4344
sys.exit(1)
4445

46+
mig_code_base = os.path.dirname(sys.argv[0])
4547
expanded_paths = []
4648
for code_path in py_code_files:
47-
expanded_paths += glob.glob(code_path)
49+
path_pattern = os.path.join(mig_code_base, code_root, code_path)
50+
expanded_paths += glob.glob(os.path.normpath(path_pattern))
4851
command_list = ["pylint", "-E"] + expanded_paths
4952
command = ' '.join(command_list)
5053
print("Bug weeding command: %s" % command)

codegrep.py

+5-2
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,10 @@
3232
from __future__ import absolute_import
3333

3434
import glob
35+
import os
3536
import sys
3637

37-
from mig.shared.projcode import code_files
38+
from mig.shared.projcode import code_root, code_files
3839
from mig.shared.safeeval import subprocess_call
3940

4041

@@ -44,10 +45,12 @@
4445
print('Grep for PATTERN in all code files')
4546
sys.exit(1)
4647

48+
mig_code_base = os.path.dirname(sys.argv[0])
4749
pattern = sys.argv[1]
4850
expanded_paths = []
4951
for code_path in code_files:
50-
expanded_paths += glob.glob(code_path)
52+
path_pattern = os.path.join(mig_code_base, code_root, code_path)
53+
expanded_paths += glob.glob(os.path.normpath(path_pattern))
5154
command_list = ["grep", "-E", "%s" % pattern] + expanded_paths
5255
# NOTE: we use command list to avoid shell requirement
5356
subprocess_call(command_list)

mig/shared/findtype.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
# --- BEGIN_HEADER ---
55
#
66
# findtype - Detect client entity type
7-
# Copyright (C) 2003-2018 The MiG Project lead by Brian Vinter
7+
# Copyright (C) 2003-2020 The MiG Project lead by Brian Vinter
88
#
99
# This file is part of MiG.
1010
#
@@ -29,15 +29,15 @@
2929
from __future__ import absolute_import
3030

3131
import os
32-
from string import letters, digits
32+
from string import ascii_letters, digits
3333

3434
from mig.shared.defaults import user_db_filename
3535
from mig.shared.base import client_id_dir
3636
from mig.shared.listhandling import is_item_in_pickled_list
3737
from mig.shared.validstring import valid_user_path
3838
from mig.shared.serial import load
3939

40-
VALID_FQDN_CHARACTERS = letters + digits + '.-'
40+
VALID_FQDN_CHARACTERS = ascii_letters + digits + '.-'
4141
MIG_SERVER_ID = 'MiG-Server'
4242

4343

mig/shared/mrsltoxrsl.py

+11-12
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
#!/usr/bin/python
22
# -*- coding: utf-8 -*-
3-
43
#
54
# --- BEGIN_HEADER ---
65
#
76
#
87
# mrsltoxrsl - [optionally add short module description on this line]
9-
# Copyright (C) 2003-2017 The MiG Project lead by Brian Vinter
8+
# Copyright (C) 2003-2020 The MiG Project lead by Brian Vinter
109
#
1110
# This file is part of MiG.
1211
#
@@ -97,10 +96,10 @@ def indent(acc, n, s):
9796
if not s:
9897
return acc
9998
if s[0] == '(':
100-
start = '\n' + ' '*n
101-
return(indent(acc + start + '(', n+2, s[1:]))
99+
start = '\n' + ' ' * n
100+
return(indent(acc + start + '(', n + 2, s[1:]))
102101
elif s[0] == ')':
103-
return(indent(acc + ')', n-2, s[1:]))
102+
return(indent(acc + ')', n - 2, s[1:]))
104103

105104
return(indent(acc + s[0], n, s[1:]))
106105

@@ -111,7 +110,7 @@ def indent(acc, n, s):
111110
# -> (Xrsl,Job Script,name for Job script)
112111
def translate(mrsl_dict, session_id=None):
113112
"""Translate an (already checked) mRSL dictionary into xRSL,
114-
suitable for submitting to an ARC resource.
113+
suitable for submitting to an ARC resource.
115114
116115
Returns arclib.Xrsl object.
117116
Throws exception if errors in the xRSL generation occur."""
@@ -167,10 +166,10 @@ def translate(mrsl_dict, session_id=None):
167166
j_name = mrsl_dict['JOB_ID']
168167
else:
169168
# random string. should not happen anyway...
170-
j_name = ''.join(random.choice(string.letters)
169+
j_name = ''.join(random.choice(string.ascii_letters)
171170
for i in xrange(12))
172171
# j_name = mrsl_dict.get('JOB_ID',
173-
# ''.join(random.choice(string.letters) \
172+
# ''.join(random.choice(string.ascii_letters) \
174173
# for i in xrange(12)))
175174

176175
# use JOBID as ARC jobname to avoid presenting only ARC IDs
@@ -247,7 +246,7 @@ def fst(list):
247246
# requested runtime, given in minutes in (user) xrsl ...
248247
time = mrsl_dict.get('CPUTIME')
249248
if time:
250-
addRel(xrsl, 'cputime', str(int(math.ceil(float(time)/60))))
249+
addRel(xrsl, 'cputime', str(int(math.ceil(float(time) / 60))))
251250

252251
# simply copy the values for these:
253252
copy_items = ['MEMORY', 'DISK', 'NODECOUNT']
@@ -286,8 +285,8 @@ def fst(list):
286285
if address != 'SETTINGS':
287286
addresses.append(address)
288287
# else:
289-
# # this should be replaced already, but...
290-
# # FIXME: get it from the settings :-P
288+
# this should be replaced already, but...
289+
# FIXME: get it from the settings :-P
291290
# addresses.append('*FROM THE SETTINGS*')
292291
if addresses:
293292
addRel(xrsl, 'notify', 'ec ' + ' '.join(addresses))
@@ -354,7 +353,7 @@ def is_mail(str):
354353

355354

356355
def file_mapping(line):
357-
"""Splits the given line of the expected format
356+
"""Splits the given line of the expected format
358357
local_name <space> remote_name
359358
into a 2-element list [local_name,remote_name]
360359
If remote_name is empty, the empty string is returned as the 2nd part.

mig/shared/projcode.py

+5
Original file line numberDiff line numberDiff line change
@@ -23,9 +23,14 @@
2323

2424
"""Helpers to transform or search project code files"""
2525

26+
# Top dir with all code
27+
code_root = 'mig'
28+
2629
# Ignore backup and dot files in wild card match
2730
plain = '[a-zA-Z0-9]*.py'
2831
py_code_files = [
32+
# a few scripts are in parent dir of code_root
33+
'../%s' % plain,
2934
'%s' % plain,
3035
'cgi-bin/%s' % plain,
3136
'cgi-sid/%s' % plain,

mig/shared/safeinput.py

+32-25
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939

4040
import cgi
4141
from email.utils import parseaddr, formataddr
42-
from string import letters, digits, printable
42+
from string import ascii_letters, digits, printable
4343
from unicodedata import category, normalize, name as unicode_name
4444

4545
from mig.shared.base import force_unicode, force_utf8
@@ -105,16 +105,16 @@
105105

106106
# We must be careful about characters that have special regex meaning
107107

108-
VALID_SAFE_PATH_CHARACTERS = letters + digits + "/.,_-+="
109-
VALID_PATH_CHARACTERS = letters + digits + CURRENCY + "/.,_-+±×÷=½¾" + \
108+
VALID_SAFE_PATH_CHARACTERS = ascii_letters + digits + "/.,_-+="
109+
VALID_PATH_CHARACTERS = ascii_letters + digits + CURRENCY + "/.,_-+±×÷=½¾" + \
110110
" " + "'" + ":;@§%‰()~!&¶"
111111

112112
# Plain text here only - *no* html tags, i.e. no '<' or '>' !!
113113

114114
VALID_TEXT_CHARACTERS = VALID_PATH_CHARACTERS + CURRENCY + '?#*[]{}' + '"' + \
115115
"`|^" + '\\' + '\n\r\t'
116-
VALID_FQDN_CHARACTERS = letters + digits + '.-'
117-
VALID_BACKEND_NAME_CHARACTERS = letters + digits + '-_'
116+
VALID_FQDN_CHARACTERS = ascii_letters + digits + '.-'
117+
VALID_BACKEND_NAME_CHARACTERS = ascii_letters + digits + '-_'
118118
VALID_BASEURL_CHARACTERS = VALID_FQDN_CHARACTERS + ':/_'
119119
VALID_URL_CHARACTERS = VALID_BASEURL_CHARACTERS + '?;&%='
120120
# According to https://tools.ietf.org/html/rfc3986#section-2 URLs may contain
@@ -138,15 +138,15 @@
138138
# Allow these chars in addition to plain letters and digits
139139
# We explicitly allow email chars in CN to work around broken DNs
140140

141-
#############################################################################
142-
# IMPORTANT: never allow '+' or '_' in name: reserved for path translation! #
143-
#############################################################################
141+
#*****************************************************************************
142+
#* IMPORTANT: never allow '+' or '_' in name: reserved for path translation! *
143+
#*****************************************************************************
144144

145145
name_extras = ' -@.'
146146

147-
#############################################################################
148-
# IMPORTANT: never allow '+' in DN: reserved for path translation! #
149-
#############################################################################
147+
#*****************************************************************************
148+
#* IMPORTANT: never allow '+' in DN: reserved for path translation! *
149+
#*****************************************************************************
150150
# We allow ':' in DN, however, as it is used by e.g. DanID:
151151
# /C=DK/O=Ingen organisatorisk tilknytning/CN=${NAME}/serialNumber=PID:${SERIAL}
152152
# Similarly we must allow '_' in DN since it is valid in emailAddress. We only
@@ -165,9 +165,9 @@
165165

166166
valid_integer_chars = digits + integer_extras
167167
valid_float_chars = digits + float_extras
168-
valid_password_chars = letters + digits + password_extras
169-
valid_name_chars = letters + digits + name_extras
170-
valid_dn_chars = letters + digits + dn_extras
168+
valid_password_chars = ascii_letters + digits + password_extras
169+
valid_name_chars = ascii_letters + digits + name_extras
170+
valid_dn_chars = ascii_letters + digits + dn_extras
171171
valid_username_chars = user_id_charset
172172
VALID_INTEGER_CHARACTERS = valid_integer_chars
173173
VALID_FLOAT_CHARACTERS = valid_float_chars
@@ -305,7 +305,8 @@ def valid_printable(contents, min_length=0, max_length=-1):
305305
def valid_ascii(contents, min_length=0, max_length=-1, extra_chars=''):
306306
"""Verify that supplied contents only contain ascii characters"""
307307

308-
__valid_contents(contents, letters + extra_chars, min_length, max_length)
308+
__valid_contents(
309+
contents, ascii_letters + extra_chars, min_length, max_length)
309310

310311

311312
def valid_numeric(contents, min_length=0, max_length=-1):
@@ -317,7 +318,8 @@ def valid_numeric(contents, min_length=0, max_length=-1):
317318
def valid_alphanumeric(contents, min_length=0, max_length=-1, extra_chars=''):
318319
"""Verify that supplied contents only contain alphanumeric characters"""
319320

320-
__valid_contents(contents, letters + digits + extra_chars, min_length,
321+
__valid_contents(
322+
contents, ascii_letters + digits + extra_chars, min_length,
321323
max_length)
322324

323325

@@ -814,7 +816,7 @@ def __valid_gdp_var(gdp_var):
814816
"""Verify that supplied gdp_var only contains characters that
815817
we consider valid in various gdp variable names.
816818
"""
817-
__valid_contents(gdp_var, letters + '_')
819+
__valid_contents(gdp_var, ascii_letters + '_')
818820

819821

820822
def valid_gdp_category_id(category_id):
@@ -835,7 +837,7 @@ def valid_gdp_ref_value(ref_value):
835837
"""Verify that supplied ref_value only contains characters that
836838
we consider valid in GDP ref values.
837839
"""
838-
__valid_contents(ref_value, letters + digits + '+-=/.:_')
840+
__valid_contents(ref_value, ascii_letters + digits + '+-=/.:_')
839841

840842

841843
def valid_cloud_instance_id(
@@ -1026,8 +1028,9 @@ def valid_workflow_attributes(attributes):
10261028

10271029

10281030
def valid_workflow_operation(operation):
1029-
"""Verify that the supplied workflow
1030-
operation only contains letters + _ """
1031+
"""Verify that the supplied workflow operation only contains letters and
1032+
underscores.
1033+
"""
10311034
valid_ascii(operation, extra_chars='_')
10321035

10331036

@@ -1055,19 +1058,23 @@ def valid_job_attributes(attributes):
10551058

10561059

10571060
def valid_job_type(type):
1058-
"""Verify that the supplied job type only contains letters + _ """
1061+
"""Verify that the supplied job type only contains letters and
1062+
underscores.
1063+
"""
10591064
valid_ascii(type, extra_chars='_')
10601065

10611066

10621067
def valid_job_operation(operation):
1063-
"""Verify that the supplied job operation only contains letters + _ """
1068+
"""Verify that the supplied job operation only contains letters and
1069+
underscores.
1070+
"""
10641071
valid_ascii(operation, extra_chars='_')
10651072

10661073

10671074
def filter_ascii(contents):
10681075
"""Filter supplied contents to only contain ascii characters"""
10691076

1070-
return __filter_contents(contents, letters)
1077+
return __filter_contents(contents, ascii_letters)
10711078

10721079

10731080
def filter_numeric(contents):
@@ -1079,13 +1086,13 @@ def filter_numeric(contents):
10791086
def filter_alphanumeric(contents):
10801087
"""Filter supplied contents to only contain alphanumeric characters"""
10811088

1082-
return __filter_contents(contents, letters + digits)
1089+
return __filter_contents(contents, ascii_letters + digits)
10831090

10841091

10851092
def filter_alphanumeric_and_spaces(contents):
10861093
"""Filter supplied contents to only contain alphanumeric characters"""
10871094

1088-
return __filter_contents(contents, letters + digits + ' ')
1095+
return __filter_contents(contents, ascii_letters + digits + ' ')
10891096

10901097

10911098
def filter_date(contents):

0 commit comments

Comments
 (0)