Example #1
0
def commandProfileSet(args, session):
  profile = session.query(Profile).filter_by(handle=args.handle).first()
  dieIf(not profile, 'Profile not found.')
  dieIf(not hasattr(profile, args.setting_name), 'Setting does not exist.')
  setattr(profile, args.setting_name, args.setting_value)
  session.commit()
  print('Set ' + args.setting_name + '=' + args.setting_value)
Example #2
0
def commandInit(args, dummy):
  db_path = args.db_path

  dieIf(os.path.exists(db_path), "File '" + db_path + "' already exists.\n")

  db = sqlalchemy.create_engine('sqlite:///' + db_path)

  base.Base.metadata.create_all(db)
Example #3
0
def _createInvoice(profile):
  result = _invokeLokki(profile, [
    'lk',
    'invoice',
    'add',
    '--json',
  ])

  dieIf('invoice' not in result, 'Failed to create invoice.')
  dieIf('invoice_number' not in result['invoice'], 'Failed to create invoice.')

  return result['invoice']['invoice_number']
Example #4
0
def _addCompositeRow(profile, invoiceNumber, title):
  result = _invokeLokki(profile, [
    'lk',
    'composite',
    'add',
    '--json',

    '--external_source',
    'atrium-fetch',

    title,
  ])

  dieIf('index' not in result, 'Failed to create composite row.')

  return result['index']
Example #5
0
def _request(connection, url, headers, body):
  if body:
    method = 'POST'
  else:
    method = 'GET'
  url_parsed = urllib.parse.urlparse(url)
  path = urllib.parse.urlunparse([
    '',
    '',
    url_parsed.path,
    url_parsed.params,
    url_parsed.query,
    ''
  ])
  connection.request(method, path, body, headers)
  response = connection.getresponse()
  dieIf(response.status != 200, 
    "Request to " + url + " failed: " + str(response.status) + " " 
    + response.reason)
  return response.read().decode('utf-8')
Example #6
0
def _getSetting(session, name):
  setting = session.query(Setting).filter_by(name=name).first()
  dieIf(not setting, 'Setting ' + name + ' not set.')
  return setting.value
Example #7
0
def commandProfileGet(args, session):
  profile = session.query(Profile).filter_by(handle=args.handle).first()
  dieIf(not profile, 'Profile not found.')
  dieIf(not hasattr(profile, args.setting_name), 'Setting does not exist.')
  print(getattr(profile, args.setting_name))
Example #8
0
def commandProfileRemove(args, session):
  profile = session.query(Profile).filter_by(handle=args.handle).first()
  dieIf(not profile, 'Profile not found.')

  session.delete(profile)
  session.commit()