Пример #1
0
def main():
    # check last update date
    path = "/home/kame/Dropbox/data/pip_updater_date.txt"
    start_time = f.file_get_last_line(path)
    if f.time_diff_in_seconds(start_time, f.get_datetime()) > 1 * 24 * 3600:
        sudo_password = input("password:"******"pip2", "list", "-o"], stdout=subprocess.PIPE).communicate()[0]
        tasks = tasks.decode('UTF-8').split("\n")
        for elem in tasks:
            if elem != '':
                elem = re.findall(r"(.*?) \(", elem)[0]
                print("##########################################################")
                print("#####           installing " + str(elem))
                print("##########################################################")
                command = "pip2 install --upgrade " + str(elem)
                os.system('echo %s|sudo -H -S %s' % (sudo_password, command))

        # update all python 3.x modules
        tasks = subprocess.Popen(["pip3", "list", "-o"], stdout=subprocess.PIPE).communicate()[0]
        tasks = tasks.decode('UTF-8').split("\n")
        for elem in tasks:
            if elem != '':
                elem = re.findall(r"(.*?) \(", elem)[0]
                print("##########################################################")
                print("#####           installing " + str(elem))
                print("##########################################################")
                command = "pip3 install --upgrade " + str(elem)
                os.system('echo %s|sudo -H -S %s' % (sudo_password, command))

        # append date to log-file
        f.file_insert_line(path, f.file_count_lines(path), f.get_datetime() + "\n")
Пример #2
0
def main():
    # check last update date
    path = "/home/kame/Dropbox/data/pip_updater_date.txt"
    start_time = f.file_get_last_line(path)
    if f.time_diff_in_seconds(start_time, f.get_datetime()) > 1 * 24 * 3600:
        sudo_password = input("password:"******"pip2", "list", "-o", "--format=legacy"],
                                 stdout=subprocess.PIPE).communicate()[0]
        tasks = tasks.decode('UTF-8').split("\n")
        for elem in tasks:
            if elem != '':
                elem = re.findall(r"(.*?) \(", elem)[0]
                print(
                    "##########################################################"
                )
                print("#####           installing " + str(elem))
                print(
                    "##########################################################"
                )
                command = "pip2 install --upgrade " + str(elem)
                os.system('echo %s|sudo -H -S %s' % (sudo_password, command))

        # update all python 3.x modules
        tasks = subprocess.Popen(["pip3", "list", "-o", "--format=legacy"],
                                 stdout=subprocess.PIPE).communicate()[0]
        tasks = tasks.decode('UTF-8').split("\n")
        for elem in tasks:
            if elem != '':
                elem = re.findall(r"(.*?) \(", elem)[0]
                print(
                    "##########################################################"
                )
                print("#####           installing " + str(elem))
                print(
                    "##########################################################"
                )
                command = "pip3 install --upgrade " + str(elem)
                os.system('echo %s|sudo -H -S %s' % (sudo_password, command))

        # append date to log-file
        f.file_insert_line(path, f.file_count_lines(path),
                           f.get_datetime() + "\n")
