1#************************************************************** 2# 3# Licensed to the Apache Software Foundation (ASF) under one 4# or more contributor license agreements. See the NOTICE file 5# distributed with this work for additional information 6# regarding copyright ownership. The ASF licenses this file 7# to you under the Apache License, Version 2.0 (the 8# "License"); you may not use this file except in compliance 9# with the License. You may obtain a copy of the License at 10# 11# http://www.apache.org/licenses/LICENSE-2.0 12# 13# Unless required by applicable law or agreed to in writing, 14# software distributed under the License is distributed on an 15# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16# KIND, either express or implied. See the License for the 17# specific language governing permissions and limitations 18# under the License. 19# 20# usage: runpy.sh fixtures/base/verify.py <port> <outdir> [<name>.odb ...] 21# Reloads base-*.odb files of <outdir> read-only and prints what the data source holds. 22import glob, os, sys, uno 23from unohelp import connect, desktop, pv 24 25port, out = int(sys.argv[1]), os.path.abspath(sys.argv[2]) 26d = desktop(connect(port)) 27NO_CONNECT = ("mysql", "oracle", "odbc", "ldap", "adabas", "settings") 28 29 30def names(c): 31 return list(c.ElementNames) if c is not None else [] 32 33 34def walk(c, prefix=""): 35 for n in names(c): 36 e = c.getByName(n) 37 if hasattr(e, "ElementNames"): 38 yield from walk(e, prefix + n + "/") 39 else: 40 yield prefix + n 41 42 43paths = [os.path.join(out, n) for n in sys.argv[3:]] or sorted(glob.glob(os.path.join(out, "base-*.odb"))) 44for path in paths: 45 base = os.path.basename(path) 46 doc = d.loadComponentFromURL(uno.systemPathToFileUrl(path), "_blank", 0, 47 (pv("Hidden", True), pv("MacroExecutionMode", 0), pv("ReadOnly", True))) 48 ds = doc.DataSource 49 row = {"url": ds.URL.split("/work/")[-1] if "file:" in ds.URL else ds.URL, 50 "user": ds.User, "pwreq": ds.IsPasswordRequired, 51 "queries": names(ds.QueryDefinitions), "tabledefs": names(ds.Tables), 52 "forms": list(walk(doc.FormDocuments)), "reports": list(walk(doc.ReportDocuments)), 53 "filter": list(ds.TableFilter), "typefilter": list(ds.TableTypeFilter)} 54 q = ds.QueryDefinitions 55 if "Q_Cols" in names(q): 56 row["Q_Cols.columns"] = names(q.getByName("Q_Cols").Columns) 57 if not any(base.startswith("base-" + n) for n in NO_CONNECT): 58 try: 59 conn = ds.getConnection("", "") 60 row["tables"] = names(conn.Tables) 61 st = conn.createStatement() 62 counts = {} 63 for t in names(conn.Tables): 64 rs = st.executeQuery('SELECT COUNT(*) FROM "%s"' % t) 65 rs.next() 66 counts[t] = rs.getInt(1) 67 row["rows"] = counts 68 conn.close() 69 except Exception as e: 70 row["connect"] = "FAIL " + str(e)[:150] 71 for fdoc in ("Form1",): 72 fd = doc.FormDocuments 73 if fd.hasByName(fdoc): 74 f = fd.loadComponentFromURL(fdoc, "", 0, (pv("OpenMode", "open"),)) 75 forms = f.DrawPage.Forms 76 row["Form1.controls"] = sum(len(names(forms.getByName(n))) for n in names(forms)) 77 row["Form1.forms"] = names(forms) 78 cmd = uno.createUnoStruct("com.sun.star.ucb.Command") 79 cmd.Name, cmd.Handle = "close", -1 80 fd.getByName(fdoc).execute(cmd, 0, None) 81 row["settings"] = sorted(p.Name for p in doc.DataSource.Info if p.Name.startswith("My")) 82 print(base, row) 83 doc.close(True) 84