Idea 1 for GSoC 2013

20 views
Skip to first unread message

Arsenii Bochechko

unread,
Apr 26, 2013, 8:14:07 AM4/26/13
to crow...@googlegroups.com
I've submitted a proposal for this idea, and think of myself as capable of doing it, and as a proof that I have a knowledge of python - here is part of the python code, I've used for automating user interface clicks

def setRightTrimFlag(app, mainWindow):
  makeOp(lambda: mainWindow.MenuItem('View->Options').Click(), lambda: isWindowPresent(app, OPTIONS_TITLE_REGEXP, maxAttempts = 1), maxAttempts = 7)
  optionsWindow = connectToWindow(app, OPTIONS_TITLE_REGEXP)
  checkBox = None
  if DATABASE_TYPE == 2:
    checkBox = optionsWindow.CheckBox2
  else:
    checkBox = optionsWindow.CheckBox3
  if RIGHT_TRIM == True:
    checkBox.Check()
  else:
    checkBox.UnCheck()
  makeOp(lambda: optionsWindow.OK.CloseClick(), lambda: not isWindowPresent(app, OPTIONS_TITLE_REGEXP, maxAttempts = 1), maxAttempts = 7)

def processSelectPath(app, titleRegexp, path, maxAttempts = 7):
  window = connectToWindow(app, titleRegexp, maxAttempts = maxAttempts)
  window.Edit.SetText(path)
  makeOp(lambda: window.Open.CloseClick(), lambda: not isWindowPresent(app, titleRegexp, maxAttempts = 1), maxAttempts = maxAttempts)

def findColumnPosition(columnName, listView):
  return filter(lambda x: x.get('text').upper() == columnName.upper(), listView.Columns())[0].get('order')

def findColumnOffset(columnName, listView):
  pos = findColumnPosition(columnName, listView)
  return reduce(lambda x,y: x+y.get('width'), filter(lambda x: x.get('order')<pos, listView.Columns()), 0) + filter(lambda x: x.get('order')==pos, listView.Columns())[0].get('width') / 2

