Skip to content

Commit

Permalink
Version 0.0.2
Browse files Browse the repository at this point in the history
* Add versioning
* Delete old versions
* Improve README
* Add .exe compilation instructions
* Default download directory to the default GOG Galaxy plugin directory
  on Windows
* Prompt for user input at the end of the process on Windows so the
  script doesn't immediately terminate and close the command prompt
  • Loading branch information
Slashbunny committed Oct 11, 2019
1 parent 3738c12 commit 1bdb8b8
Show file tree
Hide file tree
Showing 2 changed files with 115 additions and 15 deletions.
49 changes: 43 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,23 @@ list of plugins from this from this repository on Github (`plugins.yaml`).
If does not modify any directories in the destination folder. You should
manually delete your existing/old plugins.

# Requirements
# Basic

Install Python 3 on your OS. Clone or [download](https://github.com/Slashbunny/gog-galaxy-plugin-downloader/archive/master.zip)+extract this repository into a directory of your choice.
* Download the latest release from the [Releases](Releases) page.
* Extract the zip file anywhere on your PC.
* Double click on `gog-plugins-downloader.exe` to run the plugin to download or
update your plugins.

# Usage
This will only work for Windows. If you are using another OS, you will need to
follow the Advanced instructions below.

# Advanced

## Requirements

Install Python 3 on your OS. Clone or [download](https://github.com/Slashbunny/gog-galaxy-plugin-downloader/archive/master.zip), then extract this repository into a directory of your choice.

## Usage

Open a command line terminal and navigate to the directory where you downloaded
or cloned this repository.
Expand All @@ -25,13 +37,19 @@ Install dependencies
pip install -r requirements.txt
```

Download plugins to Galaxy's "installed" directory:
Download plugins to Galaxy's "installed" directory on Windows (`%localappdata\GOG.com\Galaxy\plugins\installed`):

```
python download.py
```

You can also download to a custom directory (Required on non-Windows systems):

```
python download.py -d %localappdata%\GOG.com\Galaxy\plugins\installed
python download.py -d output-folder
```

# Advanced Usage
## Custom Plugins

By default the list of plugins comes from the YAML file in this repository. You
can use your own local plugins YAML file like this:
Expand All @@ -46,6 +64,25 @@ Or use your own remote plugins YAML file hosted at any URL:
python download.py -d output-directory -c https://www.mydomain.com/gog-plugins.yaml
```

## Building the Executable

If you want to build the Windows executable, you must follow these steps on
Windows.

First, install pyinstaller:

```
pip install pyinstaller
```

Then build the executables as follows:

```
pyinstaller download.py -n gog-plugins-downloader --onefile
```

`gog-plugins-downloader.exe` will be in the `dist/` subfolder.

# Contibute

Open a Merge Request with updates to plugins in `plugins.yaml` so everyone
Expand Down
81 changes: 72 additions & 9 deletions download.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@
from urllib.parse import urlparse
from urllib.request import urlopen

__version__ = '0.0.2'

# URL to the plugins.yaml file if one is not supplied by the user
default_plugins = 'https://raw.githubusercontent.com/Slashbunny' \
'/gog-galaxy-plugin-downloader/master/plugins.yaml'


def get_plugin_config(config_uri):
"""
Expand Down Expand Up @@ -55,6 +61,11 @@ def process_template_strings(data):


def download_plugins(data, dest):
"""
Downloads and extracts plugins
If the destination directory already exists, the plugin is skipped
"""
for name, data in data.items():
version = data['version']
url = data['url']
Expand All @@ -67,11 +78,11 @@ def download_plugins(data, dest):
dest_dir = os.path.join(dest, name + '_v' + version)

if os.path.isdir(dest_dir):
print('NOTICE: Skipping "{}" download, {} already exists'
print('NOTICE: Skipping "{}" download, "{}" already exists'
.format(name, dest_dir))
continue
else:
print('Downloading {} version {}'.format(name, version))
print('Downloading "{}" version "{}"'.format(name, version))

# Download zip file into memory
plugin_url = urlopen(url)
Expand All @@ -95,24 +106,69 @@ def download_plugins(data, dest):
tmp_dir.cleanup()


def delete_old_plugins(data, dest):
"""
Deletes versions of plugins that don't match the yaml manifest. In theory
this should only be older versions, but any version that doesn't match
the yaml definition will be deleted
This explicitly does not touch other directories that do not match the
known plugin names. It only deletes directories of the format:
<plugin name>_v<version>
If the version doesn't match the yaml definition, the directory is removed
"""
# Loop over each plugin
for name, data in data.items():
current_plugin_dir = name + '_v' + data['version']

# Loop through directories in the destination directory
for item in os.listdir(dest):
full_path = os.path.join(dest, item)

# Skip non-directories
if not os.path.isdir(full_path):
continue

# Skip directory names that are in the valid plugin directory array
if item == current_plugin_dir:
continue

# If any other directory begins with <plugin_name>_v, delete it
if item.startswith(name + '_v'):
print('Deleting wrong version "{}" from "{}"'
.format(item, dest))
shutil.rmtree(full_path)


if __name__ == "__main__":
"""
Entry point to script
- Parses command line arguments
- Calls function to fetch/parse plugin config yaml file
- Calls function to download plugins
- Calls function to delete old/invalid plugins
"""
# Define script arguments
parser = argparse.ArgumentParser(
description='Download GOG Galaxy 2.0 Plugins')
parser.add_argument('-c', '--conf',
default='https://raw.githubusercontent.com/'
'Slashbunny/gog-galaxy-plugin-downloader/'
'master/plugins.yaml',
description='GOG Galaxy Plugin Downloader')
parser.add_argument('-c', '--conf', default=default_plugins,
help='Path or URL to plugin configuration YAML file')
parser.add_argument('-d', '--dest', required=True,
help='Destination directory for plugins')

# On Windows, default the destination directory argument
if os.name == "nt":
plugins_dir = os.path.join(os.environ['localappdata'], 'GOG.com',
'Galaxy', 'plugins', 'installed')
parser.add_argument('-d', '--dest', default=plugins_dir,
help='Destination directory for plugins')
else:
parser.add_argument('-d', '--dest', required=True,
help='Destination directory for plugins')

parser.add_argument('--version', action='version',
version='{}'.format(__version__))

# Parse arguments
args = parser.parse_args()
Expand All @@ -125,3 +181,10 @@ def download_plugins(data, dest):

# Download plugins
download_plugins(plugins, args.dest)

# Delete old plugins
delete_old_plugins(plugins, args.dest)

# If on Windows, prompt user to press a button before exiting
if os.name == "nt":
input('Process complete! Press the Enter key to exit...')

0 comments on commit 1bdb8b8

Please sign in to comment.