Example #1
0
    def runBuild(self, buildGroupList, options):
        if not buildGroupList:
            return
        buildGroupList = set(buildGroupList)
        # by default fail if a table couldn't be built
        options['noFail'] = False
        if 'all' in buildGroupList or 'allAvail' in buildGroupList:
            if 'allAvail' in buildGroupList:
                if len(buildGroupList) == 1:
                    # don't fail on non available
                    options['noFail'] = True
                else:
                    # allAvail not compatible with others, as allAvail means not
                    # failing if build fails, but others will need failing when
                    # explicitly named
                    raise ValueError("group 'allAvail' can't be specified " \
                        + "together with other groups.")
            # if generic group given get list
            buildGroupList = build.DatabaseBuilder.getSupportedTables()

        deprecatedGroups = self._getDeprecated() & set(buildGroupList)
        if deprecatedGroups:
            warnings.warn("Group(s) '%s' is (are) deprecated" %
                          "', '".join(deprecatedGroups) +
                          " and will disappear from future versions.",
                          category=DeprecationWarning)

        # unpack groups
        groups = []
        while len(buildGroupList) != 0:
            group = buildGroupList.pop()
            if self.BUILD_GROUPS.has_key(group):
                buildGroupList.update(self.BUILD_GROUPS[group])
            else:
                groups.append(group)

        # re-add builders preferred by default, in case overwritten by user
        preferredBuilderNames = options.get('prefer', [])
        if preferredBuilderNames:
            options['prefer'] = self._combinePreferred(preferredBuilderNames,
                                                       self.DB_PREFER_BUILDERS)

        # get database connection
        configuration = dbconnector.getDefaultConfiguration()
        configuration['sqlalchemy.url'] = options.pop(
            'databaseUrl', configuration['sqlalchemy.url'])
        configuration['attach'] = [
            attach for attach in options.pop('attach',
                                             configuration.get('attach', []))
            if attach
        ]
        if 'registerUnicode' in options:
            configuration['registerUnicode'] = options.pop('registerUnicode')
        try:
            db = dbconnector.DatabaseConnector(configuration)
        except ValueError, e:
            print >> sys.stderr, "Error: %s" % e
            return False
Example #2
0
File: cli.py Project: KentVu/cjklib
    def runBuild(self, buildGroupList, options):
        if not buildGroupList:
            return
        buildGroupList = set(buildGroupList)
        # by default fail if a table couldn't be built
        options['noFail'] = False
        if 'all' in buildGroupList or 'allAvail' in buildGroupList:
            if 'allAvail' in buildGroupList:
                if len(buildGroupList) == 1:
                    # don't fail on non available
                    options['noFail'] = True
                else:
                    # allAvail not compatible with others, as allAvail means not
                    # failing if build fails, but others will need failing when
                    # explicitly named
                    raise ValueError("group 'allAvail' can't be specified " \
                        + "together with other groups.")
            # if generic group given get list
            buildGroupList = build.DatabaseBuilder.getSupportedTables()

        deprecatedGroups = self._getDeprecated() & set(buildGroupList)
        if deprecatedGroups:
            warnings.warn("Group(s) '%s' is (are) deprecated"
                    % "', '".join(deprecatedGroups)
                + " and will disappear from future versions.",
                category=DeprecationWarning)

        # unpack groups
        groups = []
        while len(buildGroupList) != 0:
            group = buildGroupList.pop()
            if self.BUILD_GROUPS.has_key(group):
                buildGroupList.update(self.BUILD_GROUPS[group])
            else:
                groups.append(group)

        # re-add builders preferred by default, in case overwritten by user
        preferredBuilderNames = options.get('prefer', [])
        if preferredBuilderNames:
            options['prefer'] = self._combinePreferred(preferredBuilderNames,
                self.DB_PREFER_BUILDERS)

        # get database connection
        configuration = dbconnector.getDefaultConfiguration()
        configuration['sqlalchemy.url'] = options.pop('databaseUrl',
            configuration['sqlalchemy.url'])
        configuration['attach'] = [attach for attach in
            options.pop('attach', configuration.get('attach', [])) if attach]
        if 'registerUnicode' in options:
            configuration['registerUnicode'] = options.pop('registerUnicode')
        try:
            db = dbconnector.DatabaseConnector(configuration)
        except ValueError, e:
            print >> sys.stderr, "Error: %s" % e
            return False