def main():      
  # Connecting
  app = None
  while app is None:  
      app = connectToApplication(APP_TITLE_REGEXP)
  mainWindow = connectToWindow(app, APP_TITLE_REGEXP)
  # Closing window that has been opened by Security Manager
  while app.top_window_() in [None, mainWindow]:
      app = app
  try:
      app.top_window_().Close()
  except:
      app = app
  # Setting base 
  changeBASE(app, mainWindow)
  # Filtering list, to be sure that our table will be first
  # in list view (to escape situations when there are a lot of
  # tables, and the one we are searching for is placed at non-visible
  # part of screen).
  def applyFilter():
    mainWindow.MenuItem('View->Filter table selection').Click()
    return connectToWindow(app, FILTER_TABLES_REGEXP)
  filterWindow = makeOp(applyFilter)
  filterWindow.Edit.SetText(TABLE_NAME)  
  makeOp(lambda: filterWindow.ApplyFilter.CloseClick(), lambda: not isWindowPresent(app, FILTER_TABLES_REGEXP, maxAttempts = 1), maxAttempts = 7)
  # Testing that there is such a table.
  if (mainWindow.ListView.ItemCount() < 1) or ((mainWindow.ListView.GetItem(0)['text'].upper() != TABLE_NAME) and (mainWindow.ListView.GetItem(0)['text'].upper() != TABLE_NAME+'_ENC')):
    raise RuntimeError('No such table')
  # Setting right trim flag to correct value.
  setRightTrimFlag(app, mainWindow)
  # Now we should click it.
  # Firstly we are getting its coordinates.
  # It has index of 0 because of filtering.
  coord = mainWindow.ListView.GetItemRect(0)
  mainWindow.ListView.Click(coords = ((coord.left+coord.right)/2, (coord.top+coord.bottom)/2))
  # Now let's find offset of data element column
  dataElemPosition = findColumnPosition('Data Element', mainWindow.ListView2)
  dataElemOffset = findColumnOffset('Data Element', mainWindow.ListView2)
  # For future purposes let's find in which column dbColumn name is placed.
  columnNamePosition = findColumnPosition('Column', mainWindow.ListView2)
  # Now for each column that exists, let's set encryption.
  for i in range(mainWindow.ListView2.ItemCount()):
    tempKey = mainWindow.ListView2.GetItem(i, columnNamePosition)['text'].upper()
    # If that encryption is already set then we shouldn't try to re-set it, cause pywinauto can fail.
    columnEncryption = TABLE_DATA[tempKey][ENC_KEY]
    if columnEncryption == mainWindow.ListView2.GetItem(i, dataElemPosition)['text']:
      TABLE_DATA[tempKey].pop(ENC_KEY)
      # If there is no encryption, then setting of no-encryption-value has no sense.
      if (columnEncryption == '') or (len(TABLE_DATA[tempKey]) == 0):
        TABLE_DATA.pop(tempKey)
      continue
    coord = mainWindow.ListView2.GetItemRect(i)
    mainWindow.ListView2.Click(coords = (coord.left + dataElemOffset, (coord.top + coord.bottom)/2))
    # Checking if "information" window has appeared.
    baseSleep()
    if isWindowPresent(app, "(?i).*information.*", maxAttempts = 5):
      toList("raise IndexError()")
    # Processing no data element, and no security coordinates.
    openWindowRegexp = "(?i).*open.*"
    
    baseSleep()
    noDataElemRegexp = "(?i).*no.*data.*"
    if (isWindowPresent(app, noDataElemRegexp, maxAttempts = 5)):
      makeOp(lambda: connectToWindow(app, noDataElemRegexp, maxAttempts = 1).Yes.CloseClick(), lambda: not isWindowPresent(app, noDataElemRegexp), maxAttempts = 7)
      openDialog = connectToWindow(app, openWindowRegexp)
      openDialog.Edit.SetText(PATH_TO_DATA_ELEMENTS)
      makeOp(lambda: openDialog.Open.CloseClick(), lambda: not isWindowPresent(app, openWindowRegexp), maxAttempts = 7)
    #
    baseSleep()
    noSecurityCoordRegexp = "(?i).*no.*security.*coordinates.*"
    if (isWindowPresent(app, noSecurityCoordRegexp, maxAttempts = 5)):
      makeOp(lambda: connectToWindow(app, noSecurityCoordRegexp, maxAttempts = 1).Yes.CloseClick(), lambda: not isWindowPresent(app, noSecurityCoordRegexp), maxAttempts = 7)
      openDialog = connectToWindow(app, openWindowRegexp)
      openDialog.Edit.SetText(PATH_TO_SECURITY_COORDINATES)
      makeOp(lambda: openDialog.Open.CloseClick(), lambda: not isWindowPresent(app, openWindowRegexp, maxAttempts = 1), maxAttempts = 7)
    for item in mainWindow.ComboBox.ItemTexts():
      if item.upper() == columnEncryption.upper():
        columnEncryption = item
        break
    mainWindow.ComboBox.Select(columnEncryption)

    baseSleep()
    errorTitleRegexp = "(?i).*error.*"
    warningTitleRegexp = "(?i).*warning.*"
    while (isWindowPresent(app, errorTitleRegexp, maxAttempts = 1) or isWindowPresent(app, warningTitleRegexp, maxAttempts = 1)):
      try:
        makeOp(lambda: connectToWindow(app, errorTitleRegexp, maxAttempts = 1).Yes.Click(), lambda: not isWindowPresent(app, errorTitleRegexp, maxAttempts = 1), maxAttempts = 1)
      except:
        pass
      try:
        makeOp(lambda: connectToWindow(app, warningTitleRegexp, maxAttempts = 1).Ok.Click(), lambda: not isWindowPresent(app, warningTitleRegexp, maxAttempts = 1), maxAttempts = 1)
      except:
        pass
      baseSleep()
    if (DATABASE_TYPE == 1): # DB2 specific
      baseSleep()
      if isWindowPresent(app, '(?i).*information.*', maxAttempts = 5):
        raise RuntimeError('Seems like table contains some triggers.')
    TABLE_DATA[tempKey].pop(ENC_KEY)
    if len(TABLE_DATA[tempKey]) == 0:
      TABLE_DATA.pop(tempKey)
  # Setting no access values.
  NO_ACCESS_TITLE_REGEXP = "(?i)no.*access.*value"
  coord = mainWindow.ListView2.GetItemRect(0)
  mainWindow.ListView2.ClickInput(coords=(coord.left, coord.top), button='right')
  baseSleep()
  app.Popup.MenuItem('Set No Access Value').Click()
  noAccessValuesWindow = connectToWindow(app, NO_ACCESS_TITLE_REGEXP)
  navOffset = findColumnOffset("No Access Value", noAccessValuesWindow.ListView)
  columnPos = findColumnPosition("Columns", noAccessValuesWindow.ListView)
  for i in range(noAccessValuesWindow.ListView.ItemCount()):
    tempKey = noAccessValuesWindow.ListView.GetItem(i, columnPos)['text'].upper()
    if TABLE_DATA.has_key(tempKey):
      if TABLE_DATA[tempKey].has_key(NAV_KEY):
        nav = base64.b64decode(TABLE_DATA[tempKey][NAV_KEY])
        coord = noAccessValuesWindow.ListView.GetItemRect(i)
        noAccessValuesWindow.ListView.ClickInput(coords = (coord.left + navOffset, (coord.top + coord.bottom)/2))
        baseSleep()
        if isWindowPresent(app, "(?i).*warning.*", maxAttempts = 3):
          raise RuntimeError('You are trying to set a no access value to the column, which is either without data element or is nullable.')
        noAccessValuesWindow.Edit.SetText(nav)
        noAccessValuesWindow.Edit.TypeKeys('{ENTER}')
        baseSleep()
        if isWindowPresent(app, "(?i).*error.*", maxAttempts = 3):
          raise RuntimeError('You are trying to set an illegal no access value to a column.')
        TABLE_DATA[tempKey].pop(NAV_KEY)
        if len(TABLE_DATA[tempKey]) == 0:
          TABLE_DATA.pop(tempKey)
  makeOp(lambda: noAccessValuesWindow.OK.ClickInput(), lambda: not isWindowPresent(app, NO_ACCESS_TITLE_REGEXP, maxAttempts = 1), maxAttempts = 7)
  if len(TABLE_DATA) > 0:
    raise RuntimeError('Not all columns were processed: ' + str(TABLE_DATA))
  mainWindow.TabControl.Select('Script')
  baseSleep()
  try:
    makeOp(lambda: connectToWindow(app, "(?i).*warning.*", maxAttempts = 1).Ok.Click(), lambda: not isWindowPresent(app, "(?i).*warning.*", maxAttempts = 1), maxAttempts = 5)
  except:
    baseSleep() # Just to do something
  print mainWindow.Edit.TextBlock()
  closeApplication(APP_TITLE_REGEXP)     
