|
| 1 | +#!/usr/bin/env python |
| 2 | + |
| 3 | +# Copyright 2023 Google |
| 4 | +# |
| 5 | +# Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | +# you may not use this file except in compliance with the License. |
| 7 | +# You may obtain a copy of the License at |
| 8 | +# |
| 9 | +# http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +# |
| 11 | +# Unless required by applicable law or agreed to in writing, software |
| 12 | +# distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | +# See the License for the specific language governing permissions and |
| 15 | +# limitations under the License. |
| 16 | + |
| 17 | +import sys |
| 18 | +import plistlib |
| 19 | +import json |
| 20 | + |
| 21 | +# Check if the PLIST file path was provided as a command-line argument |
| 22 | +if len(sys.argv) != 2: |
| 23 | + print("Usage: python read_plist.py <path_to_googleService-info.plist>") |
| 24 | + sys.exit(1) |
| 25 | + |
| 26 | +plist_file_path = sys.argv[1] |
| 27 | + |
| 28 | +# Read the PLIST file |
| 29 | +try: |
| 30 | + with open(plist_file_path, 'rb') as plist_file: |
| 31 | + plist_data = plistlib.load(plist_file) |
| 32 | + |
| 33 | + # Extract the 'project_id' field only for confidentiality |
| 34 | + project_id = plist_data.get('PROJECT_ID') |
| 35 | + |
| 36 | + if project_id: |
| 37 | + with open('Firestore/Example/App/project_info.json', 'w') as json_file: |
| 38 | + json.dump({'project_id': project_id}, json_file) |
| 39 | + else: |
| 40 | + print("PROJECT_ID key not found in the plist file.") |
| 41 | +except FileNotFoundError: |
| 42 | + print(f"File not found: {plist_file_path}") |
| 43 | +except plistlib.InvalidFileException as e: |
| 44 | + print(f"Invalid plist file: {e}") |
| 45 | +except Exception as e: |
| 46 | + print(f"An error occurred: {e}") |
0 commit comments