Example #3
0
    def getDefaultOptions(cls):
        options = {}
        # prefer
        options['prefer'] = cls.DB_PREFER_BUILDERS[:]

        options['attach'] = []

        config = dbconnector.getDefaultConfiguration()
        if 'registerUnicode' in config:
            options['registerUnicode'] = config['registerUnicode']

        # build specific options
        options.update(cls.getBuilderConfigSettings())
        return options
Example #4
0
    def getDefaultOptions(cls):
        options = {}
        # prefer
        options['prefer'] = cls.DB_PREFER_BUILDERS[:]

        options['attach'] = []

        config = dbconnector.getDefaultConfiguration()
        if 'registerUnicode' in config:
            options['registerUnicode'] = config['registerUnicode']

        # build specific options
        options.update(cls.getBuilderConfigSettings())
        return options
Example #5
0
    def getConnectionConfigSettings(cls):
        """
        Gets the connections settings from cjklib.conf.

        :rtype: dict
        :return: dictionary of connection options
        """
        options = {}
        config = dbconnector.getDefaultConfiguration()
        if 'sqlalchemy.url' in config:
            options['databaseUrl'] = config['sqlalchemy.url']
        if 'attach' in config:
            options['attach'] = config['attach']
        if 'registerUnicode' in config:
            options['registerUnicode'] = config['registerUnicode']
        return options
Example #6
0
File: cli.py Project: Phil-V/cjklib
    def getConnectionConfigSettings(cls):
        """
        Gets the connections settings from cjklib.conf.

        :rtype: dict
        :return: dictionary of connection options
        """
        options = {}
        config = dbconnector.getDefaultConfiguration()
        if "sqlalchemy.url" in config:
            options["databaseUrl"] = config["sqlalchemy.url"]
        if "attach" in config:
            options["attach"] = config["attach"]
        if "registerUnicode" in config:
            options["registerUnicode"] = config["registerUnicode"]
        return options
Example #7
0
File: cli.py Project: KentVu/cjklib
    def getConnectionConfigSettings(cls):
        """
        Gets the connections settings from cjklib.conf.

        :rtype: dict
        :return: dictionary of connection options
        """
        options = {}
        config = dbconnector.getDefaultConfiguration()
        if 'sqlalchemy.url' in config:
            options['databaseUrl'] = config['sqlalchemy.url']
        if 'attach' in config:
            options['attach'] = config['attach']
        if 'registerUnicode' in config:
            options['registerUnicode'] = config['registerUnicode']
        return options
Example #8
0
    def getDefaultDatabaseUrl(cls,
                              dictionaryName,
                              prefix=None,
                              local=False,
                              projectName='cjklib'):

        configuration = dbconnector.getDefaultConfiguration()
        if not configuration['sqlalchemy.url'].startswith('sqlite://'):
            # only know how to connect to this database
            return configuration['sqlalchemy.url']

        # for SQLite
        if sys.platform == 'win32':
            if local:
                path = os.path.join(os.path.expanduser('~'),
                                    '%s' % projectName)
            elif prefix:  # jichi 2/9/2014: add prefix
                path = prefix
            elif 'APPDATA' in os.environ:
                path = os.path.join(os.environ['APPDATA'], projectName)
            else:
                major, minor = sys.version_info[0:2]
                path = "C:\Python%d%d\share\%s" % (major, minor, projectName)

        elif sys.platform == 'darwin':
            if local:
                path = os.path.join(os.path.expanduser('~'), "Library",
                                    "Application Support", projectName)
            elif prefix:  # jichi 2/9/2014: add prefix
                path = prefix
            else:
                path = os.path.join("/Library", "Application Support",
                                    projectName)

        else:
            if local:
                path = os.path.join(os.path.expanduser('~'),
                                    '.%s' % projectName)
            else:
                prefix = prefix or '/usr/local'
                path = os.path.join(prefix, 'share', projectName)

        filePath = os.path.join(path, '%s.db' % dictionaryName.lower())
        return 'sqlite:///%s' % filePath