main()


Max Nanis

unread,
Apr 26, 2013, 8:33:43 PM4/26/13
to crow...@googlegroups.com
Hi Arsenii -- could you put this in a gist so we can read it with syntax highlighting?

Thanks,
M

Бочечко Арсений

unread,
Apr 27, 2013, 3:04:41 AM4/27/13
to crow...@googlegroups.com, crow...@googlegroups.com
Sure, I'll try to do it today, if I get my hands on the internet


--- пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ ---
пїЅпїЅ пїЅпїЅпїЅпїЅ: "Max Nanis" <x0xma...@gmail.com>
пїЅпїЅпїЅпїЅ: 27 пїЅпїЅпїЅпїЅпїЅпїЅ 2013, 04:33:48



>
> Hi Arsenii -- could you put this in a gist so we can read it with syntax highlighting?
>
>
> Thanks,
> M
>
> On Friday, April 26, 2013 5:14:07 AM UTC-7, Arsenii Bochechko wrote:I've submitted a proposal for this idea, and think of myself as capable of doing it, and as a proof that I have a knowledge of python - here is part of the python code, I've used for automating user interface clicks



def setRightTrimFlag(app, mainWindow):
пїЅ makeOp(lambda: mainWindow.MenuItem('View->Options').Click(), lambda: isWindowPresent(app, OPTIONS_TITLE_REGEXP, maxAttempts = 1), maxAttempts = 7)
пїЅ optionsWindow = connectToWindow(app, OPTIONS_TITLE_REGEXP)
пїЅ checkBox = None
пїЅ if DATABASE_TYPE == 2:
пїЅ пїЅ checkBox = optionsWindow.CheckBox2
пїЅ else:
пїЅ пїЅ checkBox = optionsWindow.CheckBox3
пїЅ if RIGHT_TRIM == True:
пїЅ пїЅ checkBox.Check()
пїЅ else:
пїЅ пїЅ checkBox.UnCheck()
пїЅ makeOp(lambda: optionsWindow.OK.CloseClick(), lambda: not isWindowPresent(app, OPTIONS_TITLE_REGEXP, maxAttempts = 1), maxAttempts = 7)


def processSelectPath(app, titleRegexp, path, maxAttempts = 7):
пїЅ window = connectToWindow(app, titleRegexp, maxAttempts = maxAttempts)
пїЅ window.Edit.SetText(path)
пїЅ makeOp(lambda: window.Open.CloseClick(), lambda: not isWindowPresent(app, titleRegexp, maxAttempts = 1), maxAttempts = maxAttempts)


def findColumnPosition(columnName, listView):
пїЅ return filter(lambda x: x.get('text').upper() == columnName.upper(), listView.Columns())[0].get('order')


def findColumnOffset(columnName, listView):
пїЅ pos = findColumnPosition(columnName, listView)
пїЅ return reduce(lambda x,y: x+y.get('width'), filter(lambda x: x.get('order')<pos, listView.Columns()), 0) + filter(lambda x: x.get('order')==pos, listView.Columns())[0].get('width') / 2


