Skip to content

Commit

Permalink
Fixed crash on lack of builds #13 and raised minimum python version #12
Browse files Browse the repository at this point in the history
  • Loading branch information
OwenCochell committed Jun 9, 2022
1 parent 03f8979 commit 408815a
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 27 deletions.
14 changes: 14 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,19 @@
# Changelog

## 2.2.1

Bug Fixes:

- Changed the lowest required version from 3.6 to 3.7.
- Fixed bug where script crashes if no builds are available for the selected version.
We now display a message and exit.
- Fixed bug where option '--stats' fails if the selected version and build are invalid.

Other Fixes:

- Changed the lowest version required in the readme.
- Fixed some errors and typos in the readme

## 2.2.0

Features Added:
Expand Down
26 changes: 12 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ Check out the [PaperMC Documentation](https://paper.readthedocs.io/en/latest/),

# Prerequisites

You must have Python 3.6+ installed. It should come pre-installed on most linux systems.
You must have Python 3.7+ installed. It should come pre-installed on most linux systems.
This script has no other dependencies, so all you need is python! Instructions for installation are below:

## Linux:
Expand All @@ -25,7 +25,7 @@ Or use whatever package manager is installed on your system.
The only important part is specifying python3.9!

You don't have to install the latest version of python for this script to work, but I highly recommend you do so!
Again, we require python 3.6 or above.
Again, we require python 3.7 or above.


## Windows:
Expand All @@ -34,7 +34,7 @@ Windows users can download python [here](https://www.python.org/downloads/window
although we recommend you add python to your PATH environment variable, as this makes using python much easier.

More information on installing/configuring python can be found [here](https://www.python.org/downloads/)
(Any python 3.6+ version works, although I recommend python 3.9).
(Any python 3.7+ version works, although I recommend python 3.9).

We also supply windows binaries that can be ran directly on windows systems without python!
We use [PyInstaller](https://www.pyinstaller.org/) to build these binaries, and they are built using the one file option, or '-F'.
Expand All @@ -59,7 +59,7 @@ Again, the installation is very straightforward, but more information can be fou
# Note on Python Versions:

In some systems, the 'python' command may point to an older version of python.
As stated above, we require python 3.6 or above, so it may be necessary to manually specify the python version to use.
As stated above, we require python 3.7 or above, so it may be necessary to manually specify the python version to use.

This can be done like so:

Expand All @@ -76,7 +76,7 @@ To find the version of python your command points to, you can check it's version

>python --version
If it is below 3.6, then you will have to manually specify the version to run!
If it is below 3.7, then you will have to manually specify the version to run!

From this point on, we will use the default 'python' command in our examples,
assuming that it's a valid python version.
Expand Down Expand Up @@ -108,6 +108,8 @@ the `--interactive` flag for this.
4. The selected version is downloaded to a temporary directory located somewhere on your computer
(This directory is generated using the python tempfile module, meaning that it will be generated in a safe,
unobtrusive manner, and will be automatically removed at termination of the script).

If the version selected has no available builds, then the script will print a warning and exit.
5. The integrity of the file will be checked using the SHA256 hash provided by the PaperMC API.
If this check fails, the install will cancel.
6. The currently installed version of the server is backed up to the temporary directory, and deleted.
Expand Down Expand Up @@ -190,7 +192,7 @@ that can be used to do special things.

The `latest` keyword will automatically select the latest option available.

The `current` keyword will automatically select the currently installed currently installed value.
The `current` keyword will automatically select the currently installed value.

For example, lets say you have paper version 1.17 and build 60 installed.
If you want to get the latest build while maintaining your installed version,
Expand All @@ -206,7 +208,6 @@ These keywords can be used in the interactive menu as well.
You can also use these keywords for selecting the build,
although using the `current` keyword for build selection is not recommended!


## Upgrading the Script

This script has the ability to upgrade itself!
Expand Down Expand Up @@ -341,14 +342,11 @@ Check to see if a newer version is available, does not install:
Display currently installed server version:
>python server_update.py --server-version [PATH]
Display stats on currently installed server version before installation:
>python server_update.py --stats [PATH]
Display stats on version 1.16.5 build 432 before installation if update is available:
>python server_update.py --stats --version 1.16.5 --build 432 [PATH]
Display stats on version 1.16.5 build 435 before installation:
>python server_update.py --stats --version 1.16.5 --build 435 [PATH]
Display stats on installed version without installing:
>python server_update.py --check-only [PATH]
Display stats on version 1.16.5 build 432 without installing anything:
>python server_update.py --stats --version 1.16.5, --build 432 -c -nc
Install a paper jar at the given location, without going through the update process.
Great if you want to set up a new server install.
Expand Down
58 changes: 45 additions & 13 deletions server_update.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@

# Before we do ANYTHING, we check to make sure python is the correct version!

if sys.version_info < (3,6,0):
if sys.version_info < (3,7,0):

sys.stdout.write("\n--== [ Invalid python version! ] ==--\n")
sys.stdout.write("Current version: {}\n".format(version_info))
sys.stdout.write("Expected version: 3.6+\n")
sys.stdout.write("Expected version: 3.7+\n")
sys.stdout.write("\nPlease install the correct version of python before continuing!\n")

sys.exit()
Expand All @@ -33,7 +33,7 @@
A Set of tools to automate the server update process.
"""

__version__ = '2.2.0'
__version__ = '2.2.1'

# These variables contain links for the script updating process.

Expand Down Expand Up @@ -131,6 +131,8 @@ def upgrade_script(serv: ServerUpdater):

return

serv.fileutil.path = path

# Getting data:

data = urllib.request.urlopen(urllib.request.Request(url))
Expand Down Expand Up @@ -572,7 +574,7 @@ def get(self, version: str=None, build_num: int=None) -> dict:
"""
Gets RAW data from the Paper API, version info only.
We utilise some basic caching to remember responses
We utilize some basic caching to remember responses
instead of calling the PaperMC API multiple times.
You can use this to get a list of valid versions,
Expand Down Expand Up @@ -1045,6 +1047,14 @@ def view_data(self):

ver, build = self.version_select(args.version, args.build)

# Check if install is aborted:

if ver == '' or build == -1:

# Error occurred, cancel stats operation

return

# Get the data:

data = self.update.get(ver, build)
Expand Down Expand Up @@ -1112,7 +1122,7 @@ def check(self, default_version: str, default_build: int):

output("# Comparing local <> remote server versions ...")

if self.version != self._select(default_version, ver, 'latest', 'version', print=False) and (self.version == '0' or ver[-1] != self.version):
if self.version != self._select(default_version, ver, 'latest', 'version', print_output=False) and (self.version == '0' or ver[-1] != self.version):

# New version available!

Expand Down Expand Up @@ -1153,7 +1163,7 @@ def check(self, default_version: str, default_build: int):

output("# Comparing local <> remote builds ...")

if self.buildnum != self._select(default_build, build, 'latest', 'buildnum', print=False) and (self.buildnum == 0 or build[-1] != self.buildnum):
if self.buildnum != self._select(default_build, build, 'latest', 'buildnum', print_output=False) and (self.buildnum == 0 or build[-1] != self.buildnum):

# New build available!

Expand Down Expand Up @@ -1192,7 +1202,7 @@ def version_select(self, default_version: str='latest', default_build: int=-1) -

if new_default == '-1':

# Convert into something more redable:
# Convert into something more readable:

new_default: str = 'latest'

Expand Down Expand Up @@ -1295,6 +1305,26 @@ def version_select(self, default_version: str='latest', default_build: int=-1) -

return '', -1

# Check if their are no builds:

if len(nums) == 0:

# No builds available, abort:

print("# No builds available!")
print("\nThe version you have selected has no builds available.")
print("This could be because the version you are attempting to install is too new or old.")
print("The best solution is to either wait for a build to be produced for your version,")
print("Or select a different version instead.")

print("\nTo see if a specific version has builds, you can issue the following command:\n")
print("python server_update.py -nc --version [version]")
print("\nSimply replace [version] with the version you wish to check.")
print("This message will appear again if there are still no builds available.")
print("The script will now exit.")

return '', -1

if self.prompt:

print("\nPlease enter the build you would like to download:")
Expand Down Expand Up @@ -1520,7 +1550,7 @@ def get_new(self, default_version: str='latest', default_build: int=-1, backup:

return

def _select(self, val: Any, choice: Sequence[Any], default: str, name: str, print: bool=True) -> Union[str, None]:
def _select(self, val: Any, choice: Sequence[Any], default: str, name: str, print_output: bool=True) -> Union[str, None]:
"""
Selects a value from the choices.
We support updater keywords,
Expand All @@ -1534,8 +1564,8 @@ def _select(self, val: Any, choice: Sequence[Any], default: str, name: str, prin
:type default: str
:param name: Name of value we are choosing
:type name: str
:param print: Boolean determining if we output choices
:type print: bool
:param print_output: Boolean determining if we output choices
:type print_output: bool
:return: Selected value, None if invalid
:rtype: str, None
"""
Expand All @@ -1550,7 +1580,7 @@ def _select(self, val: Any, choice: Sequence[Any], default: str, name: str, prin

# User wants latest

if print:
if print_output:

output("# Selecting latest {} - [{}] ...".format(name, choice[-1]))

Expand All @@ -1574,15 +1604,15 @@ def _select(self, val: Any, choice: Sequence[Any], default: str, name: str, prin

# User selected invalid option

if print:
if print_output:

output("\n# Error: Invalid {} selected!".format(name))

return None

# Option selected is valid. Continue

if print:
if print_output:

output("# Selecting {}: [{}] ...".format(name, val))

Expand Down Expand Up @@ -1683,6 +1713,8 @@ def _url_report(self, point: str):

if args.upgrade:

output("Checking for script update ...")

upgrade_script(serv)

sys.exit()
Expand Down

0 comments on commit 408815a

Please sign in to comment.