Пример #3
0
def update_system():
    path = "/home/kame/Dropbox/data/linux_update_date.txt"
    start_time = f.file_get_last_line(path)
    if f.time_diff_in_seconds(start_time, f.get_datetime()) > 5 * 24 * 3600:
        # append date to log-file
        f.file_insert_line(path, f.file_count_lines(path), f.get_datetime() + "\n")

        sudo_password = input("password:")

        print('sudo dpkg --configure -a')
        command = 'sudo dpkg --configure -a'  # repair the system
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        print('sudo apt-get update -y')
        command = 'sudo apt-get update'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        print('sudo apt-get upgrade -y')
        command = 'sudo apt-get upgrade -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        print('sudo apt-get dist-upgrade -y')
        command = 'sudo apt-get dist-upgrade -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        print('sudo apt-get autoremove -y')
        command = 'sudo apt-get autoremove -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        print('sudo apt-get clean -y')
        command = 'sudo apt-get clean -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        print('sudo apt-get autoclean -y')
        command = 'sudo apt-get autoclean -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        # install pip
        command = 'sudo easy_install pip'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        # python-modules
        print('install modules with pip')
        # pil --> pillow
        # winsound --> not found
        command = 'sudo apt-get install python3-pip -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))
        import pip
        installed_packages = pip.get_installed_distributions()
        flat_installed_packages = [package.project_name for package in installed_packages]
        packages = ['numpy', 'Pillow', 'pymouse', 'pymysql', 'pyvirtualdisplay', 'requests',
                    'robotframework', 'robotframework-selenium2library',
                    'selenium', 'sympy']
        for package in packages:
            if package in flat_installed_packages:
                print(str(package) + ' already installed')
            else:
                print('Install package \'' + str(package) + '\'')
                command = 'pip install ' + str(package)
                os.system('echo %s|sudo -H -S %s' % (sudo_password, command))

        # programs
        print('install programs with apt-get')
        # pdfsam merges pdf-files
        # virtualbox-guest-dkms sind viele sinnvolle Erweiterungen für die virtualbox
        # gedit --> mousepad (leichter)
        # python-pip (war zu alt) --> easy_install pip
        # rausgenommen aber gut: flightgear, monodevelop (C# programming)
        # at first ttf-mscorefonts-installer installieren
        command = 'sudo apt-get install ' + str('ttf-mscorefonts-installer') + ' -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        programs = ['anki', 'bum', 'chromium-browser', 'chromium-codexs-ffmpeg',
                    'conky', 'ding', 'filezilla', 'firefox',
                    'flashplugin-installer', 'flightgear', 'git',
                    'gparted', 'ipython',
                    'nautilus-dropbox', 'mkgmap', 'mousepad', 'mypaint',
                    'nmap', 'pdfsam', 'preload',
                    'rhythmbox', 'skype', 'stellarium', 'subversion', 'tar',
                    'thunderbird', 'tmux', 'tuxpaint', 'vlc', 'vim',
                    'vim-runtime', 'virtualbox', 'virtualbox-guest-dkms',
                    'wine', 'wireshark', 'xchat', 'xvfb']

        for program in programs:
            command = 'sudo apt-get install ' + str(program) + ' -y'
            os.system('echo %s|sudo -S %s' % (sudo_password, command))

        # pycharm
        command = 'sudo add-apt-repository ppa:mystic-mirage/pycharm -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))
        command = 'sudo apt-get update'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))
        command = 'sudo apt-get install pycharm-community -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        # xlib
        command = 'sudo -H pip install svn+https://svn.code.sf.net/p/python-xlib/code/trunk/'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        #    print('remove some programs with apt-get')
        #    programs2 = ['amarok', 'audacious', 'bfgminer', 'calibre',
        #                 'clementine', 'cowsay', 'geany',
        #                 'gpodder', 'kdiff3', 'liferea', 'lmms',
        #                 'lynx', 'meld', 'midori', 'mines', 'openbve',
        #                 'rosegarden', 'simutrans', 'sudoku', 'supertuxkart']
        #    for program in programs2:
        #        command = 'sudo apt-get remove ' + str(program)
        #        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        # empty trash
        os.system('rm -rf ~/.local/share/Trash/*')
Пример #4
0
def main():
    # check last update date
    path = "/home/kame/Dropbox/data/backup_date.txt"
    start_time = f.file_get_last_line(path)
    if f.time_diff_in_seconds(start_time, f.get_datetime()) > 30 * 24 * 3600:
        print("You should backup your system!")

        # check if usb is connected
        device_flag = 0
        for device in f.detect_devices():
            if 'Toshiba' in device:
                device_flag = 1

        if device_flag == 1:
            """
            Copy a file from source to destination.
            At first all files at the destination will be deleted.
            """

            import os
            import shutil

            def copytree(src, dst, symlinks=False, ignore=None):
                # if destination folder exists, you can't copy the files
                # therefore at first delete the destination
                # try:
                #     shutil.rmtree(dst)
                # except FileNotFoundError:
                #     pass

                for item in os.listdir(src):
                    s = os.path.join(src, item)
                    d = os.path.join(dst, item)

                    # is source folder or file ?
                    folder_or_file = 0
                    if os.path.isdir(s):
                        folder_or_file = 10
                        # print("folder")
                    elif os.path.isfile(s):
                        folder_or_file = 20
                        # print("file")
                    # check if destination exist and folder of file
                    if os.path.isdir(d) or os.path.isfile(d):
                        folder_or_file += 1
                        # print("         existing")
                    else:
                        folder_or_file += 2
                        # print("         not existing")

                    if folder_or_file == 11:
                        # check last change time
                        if os.stat(s).st_mtime - os.stat(d).st_mtime > 1:
                            print(s)
                            shutil.rmtree(d)
                            shutil.copytree(s, d, symlinks, ignore)
                        else:
                            # print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
                            pass

                    if folder_or_file == 21:
                        # check last change time
                        if os.stat(s).st_mtime - os.stat(d).st_mtime > 1:
                            os.remove(d)
                            print(s)
                            shutil.copy2(s, d)
                        else:
                            # print("+++++++++++++++++++++++++++++++++++++++++++++++++++++")
                            pass

                    if folder_or_file == 12:
                        print(s)
                        shutil.copytree(s, d, symlinks, ignore)

                    # file
                    if folder_or_file == 22:
                        print(s)
                        shutil.copy2(s, d)

            # xxx
            input("Also save xxx")

            # Anki
            input("Please export Anki.apkg and insert to main folder")

            # Dropbox files
            print("copy Dropbox")
            copytree("/home/kame/Dropbox",
                     "/media/kame/TOSHIBA EXT/Steffen/Dropbox")

            # Desktop files
            print("copy main")
            copytree(r"/home/kame/Desktop/main",
                     "/media/kame/TOSHIBA EXT/Steffen/main")

            # print("copy bilder")
            # copytree(r"/home/kame/Desktop/main/bilder", "/media/kame/TOSHIBA EXT/Steffen/bilder")
            # print("copy mp3")
            # copytree(r"/home/kame/Desktop/main/mp3", "/media/kame/TOSHIBA EXT/Steffen/mp3")
            # print("copy wichtig")
            # copytree(r"/home/kame/Desktop/main/wichtig", "/media/kame/TOSHIBA EXT/Steffen/wichtig")

            # append date to log-file
            f.file_insert_line(path, f.file_count_lines(path),
                               f.get_datetime() + "\n")
