def script(path, **opts): """%prog script PATH Create an empty change script at the specified path. """ try: script_.PythonFile.create(path, **opts) except exceptions.PathFoundError, e: raise exceptions.KnownError("The path %s already exists" % e.args[0])
def catch_known_errors(f, *a, **kw): """Decorator that catches known api errors .. versionadded: 0.5.4 """ try: f(*a, **kw) except exceptions.PathFoundError, e: raise exceptions.KnownError("The path %s already exists" % e.args[0])
def create(repository, name, **opts): """%prog create REPOSITORY_PATH NAME [--table=TABLE] Create an empty repository at the specified path. You can specify the version_table to be used; by default, it is '_version'. This table is created in all version-controlled databases. """ try: rep = Repository.create(repository, name, **opts) except exceptions.PathFoundError, e: raise exceptions.KnownError("The path %s already exists" % e.args[0])
def _migrate_version(schema, version, upgrade, err): if version is None: return version # Version is specified: ensure we're upgrading in the right direction # (current version < target version for upgrading; reverse for down) version = cls_vernum(version) cur = schema.version if upgrade is not None: if upgrade: direction = cur <= version else: direction = cur >= version if not direction: raise exceptions.KnownError(err % (cur, version)) return version
def script(description, repository=None, **opts): """%prog script [--repository=REPOSITORY_PATH] DESCRIPTION Create an empty change script using the next unused version number appended with the given description. For instance, manage.py script "Add initial tables" creates: repository/versions/001_Add_initial_tables.py """ try: if repository is None: raise exceptions.UsageError("A repository must be specified") repos = cls_repository(repository) repos.create_script(description, **opts) except exceptions.PathFoundError, e: raise exceptions.KnownError("The path %s already exists" % e.args[0])
def make_update_script_for_model(url, oldmodel, model, repository, **opts): """%prog make_update_script_for_model URL OLDMODEL MODEL REPOSITORY_PATH Create a script changing the old Python model to the new (current) Python model, sending to stdout. NOTE: This is EXPERIMENTAL. """ # TODO: get rid of EXPERIMENTAL label echo = 'True' == opts.get('echo', False) engine = create_engine(url, echo=echo) try: print cls_script_python.make_update_script_for_model( engine, oldmodel, model, repository, **opts) except exceptions.PathFoundError, e: # TODO: get rid of this? if we don't add back path param raise exceptions.KnownError("The path %s already exists" % e.args[0])
def script_sql(database, repository=None, **opts): """%prog script_sql [--repository=REPOSITORY_PATH] DATABASE Create empty change SQL scripts for given DATABASE, where DATABASE is either specific ('postgres', 'mysql', 'oracle', 'sqlite', etc.) or generic ('default'). For instance, manage.py script_sql postgres creates: repository/versions/001_upgrade_postgres.py and repository/versions/001_downgrade_postgres.py """ try: if repository is None: raise exceptions.UsageError("A repository must be specified") repos = cls_repository(repository) repos.create_script_sql(database, **opts) except exceptions.PathFoundError, e: raise exceptions.KnownError("The path %s already exists" % e.args[0])