MCPcopy Create free account
hub / github.com/OpenRaiser/PaperFlow / main

Function main

scripts/init_profiles_from_roles.py:155–207  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

153
154
155def main():
156 parser = argparse.ArgumentParser(description="Initialize Profiles from roles.json")
157 parser.add_argument("--roles-path", type=str, default="data/roles.json", help="roles.json 路径")
158 parser.add_argument("--db-path", type=str, default="data/paperflow.db", help="数据库路径")
159 parser.add_argument(
160 "--overwrite-profiles",
161 action="store_true",
162 help="Back up and recreate profiles from roles.json. This deletes only profile rows and keeps papers intact.",
163 )
164 args = parser.parse_args()
165
166 # 加载 roles
167 print(f"Loading roles from {args.roles_path}...")
168 roles = load_roles(args.roles_path)
169 print(f" Found {len(roles)} roles")
170
171 # 初始化数据库
172 resolved_db_path = configure_db_path(args.db_path)
173 print(f"\nInitializing database: {resolved_db_path}...")
174 init_db()
175
176 if args.overwrite_profiles:
177 backup_path = backup_profiles(resolved_db_path)
178 removed_count = clear_profiles_only(resolved_db_path)
179 print("\nOverwriting profiles only.")
180 print(f" Backup: {backup_path}")
181 print(f" Removed profile rows: {removed_count}")
182 print(" Papers table was not modified.")
183
184 # 创建 profile
185 print("\nCreating profiles...")
186 created_count = 0
187 existing_count = 0
188
189 for role_name, role_data in sorted(roles.items()):
190 profile = build_profile_from_role(role_name, role_data)
191 user_id = profile["user_id"]
192
193 profile_id = create_profile(user_id, profile)
194 if profile_id:
195 created_count += 1
196 print(f" + {user_id} ({role_name}): {len(profile['core_directions'])} directions")
197 else:
198 existing_count += 1
199 print(f" ~ {user_id} ({role_name}): already exists")
200
201 print()
202 print("=" * 60)
203 print("Profiles Initialized")
204 print("=" * 60)
205 print(f"Created: {created_count}")
206 print(f"Already exists: {existing_count}")
207 print(f"Total: {created_count + existing_count}")
208
209
210if __name__ == "__main__":

Callers 1

Calls 7

init_dbFunction · 0.90
create_profileFunction · 0.90
configure_db_pathFunction · 0.85
backup_profilesFunction · 0.85
clear_profiles_onlyFunction · 0.85
build_profile_from_roleFunction · 0.85
load_rolesFunction · 0.70

Tested by

no test coverage detected