Пример #5
0
def main():
    # check last update date
    path = "/home/kame/Dropbox/data/backup_date.txt"
    start_time = f.file_get_last_line(path)
    if f.time_diff_in_seconds(start_time, f.get_datetime()) > 30 * 24 * 3600:
        print("You should backup your system!")

        # check if usb is connected
        device_flag = 0
        for device in f.detect_devices():
            if 'Toshiba' in device:
                device_flag = 1

        if device_flag == 1:
            """
            Copy a file from source to destination.
            At first all files at the destination will be deleted.
            """

            import os
            import shutil

            def copytree(src, dst, symlinks=False, ignore=None):
                # if destination folder exists, you can't copy the files
                # therefore at first delete the destination
                # try:
                #     shutil.rmtree(dst)
                # except FileNotFoundError:
                #     pass

                for item in os.listdir(src):
                    s = os.path.join(src, item)
                    d = os.path.join(dst, item)

                    # is source folder or file ?
                    folder_or_file = 0
                    if os.path.isdir(s):
                        folder_or_file = 10
                        # print("folder")
                    elif os.path.isfile(s):
                        folder_or_file = 20
                        # print("file")
                    # check if destination exist and folder of file
                    if os.path.isdir(d) or os.path.isfile(d):
                        folder_or_file += 1
                        # print("         existing")
                    else:
                        folder_or_file += 2
                        # print("         not existing")

                    if folder_or_file == 11:
                        # check last change time
                        if os.stat(s).st_mtime - os.stat(d).st_mtime > 1:
                            shutil.rmtree(d)
                            shutil.copytree(s, d, symlinks, ignore)
                            print(s)
                        else:
                            # print("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++")
                            pass

                    if folder_or_file == 21:
                        # check last change time
                        if os.stat(s).st_mtime - os.stat(d).st_mtime > 1:
                            os.remove(d)
                            shutil.copy2(s, d)
                            print(s)
                        else:
                            # print("+++++++++++++++++++++++++++++++++++++++++++++++++++++")
                            pass

                    if folder_or_file == 12:
                        shutil.copytree(s, d, symlinks, ignore)
                        print(s)

                    # file
                    if folder_or_file == 22:
                        shutil.copy2(s, d)
                        print(s)

            # Dropbox files
            print("copy Dropbox")
            copytree("/home/kame/Dropbox", "/media/kame/TOSHIBA EXT/Steffen/Dropbox")

            # Desktop files
            print("copy main")
            copytree(r"/home/kame/Desktop/main", "/media/kame/TOSHIBA EXT/Steffen/main")

            # print("copy bilder")
            # copytree(r"/home/kame/Desktop/main/bilder", "/media/kame/TOSHIBA EXT/Steffen/bilder")
            # print("copy mp3")
            # copytree(r"/home/kame/Desktop/main/mp3", "/media/kame/TOSHIBA EXT/Steffen/mp3")
            # print("copy wichtig")
            # copytree(r"/home/kame/Desktop/main/wichtig", "/media/kame/TOSHIBA EXT/Steffen/wichtig")

            # append date to log-file
            f.file_insert_line(path, f.file_count_lines(path), f.get_datetime() + "\n")