def main(): пїЅ пїЅ пїЅ
пїЅ # Connecting
пїЅ app = None
пїЅ while app is None: пїЅ
пїЅ пїЅ пїЅ app = connectToApplication(APP_TITLE_REGEXP)
пїЅ mainWindow = connectToWindow(app, APP_TITLE_REGEXP)
пїЅ # Closing window that has been opened by Security Manager
пїЅ while app.top_window_() in [None, mainWindow]:
пїЅ пїЅ пїЅ app = app
пїЅ try:
пїЅ пїЅ пїЅ app.top_window_().Close()
пїЅ except:
пїЅ пїЅ пїЅ app = app
пїЅ # Setting baseпїЅ
пїЅ changeBASE(app, mainWindow)
пїЅ # Filtering list, to be sure that our table will be first
пїЅ # in list view (to escape situations when there are a lot of
пїЅ # tables, and the one we are searching for is placed at non-visible
пїЅ # part of screen).
пїЅ def applyFilter():
пїЅ пїЅ mainWindow.MenuItem('View->Filter table selection').Click()
пїЅ пїЅ return connectToWindow(app, FILTER_TABLES_REGEXP)
пїЅ filterWindow = makeOp(applyFilter)
пїЅ filterWindow.Edit.SetText(TABLE_NAME) пїЅ
пїЅ makeOp(lambda: filterWindow.ApplyFilter.CloseClick(), lambda: not isWindowPresent(app, FILTER_TABLES_REGEXP, maxAttempts = 1), maxAttempts = 7)
пїЅ # Testing that there is such a table.
пїЅ if (mainWindow.ListView.ItemCount() < 1) or ((mainWindow.ListView.GetItem(0)['text'].upper() != TABLE_NAME) and (mainWindow.ListView.GetItem(0)['text'].upper() != TABLE_NAME+'_ENC')):
пїЅ пїЅ raise RuntimeError('No such table')
пїЅ # Setting right trim flag to correct value.
пїЅ setRightTrimFlag(app, mainWindow)
пїЅ # Now we should click it.
пїЅ # Firstly we are getting its coordinates.
пїЅ # It has index of 0 because of filtering.
пїЅ coord = mainWindow.ListView.GetItemRect(0)
пїЅ mainWindow.ListView.Click(coords = ((coord.left+coord.right)/2, (coord.top+coord.bottom)/2))
пїЅ # Now let's find offset of data element column
пїЅ dataElemPosition = findColumnPosition('Data Element', mainWindow.ListView2)
пїЅ dataElemOffset = findColumnOffset('Data Element', mainWindow.ListView2)
пїЅ # For future purposes let's find in which column dbColumn name is placed.
пїЅ columnNamePosition = findColumnPosition('Column', mainWindow.ListView2)
пїЅ # Now for each column that exists, let's set encryption.
пїЅ for i in range(mainWindow.ListView2.ItemCount()):
пїЅ пїЅ tempKey = mainWindow.ListView2.GetItem(i, columnNamePosition)['text'].upper()
пїЅ пїЅ # If that encryption is already set then we shouldn't try to re-set it, cause pywinauto can fail.
пїЅ пїЅ columnEncryption = TABLE_DATA[tempKey][ENC_KEY]
пїЅ пїЅ if columnEncryption == mainWindow.ListView2.GetItem(i, dataElemPosition)['text']:
пїЅ пїЅ пїЅ TABLE_DATA[tempKey].pop(ENC_KEY)
пїЅ пїЅ пїЅ # If there is no encryption, then setting of no-encryption-value has no sense.
пїЅ пїЅ пїЅ if (columnEncryption == '') or (len(TABLE_DATA[tempKey]) == 0):
пїЅ пїЅ пїЅ пїЅ TABLE_DATA.pop(tempKey)
пїЅ пїЅ пїЅ continue
пїЅ пїЅ coord = mainWindow.ListView2.GetItemRect(i)
пїЅ пїЅ mainWindow.ListView2.Click(coords = (coord.left + dataElemOffset, (coord.top + coord.bottom)/2))
пїЅ пїЅ # Checking if "information" window has appeared.
пїЅ пїЅ baseSleep()
пїЅ пїЅ if isWindowPresent(app, "(?i).*information.*", maxAttempts = 5):
пїЅ пїЅ пїЅ toList("raise IndexError()")
пїЅ пїЅ # Processing no data element, and no security coordinates.
пїЅ пїЅ openWindowRegexp = "(?i).*open.*"
пїЅ пїЅпїЅ
пїЅ пїЅ baseSleep()
пїЅ пїЅ noDataElemRegexp = "(?i).*no.*data.*"
пїЅ пїЅ if (isWindowPresent(app, noDataElemRegexp, maxAttempts = 5)):
пїЅ пїЅ пїЅ makeOp(lambda: connectToWindow(app, noDataElemRegexp, maxAttempts = 1).Yes.CloseClick(), lambda: not isWindowPresent(app, noDataElemRegexp), maxAttempts = 7)
пїЅ пїЅ пїЅ openDialog = connectToWindow(app, openWindowRegexp)
пїЅ пїЅ пїЅ openDialog.Edit.SetText(PATH_TO_DATA_ELEMENTS)
пїЅ пїЅ пїЅ makeOp(lambda: openDialog.Open.CloseClick(), lambda: not isWindowPresent(app, openWindowRegexp), maxAttempts = 7)
пїЅ пїЅ #
пїЅ пїЅ baseSleep()
пїЅ пїЅ noSecurityCoordRegexp = "(?i).*no.*security.*coordinates.*"
пїЅ пїЅ if (isWindowPresent(app, noSecurityCoordRegexp, maxAttempts = 5)):
пїЅ пїЅ пїЅ makeOp(lambda: connectToWindow(app, noSecurityCoordRegexp, maxAttempts = 1).Yes.CloseClick(), lambda: not isWindowPresent(app, noSecurityCoordRegexp), maxAttempts = 7)
пїЅ пїЅ пїЅ openDialog = connectToWindow(app, openWindowRegexp)
пїЅ пїЅ пїЅ openDialog.Edit.SetText(PATH_TO_SECURITY_COORDINATES)
пїЅ пїЅ пїЅ makeOp(lambda: openDialog.Open.CloseClick(), lambda: not isWindowPresent(app, openWindowRegexp, maxAttempts = 1), maxAttempts = 7)
пїЅ пїЅ for item in mainWindow.ComboBox.ItemTexts():
пїЅ пїЅ пїЅ if item.upper() == columnEncryption.upper():
пїЅ пїЅ пїЅ пїЅ columnEncryption = item
пїЅ пїЅ пїЅ пїЅ break
пїЅ пїЅ mainWindow.ComboBox.Select(columnEncryption)


