Skip to content

Commit

Permalink
Use /usr/bin/env python for virtualenv (mininet#1025)
Browse files Browse the repository at this point in the history
This helps with virtualenv although it can open
up another security hole if you end up using an
unexpected python interpreter.

Overall it seems to make sense to err on the side
of usability but it's good to be aware of security.

However, for the remaining utility scripts that require
python 2, we explicitly note this with #!/usr/bin/python2.
  • Loading branch information
lantz authored Feb 5, 2021
1 parent a882d68 commit f0c726a
Show file tree
Hide file tree
Showing 39 changed files with 53 additions and 57 deletions.
2 changes: 1 addition & 1 deletion bin/mn
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Mininet runner
Expand Down
2 changes: 1 addition & 1 deletion examples/baresshd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"This example doesn't use OpenFlow, but attempts to run sshd in a namespace."

Expand Down
2 changes: 1 addition & 1 deletion examples/bind.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
bind.py: Bind mount example
Expand Down
2 changes: 1 addition & 1 deletion examples/cluster.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
cluster.py: prototyping/experimentation for distributed Mininet,
Expand Down
2 changes: 1 addition & 1 deletion examples/clustercli.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"CLI for Mininet Cluster Edition prototype demo"

Expand Down
2 changes: 1 addition & 1 deletion examples/clusterdemo.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"clusterdemo.py: demo of Mininet Cluster Edition prototype"

Expand Down
2 changes: 1 addition & 1 deletion examples/clusterperf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"clusterperf.py compare the maximum throughput between SSH and GRE tunnels"

Expand Down
2 changes: 1 addition & 1 deletion examples/consoles.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
consoles.py: bring up a bunch of miniature consoles on a virtual network
Expand Down
2 changes: 1 addition & 1 deletion examples/controllers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Create a network where different switches are connected to
Expand Down
2 changes: 1 addition & 1 deletion examples/controllers2.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
This example creates a multi-controller network from semi-scratch by
Expand Down
2 changes: 1 addition & 1 deletion examples/controlnet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
controlnet.py: Mininet with a custom control network
Expand Down
2 changes: 1 addition & 1 deletion examples/cpu.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
cpu.py: test iperf bandwidth for varying cpu limits
Expand Down
2 changes: 1 addition & 1 deletion examples/emptynet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
This example shows how to create an empty Mininet object
Expand Down
2 changes: 1 addition & 1 deletion examples/hwintf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
This example shows how to add an interface (for example a real
Expand Down
2 changes: 1 addition & 1 deletion examples/intfoptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

'''
example of using various TCIntf options.
Expand Down
2 changes: 1 addition & 1 deletion examples/limit.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
limit.py: example of using link and CPU limits
Expand Down
2 changes: 1 addition & 1 deletion examples/linearbandwidth.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Test bandwidth (using iperf) on linear networks of varying size,
Expand Down
2 changes: 1 addition & 1 deletion examples/linuxrouter.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
linuxrouter.py: Example network with Linux IP router
Expand Down
2 changes: 1 addition & 1 deletion examples/miniedit.py
Original file line number Diff line number Diff line change
Expand Up @@ -1704,7 +1704,7 @@ def exportScript( self ):
# debug( "Now saving under %s\n" % fileName )
f = open(fileName, 'wb')

f.write("#!/usr/bin/python\n")
f.write("#!/usr/bin/env python\n")
f.write("\n")
f.write("from mininet.net import Mininet\n")
f.write("from mininet.node import Controller, RemoteController, OVSController\n")
Expand Down
2 changes: 1 addition & 1 deletion examples/mobility.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Simple example of Mobility with Mininet
Expand Down
2 changes: 1 addition & 1 deletion examples/multilink.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
This is a simple example that demonstrates multiple links
Expand Down
2 changes: 1 addition & 1 deletion examples/multiping.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
multiping.py: monitor multiple sets of hosts using ping
Expand Down
2 changes: 1 addition & 1 deletion examples/multipoll.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Simple example of sending output to multiple files and
Expand Down
2 changes: 1 addition & 1 deletion examples/multitest.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
This example shows how to create a network and run multiple tests.
Expand Down
2 changes: 1 addition & 1 deletion examples/nat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Example to create a Mininet topology and connect it to the internet via NAT
Expand Down
2 changes: 1 addition & 1 deletion examples/natnet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
natnet.py: Example network with NATs
Expand Down
2 changes: 1 addition & 1 deletion examples/numberedports.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Create a network with 5 hosts, numbered 1-4 and 9.
Expand Down
2 changes: 1 addition & 1 deletion examples/popen.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
This example monitors a number of hosts using host.popen() and
Expand Down
2 changes: 1 addition & 1 deletion examples/popenpoll.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"Monitor multiple hosts using popen()/pmonitor()"

Expand Down
2 changes: 1 addition & 1 deletion examples/scratchnet.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Build a simple network from scratch, using mininet primitives.
Expand Down
2 changes: 1 addition & 1 deletion examples/scratchnetuser.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Build a simple network from scratch, using mininet primitives.
Expand Down
2 changes: 1 addition & 1 deletion examples/simpleperf.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Simple example of setting network and CPU parameters
Expand Down
2 changes: 1 addition & 1 deletion examples/sshd.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Create a network and start sshd(8) on each host.
Expand Down
2 changes: 1 addition & 1 deletion examples/tree1024.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"""
Create a 1024-host network, and run the CLI on it.
Expand Down
2 changes: 1 addition & 1 deletion examples/treeping64.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

"Create a 64-node tree network, and test connectivity using ping."

Expand Down
6 changes: 1 addition & 5 deletions util/doxify.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python2

"""
Convert simple documentation to epydoc/pydoctor-compatible markup
Expand Down Expand Up @@ -83,7 +83,3 @@ def fixLines( lines, fid ):
infile.close()
os.close( outfid )
call( [ 'doxypy', outname ] )




30 changes: 15 additions & 15 deletions util/unpep8
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#!/usr/bin/python
#!/usr/bin/python2

"""
Translate from PEP8 Python style to Mininet (i.e. Arista-like)
Translate from PEP8 Python style to Mininet (i.e. Arista-like)
Python style
usage: unpep8 < old.py > new.py
Expand Down Expand Up @@ -51,7 +51,7 @@ def fixUnderscoreTriplet( match ):
def reinstateCapWords( text ):
underscoreTriplet = re.compile( r'[A-Za-z0-9]_[A-Za-z0-9]' )
return underscoreTriplet.sub( fixUnderscoreTriplet, text )

def replaceTripleApostrophes( text ):
"Replace triple apostrophes with triple quotes."
return text.replace( "'''", '"""')
Expand All @@ -60,7 +60,7 @@ def simplifyTripleQuotes( text ):
"Fix single-line doc strings."
r = re.compile( r'"""([^\"\n]+)"""' )
return r.sub( r'"\1"', text )

def insertExtraSpaces( text ):
"Insert extra spaces inside of parentheses and brackets/curly braces."
lparen = re.compile( r'\((?![\s\)])' )
Expand All @@ -76,9 +76,9 @@ def insertExtraSpaces( text ):
lcurly = re.compile( r'\{(?![\s\}])' )
text = lcurly.sub( r'{ ', text )
rcurly = re.compile( r'([^\s\{])(?=\})' )
text = rcurly.sub( r'\1 ', text)
text = rcurly.sub( r'\1 ', text)
return text

def fixDoxygen( text ):
"""Translate @param foo to foo:, @return bar to returns: bar, and
@author me to author: me"""
Expand All @@ -96,11 +96,11 @@ def removeCommentFirstBlankLine( text ):
"Remove annoying blank lines after first line in comments."
line = re.compile( r'("""[^\n]*\n)\s*\n', re.MULTILINE )
return line.sub( r'\1', text )

def fixArgs( match, kwarg = re.compile( r'(\w+) = ' ) ):
"Replace foo = bar with foo=bar."
return kwarg.sub( r'\1=', match.group() )

def fixKeywords( text ):
"Change keyword argumentsfrom foo = bar to foo=bar."
args = re.compile( r'\(([^\)]+)\)', re.MULTILINE )
Expand All @@ -115,7 +115,7 @@ def fixKeywords( text ):
def lineIter( text ):
"Simple iterator over lines in text."
for line in text.splitlines(): yield line

def stringIter( strList ):
"Yield strings in strList."
for s in strList: yield s
Expand All @@ -134,7 +134,7 @@ def restoreRegex( regex, old, new ):
# This is a cheap hack, and it may not work 100%, since
# it doesn't handle multiline strings.
# However, it should be mostly harmless...

def restoreStrings( oldText, newText ):
"Restore strings from oldText into newText, returning result."
oldLines, newLines = lineIter( oldText ), lineIter( newText )
Expand All @@ -149,13 +149,13 @@ def restoreStrings( oldText, newText ):
newLine = restoreRegex( tickStrings, oldLine, newLine )
result += newLine + '\n'
return result

# This might be slightly controversial, since it uses
# three spaces to line up multiline comments. However,
# I much prefer it. Limitations: if you have deeper
# indents in comments, they will be eliminated. ;-(

def fixComment( match,
def fixComment( match,
indentExp=re.compile( r'\n([ ]*)(?=[^/s])', re.MULTILINE ),
trailingQuotes=re.compile( r'\s+"""' ) ):
"Re-indent comment, and join trailing quotes."
Expand All @@ -166,17 +166,17 @@ def fixComment( match,
if len( originalIndent ) is not 0: indent += ' '
comment = indentExp.sub( indent, comment )
return originalIndent + trailingQuotes.sub( '"""', comment )

def fixCommentIndents( text ):
"Fix multiline comment indentation."
comments = re.compile( r'^([ ]*)("""[^"]*""")$', re.MULTILINE )
return comments.sub( fixComment, text )

def removeBogusLinefeeds( text ):
"Remove extra linefeeds at the end of single-line comments."
bogusLfs = re.compile( r'"([^"\n]*)\n"', re.MULTILINE )
return bogusLfs.sub( '"\1"', text)

def convertFromPep8( program ):
oldProgram = program
# Program text transforms
Expand Down
2 changes: 1 addition & 1 deletion util/versioncheck.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python

from subprocess import check_output as co
from sys import exit, version_info
Expand Down
2 changes: 1 addition & 1 deletion util/vm/build.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python2.7
#!/usr/bin/python2

"""
build.py: build a Mininet VM
Expand Down

0 comments on commit f0c726a

Please sign in to comment.