Skip to content

Commit

Permalink
Try updating to python3 (#48367)
Browse files Browse the repository at this point in the history
* Try updating to python3

* Fix submods

* Print syntax

* More

* More fixups

* Fix iteritems

* Headers
  • Loading branch information
wtgodbe authored May 23, 2023
1 parent 3d55a2b commit 6c66253
Show file tree
Hide file tree
Showing 7 changed files with 20 additions and 20 deletions.
2 changes: 1 addition & 1 deletion eng/docker/bionic.Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ RUN apt-get update && \
jq \
wget \
locales \
python \
python3 \
fakeroot \
debhelper \
build-essential \
Expand Down
6 changes: 3 additions & 3 deletions src/Installers/Debian/tools/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ validate_inputs(){
}

parse_config_and_set_env_vars(){
extract_base_cmd="python $SCRIPT_DIR/scripts/extract_json_value.py"
extract_base_cmd="python3 $SCRIPT_DIR/scripts/extract_json_value.py"

# Arguments Take Precedence over Config
[ -z "$PACKAGE_VERSION" ] && PACKAGE_VERSION="$($extract_base_cmd $CONFIG "release.package_version")"
Expand Down Expand Up @@ -232,15 +232,15 @@ package_install_scripts(){

## Generation Functions ##
generate_config_templates(){
python ${SCRIPT_DIR}/scripts/config_template_generator.py $CONFIG $SCRIPT_DIR/templates/debian $DEBIAN_DIR $PACKAGE_NAME $PACKAGE_VERSION
python3 ${SCRIPT_DIR}/scripts/config_template_generator.py $CONFIG $SCRIPT_DIR/templates/debian $DEBIAN_DIR $PACKAGE_NAME $PACKAGE_VERSION
}

generate_manpages(){
if [[ -f "$DOCS_JSON_PATH" ]]; then
mkdir -p $DOCS_DIR

# Generate the manpages from json spec
python ${SCRIPT_DIR}/scripts/manpage_generator.py ${DOCS_JSON_PATH} ${DOCS_DIR}
python3 ${SCRIPT_DIR}/scripts/manpage_generator.py ${DOCS_JSON_PATH} ${DOCS_DIR}
fi
}

Expand Down
10 changes: 5 additions & 5 deletions src/Installers/Debian/tools/scripts/config_template_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
Expand Down Expand Up @@ -47,7 +47,7 @@ def generate_and_write_all(config_data, template_dir, output_dir, package_name=N
symlink_contents = generate_symlinks(config_data, package_name=package_name)
rules_contents = generate_rules(config_data, template_dir)
except Exception as exc:
print exc
print(exc)
help_and_exit("Error: Generation Failed, check your config file.")

write_file(changelog_contents, output_dir, FILE_CHANGELOG)
Expand Down Expand Up @@ -157,7 +157,7 @@ def generate_symlinks(config_data, package_name=None):

symlink_data = config_data.get("symlinks", dict())

for package_rel_path, symlink_path in symlink_data.iteritems():
for package_rel_path, symlink_path in iter(symlink_data.items()):

package_abs_path = os.path.join(package_root_path, package_rel_path)

Expand Down Expand Up @@ -222,11 +222,11 @@ def write_file(contents, output_dir, name):

# Tool Functions
def help_and_exit(msg):
print msg
print(msg)
sys.exit(1)

def print_usage():
print "Usage: config_template_generator.py [config file path] [template directory path] [output directory] (package name) (package version)"
print("Usage: config_template_generator.py [config file path] [template directory path] [output directory] (package name) (package version)")

def parse_and_validate_args():
if len(sys.argv) < 4:
Expand Down
10 changes: 5 additions & 5 deletions src/Installers/Debian/tools/scripts/extract_json_value.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
Expand All @@ -12,13 +12,13 @@
import json

def print_usage():
print """
print("""
Usage: extract_json_value.py [json file path] [key of value to extract]
For nested keys, use . separator
"""
""")

def help_and_exit(msg=None):
print msg
print(msg)
print_usage()
sys.exit(1)

Expand Down Expand Up @@ -60,5 +60,5 @@ def execute():
return value

if __name__ == "__main__":
print execute()
print(execute())

8 changes: 4 additions & 4 deletions src/Installers/Debian/tools/scripts/manpage_generator.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/python3
#
# Copyright (c) .NET Foundation and contributors. All rights reserved.
# Licensed under the MIT license. See LICENSE file in the project root for full license information.
Expand Down Expand Up @@ -271,8 +271,8 @@ def _option_string_helper(specifier_short, specifier_long, parameter, include_br


def print_usage():
print "Usage: argv[1] = path to docs.json; argv[2] = output path"
print "Example: manpage_generator.py ../docs.json ./dotnet-1.0/debian"
print("Usage: argv[1] = path to docs.json; argv[2] = output path")
print("Example: manpage_generator.py ../docs.json ./dotnet-1.0/debian")

def parse_args():
doc_path = sys.argv[1]
Expand All @@ -296,7 +296,7 @@ def execute_command_line():
generate_man_pages(doc_path, output_dir)

except Exception as exc:
print "Error: ", exc
print("Error: ", exc)
print_usage()

if __name__ == "__main__":
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
"curl": {
"package_version" : "0.5.3"
},
"python":{}
"python3":{}
},

"symlinks": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ setup(){
@test "manpage generation is identical to lkg file" {
# Output is file "tool1.1"
# LKG file is "lkgtestman.1"
python $PACKAGIFY_DIR/scripts/manpage_generator.py $PACKAGIFY_DIR/test/test_assets/testdocs.json $PACKAGIFY_DIR/test/test_assets
python3 $PACKAGIFY_DIR/scripts/manpage_generator.py $PACKAGIFY_DIR/test/test_assets/testdocs.json $PACKAGIFY_DIR/test/test_assets

# Test Output existence
[ -f $PACKAGIFY_DIR/test/test_assets/tool1.1 ]
Expand Down

0 comments on commit 6c66253

Please sign in to comment.