пїЅ пїЅ baseSleep()
пїЅ пїЅ errorTitleRegexp = "(?i).*error.*"
пїЅ пїЅ warningTitleRegexp = "(?i).*warning.*"
пїЅ пїЅ while (isWindowPresent(app, errorTitleRegexp, maxAttempts = 1) or isWindowPresent(app, warningTitleRegexp, maxAttempts = 1)):
пїЅ пїЅ пїЅ try:
пїЅ пїЅ пїЅ пїЅ makeOp(lambda: connectToWindow(app, errorTitleRegexp, maxAttempts = 1).Yes.Click(), lambda: not isWindowPresent(app, errorTitleRegexp, maxAttempts = 1), maxAttempts = 1)
пїЅ пїЅ пїЅ except:
пїЅ пїЅ пїЅ пїЅ pass
пїЅ пїЅ пїЅ try:
пїЅ пїЅ пїЅ пїЅ makeOp(lambda: connectToWindow(app, warningTitleRegexp, maxAttempts = 1).Ok.Click(), lambda: not isWindowPresent(app, warningTitleRegexp, maxAttempts = 1), maxAttempts = 1)
пїЅ пїЅ пїЅ except:
пїЅ пїЅ пїЅ пїЅ pass
пїЅ пїЅ пїЅ baseSleep()
пїЅ пїЅ if (DATABASE_TYPE == 1): # DB2 specific
пїЅ пїЅ пїЅ baseSleep()
пїЅ пїЅ пїЅ if isWindowPresent(app, '(?i).*information.*', maxAttempts = 5):
пїЅ пїЅ пїЅ пїЅ raise RuntimeError('Seems like table contains some triggers.')
пїЅ пїЅ TABLE_DATA[tempKey].pop(ENC_KEY)
пїЅ пїЅ if len(TABLE_DATA[tempKey]) == 0:
пїЅ пїЅ пїЅ TABLE_DATA.pop(tempKey)
пїЅ # Setting no access values.
пїЅ NO_ACCESS_TITLE_REGEXP = "(?i)no.*access.*value"
пїЅ coord = mainWindow.ListView2.GetItemRect(0)
пїЅ mainWindow.ListView2.ClickInput(coords=(coord.left, coord.top), button='right')
пїЅ baseSleep()
пїЅ app.Popup.MenuItem('Set No Access Value').Click()
пїЅ noAccessValuesWindow = connectToWindow(app, NO_ACCESS_TITLE_REGEXP)
пїЅ navOffset = findColumnOffset("No Access Value", noAccessValuesWindow.ListView)
пїЅ columnPos = findColumnPosition("Columns", noAccessValuesWindow.ListView)
пїЅ for i in range(noAccessValuesWindow.ListView.ItemCount()):
пїЅ пїЅ tempKey = noAccessValuesWindow.ListView.GetItem(i, columnPos)['text'].upper()
пїЅ пїЅ if TABLE_DATA.has_key(tempKey):
пїЅ пїЅ пїЅ if TABLE_DATA[tempKey].has_key(NAV_KEY):
пїЅ пїЅ пїЅ пїЅ nav = base64.b64decode(TABLE_DATA[tempKey][NAV_KEY])
пїЅ пїЅ пїЅ пїЅ coord = noAccessValuesWindow.ListView.GetItemRect(i)
пїЅ пїЅ пїЅ пїЅ noAccessValuesWindow.ListView.ClickInput(coords = (coord.left + navOffset, (coord.top + coord.bottom)/2))
пїЅ пїЅ пїЅ пїЅ baseSleep()
пїЅ пїЅ пїЅ пїЅ if isWindowPresent(app, "(?i).*warning.*", maxAttempts = 3):
пїЅ пїЅ пїЅ пїЅ пїЅ raise RuntimeError('You are trying to set a no access value to the column, which is either without data element or is nullable.')
пїЅ пїЅ пїЅ пїЅ noAccessValuesWindow.Edit.SetText(nav)
пїЅ пїЅ пїЅ пїЅ noAccessValuesWindow.Edit.TypeKeys('{ENTER}')
пїЅ пїЅ пїЅ пїЅ baseSleep()
пїЅ пїЅ пїЅ пїЅ if isWindowPresent(app, "(?i).*error.*", maxAttempts = 3):
пїЅ пїЅ пїЅ пїЅ пїЅ raise RuntimeError('You are trying to set an illegal no access value to a column.')
пїЅ пїЅ пїЅ пїЅ TABLE_DATA[tempKey].pop(NAV_KEY)
пїЅ пїЅ пїЅ пїЅ if len(TABLE_DATA[tempKey]) == 0:
пїЅ пїЅ пїЅ пїЅ пїЅ TABLE_DATA.pop(tempKey)
пїЅ makeOp(lambda: noAccessValuesWindow.OK.ClickInput(), lambda: not isWindowPresent(app, NO_ACCESS_TITLE_REGEXP, maxAttempts = 1), maxAttempts = 7)
пїЅ if len(TABLE_DATA) > 0:
пїЅ пїЅ raise RuntimeError('Not all columns were processed: ' + str(TABLE_DATA))
пїЅ mainWindow.TabControl.Select('Script')
пїЅ baseSleep()
пїЅ try:
пїЅ пїЅ makeOp(lambda: connectToWindow(app, "(?i).*warning.*", maxAttempts = 1).Ok.Click(), lambda: not isWindowPresent(app, "(?i).*warning.*", maxAttempts = 1), maxAttempts = 5)
пїЅ except:
пїЅ пїЅ baseSleep() # Just to do something
пїЅ print mainWindow.Edit.TextBlock()
пїЅ closeApplication(APP_TITLE_REGEXP) пїЅ пїЅпїЅ
main()