Example #9
0
    def getDefaultDatabaseUrl(cls, dictionaryName, prefix=None, local=False,
        projectName='cjklib'):

        configuration = dbconnector.getDefaultConfiguration()
        if not configuration['sqlalchemy.url'].startswith('sqlite://'):
            # only know how to connect to this database
            return configuration['sqlalchemy.url']

        # for SQLite
        if sys.platform == 'win32':
            if local:
                path = os.path.join(os.path.expanduser('~'),
                    '%s' % projectName)
            elif 'APPDATA' in os.environ:
                path = os.path.join(os.environ['APPDATA'], projectName)
            else:
                major, minor = sys.version_info[0:2]
                path = "C:\Python%d%d\share\%s" % (major, minor, projectName)

        elif sys.platform == 'darwin':
            if local:
                path = os.path.join(os.path.expanduser('~'), "Library",
                    "Application Support", projectName)
            else:
                path = os.path.join("/Library", "Application Support",
                    projectName)

        else:
            if local:
                path = os.path.join(os.path.expanduser('~'),
                    '.%s' % projectName)
            else:
                prefix = prefix or '/usr/local'
                path = os.path.join(prefix, 'share', projectName)

        filePath = os.path.join(path, '%s.db' % dictionaryName.lower())
        return 'sqlite:///%s' % filePath
Example #10
0
File: cli.py Project: Phil-V/cjklib
    def runBuild(self, buildGroupList, options):
        if not buildGroupList:
            return
        buildGroupList = set(buildGroupList)
        # by default fail if a table couldn't be built
        options["noFail"] = False
        if "all" in buildGroupList or "allAvail" in buildGroupList:
            if "allAvail" in buildGroupList:
                if len(buildGroupList) == 1:
                    # don't fail on non available
                    options["noFail"] = True
                else:
                    # allAvail not compatible with others, as allAvail means not
                    # failing if build fails, but others will need failing when
                    # explicitly named
                    raise ValueError("group 'allAvail' can't be specified " + "together with other groups.")
            # if generic group given get list
            buildGroupList = build.DatabaseBuilder.getSupportedTables()

        deprecatedGroups = self._getDeprecated() & set(buildGroupList)
        if deprecatedGroups:
            warnings.warn(
                "Group(s) '%s' is (are) deprecated" % "', '".join(deprecatedGroups)
                + " and will disappear from future versions.",
                category=DeprecationWarning,
            )

        # unpack groups
        groups = []
        while len(buildGroupList) != 0:
            group = buildGroupList.pop()
            if group in self.BUILD_GROUPS:
                buildGroupList.update(self.BUILD_GROUPS[group])
            else:
                groups.append(group)

        # re-add builders preferred by default, in case overwritten by user
        preferredBuilderNames = options.get("prefer", [])
        if preferredBuilderNames:
            options["prefer"] = self._combinePreferred(preferredBuilderNames, self.DB_PREFER_BUILDERS)

        # get database connection
        configuration = dbconnector.getDefaultConfiguration()
        configuration["sqlalchemy.url"] = options.pop("databaseUrl", configuration["sqlalchemy.url"])
        configuration["attach"] = [
            attach for attach in options.pop("attach", configuration.get("attach", [])) if attach
        ]
        if "registerUnicode" in options:
            configuration["registerUnicode"] = options.pop("registerUnicode")
        try:
            db = dbconnector.DatabaseConnector(configuration)
        except ValueError as e:
            print("Error: %s" % e, file=sys.stderr)
            return False

        # create builder instance
        dbBuilder = build.DatabaseBuilder(dbConnectInst=db, **options)

        try:
            dbBuilder.build(groups)

            print("finished")
        except exception.UnsupportedError as e:
            print("Error building local tables, some names do not exist: %s" % e, file=sys.stderr)
            return False
        except KeyboardInterrupt:
            print("Keyboard interrupt.", file=sys.stderr)
            try:
                # remove temporary tables
                dbBuilder.clearTemporary()
            except KeyboardInterrupt:
                print("Interrupted while cleaning temporary tables", file=sys.stderr)
            return False

        return True