Пример #6
0
def update_system():
    path = "/home/kame/Dropbox/data/linux_update_date.txt"
    start_time = f.file_get_last_line(path)
    if f.time_diff_in_seconds(start_time, f.get_datetime()) > 5 * 24 * 3600:
        # append date to log-file
        f.file_insert_line(path, f.file_count_lines(path),
                           f.get_datetime() + "\n")

        sudo_password = input("password:")

        print('sudo dpkg --configure -a')
        command = 'sudo dpkg --configure -a'  # repair the system
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        print('sudo apt-get update -y')
        command = 'sudo apt-get update'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        print('sudo apt-get upgrade -y')
        command = 'sudo apt-get upgrade -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        print('sudo apt-get dist-upgrade -y')
        command = 'sudo apt-get dist-upgrade -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        print('sudo apt-get autoremove -y')
        command = 'sudo apt-get autoremove -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        print('sudo apt-get clean -y')
        command = 'sudo apt-get clean -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        print('sudo apt-get autoclean -y')
        command = 'sudo apt-get autoclean -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        # install pip
        command = 'sudo easy_install pip'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        # python-modules
        print('install modules with pip')
        # pil --> pillow
        # winsound --> not found
        command = 'sudo apt-get install python3-pip -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))
        import pip
        installed_packages = pip.get_installed_distributions()
        flat_installed_packages = [
            package.project_name for package in installed_packages
        ]
        packages = [
            'numpy', 'Pillow', 'pymouse', 'pymysql', 'pyvirtualdisplay',
            'requests', 'robotframework', 'robotframework-selenium2library',
            'selenium', 'sympy'
        ]
        for package in packages:
            if package in flat_installed_packages:
                print(str(package) + ' already installed')
            else:
                print('Install package \'' + str(package) + '\'')
                command = 'pip install ' + str(package)
                os.system('echo %s|sudo -H -S %s' % (sudo_password, command))

        # programs
        print('install programs with apt-get')
        # pdfsam merges pdf-files
        # virtualbox-guest-dkms sind viele sinnvolle Erweiterungen für die virtualbox
        # gedit --> mousepad (leichter)
        # python-pip (war zu alt) --> easy_install pip
        # rausgenommen aber gut: flightgear, monodevelop (C# programming)
        # at first ttf-mscorefonts-installer installieren
        command = 'sudo apt-get install ' + str(
            'ttf-mscorefonts-installer') + ' -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        programs = [
            'anki', 'bum', 'chromium-browser', 'chromium-codexs-ffmpeg',
            'conky', 'ding', 'filezilla', 'firefox', 'flashplugin-installer',
            'flightgear', 'git', 'gparted', 'ipython', 'nautilus-dropbox',
            'mkgmap', 'mousepad', 'mypaint', 'nmap', 'pdfsam', 'preload',
            'rhythmbox', 'skype', 'stellarium', 'subversion', 'tar',
            'thunderbird', 'tmux', 'tuxpaint', 'vlc', 'vim', 'vim-runtime',
            'virtualbox', 'virtualbox-guest-dkms', 'wine', 'wireshark',
            'xchat', 'xvfb'
        ]

        for program in programs:
            command = 'sudo apt-get install ' + str(program) + ' -y'
            os.system('echo %s|sudo -S %s' % (sudo_password, command))

        # pycharm
        command = 'sudo add-apt-repository ppa:mystic-mirage/pycharm -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))
        command = 'sudo apt-get update'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))
        command = 'sudo apt-get install pycharm-community -y'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        # xlib
        command = 'sudo -H pip install svn+https://svn.code.sf.net/p/python-xlib/code/trunk/'
        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        #    print('remove some programs with apt-get')
        #    programs2 = ['amarok', 'audacious', 'bfgminer', 'calibre',
        #                 'clementine', 'cowsay', 'geany',
        #                 'gpodder', 'kdiff3', 'liferea', 'lmms',
        #                 'lynx', 'meld', 'midori', 'mines', 'openbve',
        #                 'rosegarden', 'simutrans', 'sudoku', 'supertuxkart']
        #    for program in programs2:
        #        command = 'sudo apt-get remove ' + str(program)
        #        os.system('echo %s|sudo -S %s' % (sudo_password, command))

        # empty trash
        os.system('rm -rf ~/.local/share/Trash/*')