コード例 #1
0
    def _get_all_backgrounds(self, background_subdirectory, background_header):
        bg_root_dir = 'backgrounds'
        backgrounds = []

        # If a specific sub directory of the background directory was given, append it to bg_root_dir
        if background_subdirectory:
            bg_dir = os.path.join(bg_root_dir, background_subdirectory)
        else:
            bg_dir = bg_root_dir

        # Get a a list of all filenames
        absolute_bg_dir = os.path.join(get_main_dir(), 'data', bg_dir)
        all_bg_filenames = os.listdir(absolute_bg_dir)

        for filename in all_bg_filenames:
            # check if this pathname is a directory: skip
            if os.path.isdir(os.path.join(absolute_bg_dir, filename)):
                continue
            
            # check if files only contain valid fileformats
            if not self._is_file_format_valid(filename):
                print("Invalid file found in ", bg_dir, ": ", filename)
                raise SystemExit()
            
            # Load the image from the system
            bg_image = load_image(os.path.join(bg_dir, filename))[0]

            # Add some final touches like play area and text
            done_background = self._finalize_background(bg_image, background_header)

            backgrounds.append(bg_image)

        return backgrounds
コード例 #2
0
def clear_aliases():
    aliases.clear()
    with open("%s/aliases/aliases.csv" % utils.get_main_dir(),
              mode='w') as csvf:
        fields = ['alias', 'command']
        csvw = csv.DictWriter(csvf, fieldnames=fields)
        csvw.writeheader()
        return True
コード例 #3
0
def setup_aliases():
    with open("%s/aliases/aliases.csv" % utils.get_main_dir(),
              mode='r') as csvf:
        csvr = csv.DictReader(csvf)
        print("Setting up registered aliases...")
        for i, row in enumerate(csvr):
            aliases[row['alias']] = row['command']
            logging.info("Added [%s-%s] to the registered aliases list." %
                         (row['alias'], row['command']))
コード例 #4
0
def add_to_aliases(alias, command):
    with open("%s/aliases/aliases.csv" % utils.get_main_dir(),
              mode='a',
              newline='') as csvf:
        headers = ['alias', 'command']
        csvw = csv.DictWriter(csvf, fieldnames=headers)
        csvw.writerow({'alias': alias, 'command': command})
        aliases[alias] = command
        print("Added [%s-%s] to the user list." % (alias, command))
        return True
コード例 #5
0
    def openDocumentation(self):
        import subprocess
        import webbrowser
        import sys
        from utils import get_main_dir

        url = get_main_dir() + "/documentation/index.html"
        if sys.platform == "darwin":  # in case of OS X
            subprocess.Popen(['open', url])
        else:
            webbrowser.open_new_tab(url)
コード例 #6
0
def remove_from_aliases(alias):
    if alias in aliases.keys():
        aliases.pop(alias, None)
        with open("%s/aliases/aliases.csv" % utils.get_main_dir(),
                  mode='r') as csvf:
            csvr = csv.reader(csvf)
            content = list(csvr)
            ind = [(i, j.index(alias)) for i, j in enumerate(content)
                   if alias in j]
            if (content[ind[0][0]][0]) == alias:
                content.remove(content[ind[0][0]])
            return overwrite_aliases(content)
コード例 #7
0
def set_alias(alias, command):
    if alias in aliases.keys():
        with open("%s/aliases/aliases.csv" % utils.get_main_dir(),
                  mode='r') as csvf:
            csvr = csv.reader(csvf)
            content = list(csvr)
            ind = [(i, j.index(alias)) for i, j in enumerate(content)
                   if alias in j]
            content[ind[0][0]][1] = command
            aliases[alias] = command
            return overwrite_aliases(content)
    return False
コード例 #8
0
def alias_check(alias):
    if alias in aliases.keys():
        return aliases[alias]

    with open("%s/aliases/aliases.csv" % utils.get_main_dir(),
              mode='r') as csvf:
        csvr = csv.DictReader(csvf)
        for i, row in enumerate(csvr):
            if row['alias'] == alias:
                aliases[alias] = row['command']
                return alias[alias]
    return None
コード例 #9
0
def overwrite_aliases(content):
    try:
        with open("%s/aliases/aliases.csv" % utils.get_main_dir(),
                  mode='w',
                  newline='') as csvf:
            csvw = csv.writer(csvf)
            csvw.writerows(content)
            return True
    except Exception:
        print("There was a problem overwriting the privileges csv file.")
        logging.critical(
            "There was a problem overwriting the privileges csv file.")
        return False
コード例 #10
0
    def _read_file(self, filename):
        liedje = None
        songpath = os.path.join(utils.get_main_dir(), 'data', filename)

        with open(songpath) as f:
            liedje = f.read()

        liedje = liedje.strip().split("\n")

        teller = 0
        for i in liedje:
            liedje[teller] = i.split(" ")
            teller += 1

        return liedje
コード例 #11
0
    def initLogging(self):

        if not self.initialized:
            from utils import get_main_dir
            for handler in logging.getLogger().handlers:
                logging.getLogger().removeHandler(handler)

            formatter = logging.Formatter(
                '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
            fileHandler = logging.FileHandler(get_main_dir() + "/Log.txt")
            fileHandler.setFormatter(formatter)
            logging.getLogger().addHandler(fileHandler)

            if len(logging.getLogger().handlers) < 2:  ## ugly, but it works
                consoleHandler = logging.StreamHandler()
                logging.getLogger().addHandler(consoleHandler)

            logging.getLogger().setLevel(logging.INFO)

            self.initialized = True
コード例 #12
0
ファイル: setup.py プロジェクト: zhengfj1994/MetExtract-II
        with open(path + "/RPATH.conf", "rb") as rconf:
            line = rconf.readline()
            os.environ["R_HOME"] = line
            return True
    else:
        return False


__RHOMEENVVAR = ""
import os
from utils import get_main_dir
if "R_HOME" in os.environ.keys():
    __RHOMEENVVAR = os.environ["R_HOME"]

# try to load r configuration file (does not require any environment variables or registry keys)
if not loadRConfFile(path=get_main_dir()) or not checkR():
    os.environ["R_HOME"] = get_main_dir() + "/R"

    if checkR():
        with open("RPATH.conf", "wb") as rconf:
            rconf.write(get_main_dir() + "/R")
            tryLoad = False

            # Show a dialog box to the user that R could not be started
            from os import sys
            from PyQt4 import QtGui, QtCore

            app = QtGui.QApplication(sys.argv)

            QtGui.QMessageBox.information(
                None, "MetExtract",