1_general_forum/currency-ledger/scripts/manage-organization.py

147 lines
5.7 KiB
Python
Executable File

#!/usr/bin/env python3
"""
Organizational Management Script
Handle team memberships and role assignments
"""
import csv
import yaml
from datetime import datetime
import os
class OrganizationManager:
def __init__(self):
self.base_path = os.path.join(os.path.dirname(__file__), '..')
self.load_policies()
def load_policies(self):
"""Load organizational structure policies"""
with open(os.path.join(self.base_path, 'policies', 'organizational-structure.yml'), 'r') as f:
self.org_structure = yaml.safe_load(f)
with open(os.path.join(self.base_path, 'policies', 'license-policies.yml'), 'r') as f:
self.license_policies = yaml.safe_load(f)
def get_owner_info(self, owner_id):
"""Get complete owner information"""
book_file = os.path.join(self.base_path, 'ownership', 'book-of-owners.csv')
with open(book_file, 'r') as f:
reader = csv.DictReader(f)
for owner in reader:
if owner['owner_id'] == owner_id:
# Parse multi-value fields
owner['team_list'] = [t.strip() for t in owner['team_memberships'].split(',') if t.strip()]
owner['role_list'] = [r.strip() for r in owner['role_assignments'].split(',') if r.strip()]
owner['seniority_list'] = [s.strip() for s in owner['seniority_levels'].split(',') if s.strip()]
return owner
return None
def assign_role(self, owner_id, role_id, seniority="junior"):
"""Assign a role to an owner"""
print(f"🎯 Assigning role {role_id} to owner {owner_id}...")
# Validate role exists
if role_id not in self.org_structure['roles']:
print(f"❌ Role {role_id} not found in organizational structure")
return False
role_info = self.org_structure['roles'][role_id]
team_id = role_info['team']
# Get current owner info
owner = self.get_owner_info(owner_id)
if not owner:
print(f"❌ Owner {owner_id} not found")
return False
# Add team membership if not already member
if team_id not in owner['team_list']:
owner['team_list'].append(team_id)
# Add role assignment
if role_id not in owner['role_list']:
owner['role_list'].append(role_id)
owner['seniority_list'].append(seniority)
else:
print(f"⚠️ Owner already has role {role_id}")
return False
# Update Book of Owners
self.update_owner_record(owner_id, owner)
print(f"✅ Role {role_id} assigned to {owner['display_name']} as {seniority}")
print(f"✅ Auto-added to team {team_id}")
return True
def update_owner_record(self, owner_id, owner_data):
"""Update owner record in Book of Owners"""
book_file = os.path.join(self.base_path, 'ownership', 'book-of-owners.csv')
timestamp = datetime.now().isoformat() + 'Z'
# Read all records
records = []
with open(book_file, 'r') as f:
reader = csv.DictReader(f)
for record in reader:
if record['owner_id'] == owner_id:
# Update this record
record['team_memberships'] = ','.join(owner_data['team_list'])
record['role_assignments'] = ','.join(owner_data['role_list'])
record['seniority_levels'] = ','.join(owner_data['seniority_list'])
record['last_updated'] = timestamp
records.append(record)
# Write back
with open(book_file, 'w', newline='') as f:
fieldnames = ['owner_id', 'display_name', 'license_type', 'license_date', 'current_sk', 'voting_weight', 'status', 'team_memberships', 'role_assignments', 'seniority_levels', 'last_updated']
writer = csv.DictWriter(f, fieldnames=fieldnames)
writer.writeheader()
writer.writerows(records)
def show_organizational_chart(self):
"""Display current organizational structure"""
print("🏢 SMARTUP ZERO ORGANIZATIONAL CHART")
print("=" * 50)
book_file = os.path.join(self.base_path, 'ownership', 'book-of-owners.csv')
try:
with open(book_file, 'r') as f:
reader = csv.DictReader(f)
owners = list(reader)
# Filter out comment rows
active_owners = [o for o in owners if o['owner_id'] and not o['owner_id'].startswith('#')]
if active_owners:
for owner in active_owners:
print(f"👤 {owner['display_name']} (#{owner['owner_id']})")
print(f" License: {owner['license_type']} | SK: {owner['current_sk']}")
print(f" Teams: {owner['team_memberships']}")
print(f" Roles: {owner['role_assignments']} ({owner['seniority_levels']})")
print()
else:
print("📝 No active owners found")
except FileNotFoundError:
print("❌ Book of Owners not found")
def main():
"""Main organizational management interface"""
manager = OrganizationManager()
print("🏢 ORGANIZATIONAL MANAGEMENT")
print("=" * 40)
try:
manager.show_organizational_chart()
except Exception as e:
print(f"❌ Error: {e}")
print("\n" + "=" * 50)
print("💡 Use this script to manage team memberships and role assignments")
if __name__ == "__main__":
main()