123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140 |
- #! /usr/bin/env python
- #
- # This file is part of stov, written by Helmut Pozimski in 2012.
- #
- # stov is free software: you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation, version 2 of the License.
- #
- # stov is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with stov. If not, see <http://www.gnu.org/licenses/>.
- # -*- coding: utf8 -*-
- from __future__ import print_function, unicode_literals
- import sys
- import subprocess
- import os
- import shutil
- """A simple installation script which checks if all requirements are met
- and copies all files of stov in the necessary locations
- """
- def main():
- """Check if a valid Path option is set or print the help if called"""
- try:
- sys.argv[1]
- except IndexError:
- print("No argument given, please give the path to install the program to"
- " or --help")
- sys.exit(2)
- if sys.argv[1] == "-h" or sys.argv[1] == "--help":
- print("""Usage: ./install.py OPTION
- Valid options are:
- -h or --help: Print this help screen
- $PATH: Define the Path to install to, e.g. /usr/local or /usr/share
- If installation fails, please check if the given path is correct and
- you can write to it.""")
- sys.exit(0)
- else:
- installpath = sys.argv[1]
- if os.access(installpath, os.F_OK) is not True:
- print >> sys.stderr, ("The directory does not exist, "
- "cancelling installation!")
- sys.exit(1)
- elif os.access(installpath, os.W_OK) is not True:
- print >> sys.stderr, ("You have no write permission"
- "for the defined directory, cancelling installation")
- sys.exit(1)
- """First check if all requirements are met and alert the user if
- they are not.
- """
- if sys.version_info < (2, 6):
- print >> sys.stderr, ("Your python version is below 2.6! You might still"
- "be able to run the program but use it at your own risk!")
- else:
- print("Checking running python version: OK")
- try:
- subprocess.check_call(["youtube-dl", "-h"], stdout=subprocess.PIPE)
- except subprocess.CalledProcessError:
- print >> sys.stderr, ("Could not find youtube-dl, it either does not exist,"
- " is not readable or not executable. Please note that "
- "youtube-dl is not needed for the program to run but is"
- " needed to use the download option which won't work otherwise."
- " If youtube-dl isn't found automatically, you may also enter "
- "the path to it in the configuration file.")
- else:
- print("Checking for youtube-dl: OK")
- """Create the subdirectory for the installation process"""
- programpath = os.path.join(installpath, "stov")
- files = ["stov.py", "subscription.py", "youtube.py", "configuration.py",
- "outputhelper.py", "youtubeAPI.py"]
- directories = ["locale"]
- installation_success = True
- """Start the installation process by copying files into the directory"""
- try:
- if os.access(programpath, os.F_OK) is not True:
- os.mkdir(programpath, 0o775)
- else:
- print("Program directory already exists, existing "
- "files will be overwritten!")
- except OSError:
- print("Directory could not be created, cancelling installation",
- file=sys.stderr)
- else:
- for i in files:
- sys.stdout.write("Copying file %s into program directory: " % i)
- try:
- shutil.copy(i, programpath)
- except IOError:
- sys.stdout.write("FAIL\n")
- install_success = False
- else:
- sys.stdout.write("OK\n")
- for i in directories:
- sys.stdout.write("Copying directory %s into program directory: " % i)
- if os.access(os.path.join(programpath, i), os.F_OK):
- shutil.rmtree(os.path.join(programpath, i))
- try:
- shutil.copytree(i, os.path.join(programpath, i))
- except IOError:
- sys.stdout.write("FAIL\n")
- install_success = False
- else:
- sys.stdout.write("OK\n")
- binpath = os.path.join(installpath, "bin")
- os.chdir(programpath)
- if os.access(binpath, os.F_OK & os.W_OK) and installation_success is True:
- try:
- os.symlink(os.path.join(programpath, "stov.py"),
- os.path.join(binpath, "stov"))
- except OSError:
- print("Symlink in bin-directory already exists")
- print("stov has been installed successfully to "
- + programpath + " and a symlink has been "
- "created in " + binpath + ", you should "
- "be able to run the program by typing \"stov\"")
- elif installation_success is True:
- print("stov has been installed successfully to %s but the installer "
- "couldn't find a suitable bin directory, you need to call stov.py"
- " with it's absolute path" % programpath)
- else:
- print("One or more installation steps failed. Please check this manually "
- "and try again")
- if __name__ == "__main__":
- main()
- else:
- print("This script needs to run on command line, please do not import it",
- file=sys.stderr)
|