Skip to content

Commit

Permalink
move CLI stuff from pickle_schema into schema-tool
Browse files Browse the repository at this point in the history
  • Loading branch information
justdave committed May 4, 2024
1 parent 2dbe9f4 commit 76163e3
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 23 deletions.
11 changes: 1 addition & 10 deletions pickle_schema.py
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,10 @@
#
# This document is not confidential.

import MySQLdb
import pickle
import sys
import os

import MySQLdb

class BzSchemaPickleException(Exception):
def __init__(self, message):
Expand Down Expand Up @@ -97,14 +96,6 @@ def pickle_schema(schema_version, db_name):
f.close()


if __name__ == "__main__":
try:
(schema_version, db_name) = sys.argv[1:]
except ValueError:
print("Please pass the schema version and the database name.")
sys.exit()
pickle_schema(schema_version, db_name)

# A. REFERENCES
#
#
Expand Down
34 changes: 27 additions & 7 deletions schema-tool
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,9 @@
# Perforce Defect Tracking Integration Project
# <http://www.ravenbrook.com/project/p4dti/>
#
# MAKE_SCHEMA_DOC.PY -- GENERATE BUGZILLA SCHEMA DOCUMENTATION
# SCHEMA-TOOL -- COMMAND LINE INTERFACE TO SCHEMA MODULES
#
# Nick Barnes, Ravenbrook Limited, 2003-07-07
# David Miller, Zarro Boogs Corporation, 2024-05-04
#
#
# 1. INTRODUCTION
Expand All @@ -28,10 +28,10 @@ import argparse
import subprocess
from pprint import pformat
from black import Mode, format_str
from collections import OrderedDict

import schema_remarks
from make_schema_doc import BzSchemaProcessingException, make_tables, version_compare
from make_schema_doc import BzSchemaProcessingException, make_tables
from pickle_schema import pickle_schema


def write_file(first, last, file):
Expand Down Expand Up @@ -259,7 +259,8 @@ def generate_schema_remarks(args):
output = template.format(**var_dict)
outfile.write(output)
subprocess.run(
["diff", "-u", "--color", "schema_remarks.py", "schema_remarks_new.py"]
["diff", "-u", "--color", "schema_remarks.py", "schema_remarks_new.py"],
check=True,
)
print("Wrote changes to schema_remarks_new.py.")
print("If these changes are okay, move it overtop of schema_remarks.py")
Expand Down Expand Up @@ -306,6 +307,9 @@ def validate_schema_remarks(_args):
sys.exit()
print("Versions validated.")

def pickle_parser(args):
pickle_schema(args.version, args.db_name)
print("Success!")

if __name__ == "__main__":
parser = argparse.ArgumentParser(
Expand Down Expand Up @@ -400,6 +404,22 @@ if __name__ == "__main__":
help="The destination version of the schema to compare",
)
parser_generate.set_defaults(func=generate_schema_remarks)
parser_pickle = subparsers.add_parser(
"pickle",
help="Generate a pickle file for a specific version",
description="Generate a pickle file for a specific version",
)
parser_pickle.add_argument(
'version',
metavar = 'version',
help="The Bugzilla version number associated with the schema",
)
parser_pickle.add_argument(
'db_name',
metavar='db_name',
help="The name of the database to analyze"
)
parser_pickle.set_defaults(func=pickle_parser)
main_args = parser.parse_args()
main_args.func(main_args)

Expand All @@ -408,12 +428,12 @@ if __name__ == "__main__":
#
# B. DOCUMENT HISTORY
#
# 2001-03-08 NB Created.
# 2024-05-04 Created.
#
#
# C. COPYRIGHT AND LICENSE
#
# This file is copyright (c) 2001 Perforce Software, Inc. All rights
# This file is copyright (c) 2024 Bugzilla Project Contributors. All rights
# reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down
10 changes: 4 additions & 6 deletions updating.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,13 @@ For any given release of Bugzilla, the process goes something like this:

- If there are schema changes, or if you aren't sure, download the
full Bugzilla release, do a vanilla install on your MySQL, then run
``./pickle_schema.py version db_name``. For
``./schema-tool pickle version db_name``. For
instance::

> ./pickle_schema.py 3.8.12 bugs
> ./schema-tool pickle 3.8.12 bugs

For this to work you will have to have MySQLdb (the Python MySQL interface
library). You can install it with ``pip install mysqlclient``. It will use
your database host and credentials from the ``[pickle_schema]`` section of
``.my.cnf`` in your home directory. For example
This uses your database host and credentials from the ``[pickle_schema]``
section of ``.my.cnf`` in your home directory. For example

.. code-block:: ini
Expand Down

0 comments on commit 76163e3

Please sign in to comment.