>
> --
> --
> You received this message because you are subscribed to the Google
> Groups "Crowdsourcing Biology" group.
> To post to this group, send email to crow...@googlegroups.com
> To unsubscribe from this group, send email to
> crowdbio+u...@googlegroups.com
> For more options, visit this group at
> http://groups.google.com/group/crowdbio?hl=en?hl=en
>
> 2012 GSoC Organization page: http://www.google-melange.com/gsoc/org/google/gsoc2012/scripps_crowdbio
> GSoC Ideas page: http://sulab.org/gsoc/
> ---
> You received this message because you are subscribed to a topic in the Google Groups "Crowdsourcing Biology" group.
> To unsubscribe from this topic, visit https://groups.google.com/d/topic/crowdbio/zkrRDZIIWVs/unsubscribe?hl=en.
> To unsubscribe from this group and all its topics, send an email to crowdbio+u...@googlegroups.com.
> To post to this group, send email to crow...@googlegroups.com.
> Visit this group at http://groups.google.com/group/crowdbio?hl=en.
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>

Бочечко Арсений

unread,
Apr 27, 2013, 7:00:03 AM4/27/13
to crow...@googlegroups.com, crow...@googlegroups.com
Here is the gist link, sorry for small amount of summary, it's hard to type from the phone
https://gist.github.com/Slua/5472591
--- пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ ---
пїЅпїЅ пїЅпїЅпїЅпїЅ: "пїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅ" <sl...@ukr.net>
пїЅпїЅпїЅпїЅ: 27 пїЅпїЅпїЅпїЅпїЅпїЅ 2013, 11:04:44



