<commit_before>from command.default import ManagerDefaultController
from cement.core.controller import expose
from util.config import Configuration
from util.filesystem import FSCheck
from urllib.request import urlretrieve
from subprocess import call
import os
import stat
import tarfile


class DownloadController(ManagerDefaultController):
    steamcmd_url = 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz'
    steamcmd_archive = '/steamcmd.tar.gz'
    ql_appid = 349090

    class Meta:
        label = 'download'
        description = 'Allows to download/update SteamCMD and QL Dedicated Server files'

    @expose(hide=True)
    def default(self):
        self.app.args.parse_args(['--help'])

    @expose(help='Downloads and installs SteamCMD')
    def steamcmd(self):
        config = Configuration()

        steamcmd_dir = os.path.expanduser(config.get('dir', 'steamcmd'))
        steamcmd_dir_fs = FSCheck(steamcmd_dir, 'SteamCMD dir')

        #check if steamcmd dir exists
        if steamcmd_dir_fs.exists(error=False):
            print('% exists. Remove it or change SteamCMD location in settings' % steamcmd_dir)
            exit(21)

        os.makedirs(steamcmd_dir)

        steamcmd_dir_fs.access('w') #check for write access in dir

        print('Downloading SteamCMD archive')
        urlretrieve(self.steamcmd_url, steamcmd_dir + self.steamcmd_archive)

        print('Extracting SteamCMD atchive to %s' % steamcmd_dir)
        archive = tarfile.open(steamcmd_dir + self.steamcmd_archive)
        archive.extractall(steamcmd_dir)

        steamcmd_stat = os.stat(steamcmd_dir + '/steamcmd.sh')
        os.chmod(steamcmd_dir + '/steamcmd.sh', steamcmd_stat.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)

        print('SteamCMD installed in %s' % steamcmd_dir)
        print('Remember that you need "lib32stdc++6" installed in your system')

    @expose(help='Downloads and updates QL Dedicated Server files')
    def ql(self):
        config = Configuration()

        steamcmd = os.path.expanduser(config.get('dir', 'steamcmd') + '/steamcmd.sh')

        steamcmd_fs = FSCheck(steamcmd, 'SteamCMD')

        steamcmd_fs.exists()
        steamcmd_fs.access('x')

        print('Downloading QL Dedicated Server files using SteamCMD...')

        call([
            steamcmd,
            '+login anonymous +force_install_dir %s +app_update %d +quit' % (config.get('dir', 'ql'), self.ql_appid)
        ])<commit_msg>Fix command line for QL files installation<commit_after>from command.default import ManagerDefaultController
from cement.core.controller import expose
from util.config import Configuration
from util.filesystem import FSCheck
from urllib.request import urlretrieve
from subprocess import call
import os
import stat
import tarfile


class DownloadController(ManagerDefaultController):
    steamcmd_url = 'https://steamcdn-a.akamaihd.net/client/installer/steamcmd_linux.tar.gz'
    steamcmd_archive = '/steamcmd.tar.gz'
    ql_appid = 349090

    class Meta:
        label = 'download'
        description = 'Allows to download/update SteamCMD and QL Dedicated Server files'

    @expose(hide=True)
    def default(self):
        self.app.args.parse_args(['--help'])

    @expose(help='Downloads and installs SteamCMD')
    def steamcmd(self):
        config = Configuration()

        steamcmd_dir = os.path.expanduser(config.get('dir', 'steamcmd'))
        steamcmd_dir_fs = FSCheck(steamcmd_dir, 'SteamCMD dir')

        #check if steamcmd dir exists
        if steamcmd_dir_fs.exists(error=False):
            print('% exists. Remove it or change SteamCMD location in settings' % steamcmd_dir)
            exit(21)

        os.makedirs(steamcmd_dir)

        steamcmd_dir_fs.access('w') #check for write access in dir

        print('Downloading SteamCMD archive')
        urlretrieve(self.steamcmd_url, steamcmd_dir + self.steamcmd_archive)

        print('Extracting SteamCMD atchive to %s' % steamcmd_dir)
        archive = tarfile.open(steamcmd_dir + self.steamcmd_archive)
        archive.extractall(steamcmd_dir)

        steamcmd_stat = os.stat(steamcmd_dir + '/steamcmd.sh')
        os.chmod(steamcmd_dir + '/steamcmd.sh', steamcmd_stat.st_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)

        print('SteamCMD installed in %s' % steamcmd_dir)
        print('Remember that you need "lib32stdc++6" installed in your system')

    @expose(help='Downloads and updates QL Dedicated Server files')
    def ql(self):
        config = Configuration()

        steamcmd = os.path.expanduser(config.get('dir', 'steamcmd') + '/steamcmd.sh')

        steamcmd_fs = FSCheck(steamcmd, 'SteamCMD')

        steamcmd_fs.exists()
        steamcmd_fs.access('x')

        print('Downloading QL Dedicated Server files using SteamCMD...')

        call([
            steamcmd,
            '+login', 'anonymous',
            '+force_install_dir', os.path.expanduser(config.get('dir', 'ql')),
            '+app_update', str(self.ql_appid),
            '+quit'
        ])

{'fraction_non_alphanumeric': 0.10409217322208979, 'fraction_numerical': 0.004370282081843465, 'mean_word_length': 3.1645988420181967, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4696366', 'n_tokens_mistral': 1608, 'n_tokens_neox': 1566, 'n_words': 356}