<commit_before>#!/usr/bin/env python
#-*- encoding:utf-8 -*-

import os
import sys
import urllib2
import subprocess
import BaseHTTPServer
from HttpServer import HttpServerHandler, ThreadedHTTPServer

class Initialization ():
    def __init__(self, verbose):
        self._verbose = verbose
        self.show('Initializing')

        self.show('Checking for youtube-dl')
        if (not os.path.exists('/usr/local/bin/youtube-dl')):
            self.show('You need youtube-dl to catch links')
            self.downloadYdl()

        self.show('youtube-dl --version\n' + subprocess.check_output(["youtube-dl", "--version"]))

        if (os.geteuid() == 0):
            self.show('For safety, you can\'t start the server as root')
        else:
            self.show('Running HTTP server')
            httpd = ThreadedHTTPServer(('localhost', 49149), HttpServerHandler)
            httpd.serve_forever()
    
    def downloadYdl (self):
        if (os.geteuid() != 0):
            self.show('You need root permss for auto-install. Try this:')
            self.show('sudo !!')
            sys.exit(1)
        else:
            self.show('Downloading youtube-dl')
            try:
                latest = urllib2.urlopen("https://yt-dl.org/latest/youtube-dl")
            except:
                self.show('No Internet connexion')
                sys.exit(1)
            output = open('/usr/local/bin/youtube-dl','wb')
            output.write(latest.read())
            output.close()

            self.show('Changing permissions to youtube-dl')
            subprocess.check_output(["chmod", "a+x", "/usr/local/bin/youtube-dl"])

            self.show('\nRestart youtube-dl-simple-server')
            sys.exit(0)


    def show (self, s):
        if (self._verbose):
            print s<commit_msg>Add version control<commit_after>#!/usr/bin/env python
#-*- encoding:utf-8 -*-

import os
import sys
import urllib2
import subprocess
import BaseHTTPServer
from HttpServer import HttpServerHandler, ThreadedHTTPServer

class Initialization ():
    def __init__(self, verbose):
        self._verbose = verbose

        self.show('\nChecking for youtube-dl')
        if (not os.path.exists('/usr/local/bin/youtube-dl')):
            self.show('You need youtube-dl to catch links')
            self.downloadYdlLatest()

        self.show('\nChecking youtube-dl version')
        version = subprocess.check_output(["youtube-dl", "--version"]).replace("\n", '')
        latestVersion = self.getVersionYdlLatest()
        self.show(' - Latest youtube-dl ' + latestVersion)
        self.show(' - Yours  youtube-dl ' + version)
        if version != latestVersion:
            self.show(' You should update youtube-dl:')
            self.show(' sudo youtube-dl -U')

        if (os.geteuid() == 0):
            self.show('\nFor safety, you can\'t start the server as root. Run again')
        else:
            self.show('\nRunning HTTP server')
            httpd = ThreadedHTTPServer(('localhost', 49149), HttpServerHandler)
            httpd.serve_forever()
    
    def downloadYdlLatest (self):
        if (os.geteuid() != 0):
            self.show('You need root permss for auto-install. Try this:')
            self.show('sudo !!')
            sys.exit(1)
        else:
            self.show('Downloading youtube-dl')
            try:
                latest = urllib2.urlopen("https://yt-dl.org/latest/youtube-dl")
            except:
                self.show('No Internet connexion')
                sys.exit(1)
            output = open('/usr/local/bin/youtube-dl','wb')
            output.write(latest.read())
            output.close()

            self.show('Changing permissions to youtube-dl')
            subprocess.check_output(["chmod", "a+x", "/usr/local/bin/youtube-dl"])

            self.show('\nRestart youtube-dl-simple-server')
            sys.exit(0)

    def getVersionYdlLatest (self):
        try:
            latestVersion = urllib2.urlopen("https://yt-dl.org/latest/version").read()
        except:
            self.show('No Internet connexion')
            sys.exit(1)
        return latestVersion

    def show (self, s):
        if (self._verbose):
            print s
{'fraction_non_alphanumeric': 0.13416089758892338, 'fraction_numerical': 0.0066841728336118405, 'mean_word_length': 2.0252707581227436, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 3, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3006264', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1204, 'n_words': 265}