> Sure, I'll try to do it today, if I get my hands on the internet
>
>
> --- пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ пїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅпїЅ ---
> пїЅпїЅ пїЅпїЅпїЅпїЅ: "Max Nanis" <x0xma...@gmail.com>
> пїЅпїЅпїЅпїЅ: 27 пїЅпїЅпїЅпїЅпїЅпїЅ 2013, 04:33:48
>
>
>
> >
> > Hi Arsenii -- could you put this in a gist so we can read it with syntax highlighting?
> >
> >
> > Thanks,
> > M
> >
> > On Friday, April 26, 2013 5:14:07 AM UTC-7, Arsenii Bochechko wrote:I've submitted a proposal for this idea, and think of myself as capable of doing it, and as a proof that I have a knowledge of python - here is part of the python code, I've used for automating user interface clicks
>
>
>
> def setRightTrimFlag(app, mainWindow):
> makeOp(lambda: mainWindow.MenuItem('View->Options').Click(), lambda: isWindowPresent(app, OPTIONS_TITLE_REGEXP, maxAttempts = 1), maxAttempts = 7)
> optionsWindow = connectToWindow(app, OPTIONS_TITLE_REGEXP)
> checkBox = None
> if DATABASE_TYPE == 2:
> checkBox = optionsWindow.CheckBox2
> else:
> checkBox = optionsWindow.CheckBox3
> if RIGHT_TRIM == True:
> checkBox.Check()
> else:
> checkBox.UnCheck()
> makeOp(lambda: optionsWindow.OK.CloseClick(), lambda: not isWindowPresent(app, OPTIONS_TITLE_REGEXP, maxAttempts = 1), maxAttempts = 7)
>
>
> def processSelectPath(app, titleRegexp, path, maxAttempts = 7):
> window = connectToWindow(app, titleRegexp, maxAttempts = maxAttempts)
> window.Edit.SetText(path)
> makeOp(lambda: window.Open.CloseClick(), lambda: not isWindowPresent(app, titleRegexp, maxAttempts = 1), maxAttempts = maxAttempts)
>
>
> def findColumnPosition(columnName, listView):
> return filter(lambda x: x.get('text').upper() == columnName.upper(), listView.Columns())[0].get('order')
>
>
> def findColumnOffset(columnName, listView):
> pos = findColumnPosition(columnName, listView)
> return reduce(lambda x,y: x+y.get('width'), filter(lambda x: x.get('order')<pos, listView.Columns()), 0) + filter(lambda x: x.get('order')==pos, listView.Columns())[0].get('width') / 2
>
>
> def main():
> # Connecting
> app = None
> while app is None:
> app = connectToApplication(APP_TITLE_REGEXP)
> mainWindow = connectToWindow(app, APP_TITLE_REGEXP)
> # Closing window that has been opened by Security Manager
> while app.top_window_() in [None, mainWindow]:
> app = app
> try:
> app.top_window_().Close()
> except:
> app = app
> # Setting base
> changeBASE(app, mainWindow)
> # Filtering list, to be sure that our table will be first
> # in list view (to escape situations when there are a lot of
> # tables, and the one we are searching for is placed at non-visible
> # part of screen).
> def applyFilter():
> mainWindow.MenuItem('View->Filter table selection').Click()
> return connectToWindow(app, FILTER_TABLES_REGEXP)
> filterWindow = makeOp(applyFilter)
> filterWindow.Edit.SetText(TABLE_NAME)
> makeOp(lambda: filterWindow.ApplyFilter.CloseClick(), lambda: not isWindowPresent(app, FILTER_TABLES_REGEXP, maxAttempts = 1), maxAttempts = 7)
> # Testing that there is such a table.
> if (mainWindow.ListView.ItemCount() < 1) or ((mainWindow.ListView.GetItem(0)['text'].upper() != TABLE_NAME) and (mainWindow.ListView.GetItem(0)['text'].upper() != TABLE_NAME+'_ENC')):
> raise RuntimeError('No such table')
> # Setting right trim flag to correct value.
> setRightTrimFlag(app, mainWindow)
> # Now we should click it.
> # Firstly we are getting its coordinates.
> # It has index of 0 because of filtering.
> coord = mainWindow.ListView.GetItemRect(0)
> mainWindow.ListView.Click(coords = ((coord.left+coord.right)/2, (coord.top+coord.bottom)/2))
> # Now let's find offset of data element column
> dataElemPosition = findColumnPosition('Data Element', mainWindow.ListView2)
> dataElemOffset = findColumnOffset('Data Element', mainWindow.ListView2)
> # For future purposes let's find in which column dbColumn name is placed.
> columnNamePosition = findColumnPosition('Column', mainWindow.ListView2)
> # Now for each column that exists, let's set encryption.
> for i in range(mainWindow.ListView2.ItemCount()):
> tempKey = mainWindow.ListView2.GetItem(i, columnNamePosition)['text'].upper()
> # If that encryption is already set then we shouldn't try to re-set it, cause pywinauto can fail.
> columnEncryption = TABLE_DATA[tempKey][ENC_KEY]
> if columnEncryption == mainWindow.ListView2.GetItem(i, dataElemPosition)['text']:
> TABLE_DATA[tempKey].pop(ENC_KEY)
> # If there is no encryption, then setting of no-encryption-value has no sense.
> if (columnEncryption == '') or (len(TABLE_DATA[tempKey]) == 0):
> TABLE_DATA.pop(tempKey)
> continue
> coord = mainWindow.ListView2.GetItemRect(i)
> mainWindow.ListView2.Click(coords = (coord.left + dataElemOffset, (coord.top + coord.bottom)/2))
> # Checking if "information" window has appeared.
> baseSleep()
> if isWindowPresent(app, "(?i).*information.*", maxAttempts = 5):
> toList("raise IndexError()")
> # Processing no data element, and no security coordinates.
> openWindowRegexp = "(?i).*open.*"
>
> baseSleep()
> noDataElemRegexp = "(?i).*no.*data.*"
> if (isWindowPresent(app, noDataElemRegexp, maxAttempts = 5)):
> makeOp(lambda: connectToWindow(app, noDataElemRegexp, maxAttempts = 1).Yes.CloseClick(), lambda: not isWindowPresent(app, noDataElemRegexp), maxAttempts = 7)
> openDialog = connectToWindow(app, openWindowRegexp)
> openDialog.Edit.SetText(PATH_TO_DATA_ELEMENTS)
> makeOp(lambda: openDialog.Open.CloseClick(), lambda: not isWindowPresent(app, openWindowRegexp), maxAttempts = 7)
> #
> baseSleep()
> noSecurityCoordRegexp = "(?i).*no.*security.*coordinates.*"
> if (isWindowPresent(app, noSecurityCoordRegexp, maxAttempts = 5)):
> makeOp(lambda: connectToWindow(app, noSecurityCoordRegexp, maxAttempts = 1).Yes.CloseClick(), lambda: not isWindowPresent(app, noSecurityCoordRegexp), maxAttempts = 7)
> openDialog = connectToWindow(app, openWindowRegexp)
> openDialog.Edit.SetText(PATH_TO_SECURITY_COORDINATES)
> makeOp(lambda: openDialog.Open.CloseClick(), lambda: not isWindowPresent(app, openWindowRegexp, maxAttempts = 1), maxAttempts = 7)
> for item in mainWindow.ComboBox.ItemTexts():
> if item.upper() == columnEncryption.upper():
> columnEncryption = item
> break
> mainWindow.ComboBox.Select(columnEncryption)
>
>
> baseSleep()
> errorTitleRegexp = "(?i).*error.*"
> warningTitleRegexp = "(?i).*warning.*"
> while (isWindowPresent(app, errorTitleRegexp, maxAttempts = 1) or isWindowPresent(app, warningTitleRegexp, maxAttempts = 1)):
> try:
> makeOp(lambda: connectToWindow(app, errorTitleRegexp, maxAttempts = 1).Yes.Click(), lambda: not isWindowPresent(app, errorTitleRegexp, maxAttempts = 1), maxAttempts = 1)
> except:
> pass
> try:
> makeOp(lambda: connectToWindow(app, warningTitleRegexp, maxAttempts = 1).Ok.Click(), lambda: not isWindowPresent(app, warningTitleRegexp, maxAttempts = 1), maxAttempts = 1)
> except:
> pass
> baseSleep()
> if (DATABASE_TYPE == 1): # DB2 specific
> baseSleep()
> if isWindowPresent(app, '(?i).*information.*', maxAttempts = 5):
> raise RuntimeError('Seems like table contains some triggers.')
> TABLE_DATA[tempKey].pop(ENC_KEY)
> if len(TABLE_DATA[tempKey]) == 0:
> TABLE_DATA.pop(tempKey)
> # Setting no access values.
> NO_ACCESS_TITLE_REGEXP = "(?i)no.*access.*value"
> coord = mainWindow.ListView2.GetItemRect(0)
> mainWindow.ListView2.ClickInput(coords=(coord.left, coord.top), button='right')
> baseSleep()
> app.Popup.MenuItem('Set No Access Value').Click()
> noAccessValuesWindow = connectToWindow(app, NO_ACCESS_TITLE_REGEXP)
> navOffset = findColumnOffset("No Access Value", noAccessValuesWindow.ListView)
> columnPos = findColumnPosition("Columns", noAccessValuesWindow.ListView)
> for i in range(noAccessValuesWindow.ListView.ItemCount()):
> tempKey = noAccessValuesWindow.ListView.GetItem(i, columnPos)['text'].upper()
> if TABLE_DATA.has_key(tempKey):
> if TABLE_DATA[tempKey].has_key(NAV_KEY):
> nav = base64.b64decode(TABLE_DATA[tempKey][NAV_KEY])
> coord = noAccessValuesWindow.ListView.GetItemRect(i)
> noAccessValuesWindow.ListView.ClickInput(coords = (coord.left + navOffset, (coord.top + coord.bottom)/2))
> baseSleep()
> if isWindowPresent(app, "(?i).*warning.*", maxAttempts = 3):
> raise RuntimeError('You are trying to set a no access value to the column, which is either without data element or is nullable.')
> noAccessValuesWindow.Edit.SetText(nav)
> noAccessValuesWindow.Edit.TypeKeys('{ENTER}')
> baseSleep()
> if isWindowPresent(app, "(?i).*error.*", maxAttempts = 3):
> raise RuntimeError('You are trying to set an illegal no access value to a column.')
> TABLE_DATA[tempKey].pop(NAV_KEY)
> if len(TABLE_DATA[tempKey]) == 0:
> TABLE_DATA.pop(tempKey)
> makeOp(lambda: noAccessValuesWindow.OK.ClickInput(), lambda: not isWindowPresent(app, NO_ACCESS_TITLE_REGEXP, maxAttempts = 1), maxAttempts = 7)
> if len(TABLE_DATA) > 0:
> raise RuntimeError('Not all columns were processed: ' + str(TABLE_DATA))
> mainWindow.TabControl.Select('Script')
> baseSleep()
> try:
> makeOp(lambda: connectToWindow(app, "(?i).*warning.*", maxAttempts = 1).Ok.Click(), lambda: not isWindowPresent(app, "(?i).*warning.*", maxAttempts = 1), maxAttempts = 5)
> except:
> baseSleep() # Just to do something
> print mainWindow.Edit.TextBlock()
> closeApplication(APP_TITLE_REGEXP)
Reply all
Reply to author
Forward
0 new messages