Exemple #1
0
def main(argv=sys.argv):
    if len(argv) != 3:
        usage(argv)
    config_uri = argv[1]
    svn_csv = argv[2]
    setup_logging(config_uri)
    settings = get_appsettings(config_uri, name='dashboard')
    engine = engine_from_config(settings, 'sa.dashboard.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all()

    with transaction.manager:
        session = DBSession()
        with open(svn_csv, 'rb') as csvfile:
            reader = csv.reader(csvfile)
            for project_id, svn_repo in reader:
                svn_repo = svn_repo.strip()
                project_id = project_id.strip()
                project = session.query(Project).get(project_id)
                app = Application(name='SVN',
                                  project_id=project_id,
                                  application_type=SVN,
                                  svn_name=svn_repo)
                project.add_application(app)
                print 'Creating svn app [%s] for project [%s]' % (svn_repo, project_id)
Exemple #2
0
def main(argv=sys.argv):
    if len(argv) != 2:
        usage(argv)

    config_uri = argv[1]
    setup_logging(config_uri)
    env = bootstrap('%s#dashboard'% config_uri)
    settings = env.get('registry').settings
    engine = engine_from_config(settings, 'sa.dashboard.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all()

    def generate_password():
        return base64.urlsafe_b64encode(os.urandom(30))

    with transaction.manager:
        session = DBSession()
        users = [
            add_user(session, u'*****@*****.**', fullname='Administrator', password='******'),
        ]

        role_admin = add_role(session, 'administrator')
        role_admin.users.append(users[0])

        add_role(session, 'external_developer')
        add_role(session, 'internal_developer')
        add_role(session, 'secretary')
        add_role(session, 'customer')
        add_role(session, 'project_manager')

        session.add(GlobalConfig(id=1))
Exemple #3
0
def main(argv=sys.argv):
    if len(argv) > 3:
        usage(argv)
    if len(argv) == 3:
        use_small = True
    else:
        use_small = False
    config_uri = argv[1]
    setup_logging(config_uri)
    env = bootstrap('%s#dashboard'% config_uri)
    settings = env.get('registry').settings
    engine = engine_from_config(settings, 'sa.dashboard.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine
    Base.metadata.create_all()


    with transaction.manager:
        random.seed(42)
        session = DBSession()
        session.add(GlobalConfig(id=1))

        users = [
                 add_user(session, u'*****@*****.**', fullname='John Smith'),
                 add_user(session, u'*****@*****.**', fullname='Mr. Customer'),
        ]

        role_admin = add_role(session, 'administrator')
        role_admin.users.append(users[0])

        add_role(session, 'external_developer')
        add_role(session, 'internal_developer')
        add_role(session, 'secretary')
        role_customer = add_role(session, 'customer')
        role_customer.users.append(users[1])
        add_role(session, 'project_manager')

        if use_small:
            small_dummies(session,users,settings)
        else:
            full_dummies(session,users,settings)
    def __call__(self, parser, namespace, values, option_string):
        super(Quality, self).__init__(parser, namespace, values, option_string)
        self.namespace = namespace
        config_uri = namespace.configuration
        setup_logging(config_uri)
        settings = get_appsettings(config_uri, name='dashboard')
        engine = engine_from_config(settings, 'sa.dashboard.')
        DBSession.configure(bind=engine)
        Base.metadata.bind = engine
        Base.metadata.create_all()
        self.metadata = MetaData(engine)

        #if not namespace.google and not namespace.filename:
        #    raise argparse.ArgumentTypeError(u'You need to pass filename or google.')

        configuration = {}
        tmp = tempfile.NamedTemporaryFile(suffix='.csv')
        namespace.filename = tmp.name
        tmp.close()
        configuration['filename'] = namespace.filename
        print 'Creating file %s' % namespace.filename
        setattr(namespace, option_string.strip('--'), configuration)
def main(argv=sys.argv):
    if len(argv) < 2:
        usage(argv)

    config_uri = argv[1]
    setup_logging(config_uri)
    env = bootstrap('%s#dashboard'% config_uri)
    settings = env.get('registry').settings
    engine = engine_from_config(settings, 'sa.dashboard.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine

    google_opts = argv[2:]
    try:
        google_user = google_opts.pop(0)
    except IndexError:
        google_user = raw_input('Google Spreadsheet User: '******'Google Spreadsheet ID: ')
    google_password = getpass.getpass("Google Spreadsheet Password: ")

    gc = gspread.login(google_user, google_password)
    sht = gc.open_by_key(spreadsheet_key)
    worksheet = sht.get_worksheet(0)
    crs = worksheet.get_all_records()

    contracts = {}
    for row in crs:
        if not row['titolocommessa']:
            continue
        contract_uid = '%s_%s_%s' % (row['project_name'],
                                     row['titolocommessa'],
                                     row['customer_id'])
        contracts.setdefault(contract_uid, {'crs': []})
        contracts[contract_uid]['titolocommessa'] = row['titolocommessa']
        contracts[contract_uid]['nrcontratto'] = row['nrcontratto']
        contracts[contract_uid]['gg'] = row['gg'] or 0
        contracts[contract_uid]['amount'] = row['amount'] or 0
        contracts[contract_uid]['crs'].append(row['cr_id'])
        contracts[contract_uid]['stato'] = map_state(row['stato'])

    # now we have a structure:
    # contracts['ContractUID'] = {'crs': ['customer_request_id_1',
    #                                     'customer_request_id_2'],
    #                             'gg': '12'}

    with transaction.manager:
        session = DBSession()
        for contract_uid, opts in contracts.items():
            crs = [session.query(CustomerRequest).get(a) for a in opts['crs']]
            crs = [a for a in crs if a]
            if not crs:
                continue
            contract = crs[0].contract
            if not contract:
                contract = Contract(name=opts['titolocommessa'])
            contract.days = opts['gg']
            contract.ammount = opts['amount']
            contract.contract_number = opts['nrcontratto']
            contract.workflow_state = opts['stato']
            for cr in crs:
                if not cr:
                    continue
                cr.contract = contract
                contract.project_id = cr.project_id

        update_time_entries()
Exemple #6
0
def initialize_sql(config=None, engine=None):
    if not engine:
        engine = engine_from_config(config.registry.settings, 'sa.dashboard.')
    DBSession.configure(bind=engine)
    Base.metadata.bind = engine