{"action":"created","comment":{"url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/comments/89810266","pull_request_review_id":10344031,"id":89810266,"diff_hunk":"@@ -1525,3 +1521,94 @@ def __addDirectory( self, path, force ):\n       else:\n         successful.append( lfn )\n     return {\"OK\":True, \"Value\": len( res['Value']['Successful'] ), \"Successful\":successful, \"Failed\": failed }\n+\n+  def setMetadata( self, path, usermetadatadict ):\n+    \"\"\" It can be applied to a file or to a directory (path). For a file, add the file to Transformations if the updated metadata dictionary passes the filter.\n+        For a directory, add the files contained in the directory to the Transformations if the the updated metadata dictionary passes the filter.\n+    \"\"\"\n+    gLogger.info( \"setMetadata: Attempting to set metadata %s to %s\" % (usermetadatadict, path) )\n+    successful = {}\n+    failed = {}\n+    if isinstance( path, dict ):\n+      path = path.keys()[0]\n+\n+    transFiles = {}\n+    filesToAdd = []\n+\n+    catalog = FileCatalog()\n+    isFile = catalog.isFile( path )['Value']['Successful'][path]\n+    isDirectory = catalog.isDirectory( path )['Value']['Successful'][path]\n+\n+    if isFile:\n+      res = catalog.getFileUserMetadata( path )\n+    elif isDirectory:\n+      res = catalog.getDirectoryUserMetadata( path )\n+\n+    if not res['OK']:\n+      failed[path] = res['Message']\n+      return S_OK( {'Successful':successful, 'Failed':failed } )\n+    else:\n+      metadatadict = res['Value']\n+    metadatadict.update( usermetadatadict )\n+    gLogger.info( 'Filter file with metadata:', metadatadict )\n+    fileTrans = self._filterFileByMetadata( metadatadict )\n+    if not ( fileTrans ):\n+      successful[path] = False\n+    elif isFile:\n+      filesToAdd.append( path )\n+      path = [path]\n+    else:\n+      res = catalog.findFilesByMetadata( metadatadict, path )\n+      path = res['Value']\n+      filesToAdd.extend( res['Value'] )\n+    for trans in fileTrans:\n+      if not transFiles.has_key( trans ):\n+        transFiles[trans] = []\n+      transFiles[trans].extend( path )\n+\n+    # Add the files to the transformations\n+    gLogger.info( 'Files to add to transformations:', filesToAdd )\n+    if filesToAdd:\n+      for transID, lfns in transFiles.items():\n+        res = self.addFilesToTransformation( transID, lfns )\n+        if not res['OK']:\n+          for lfn in lfns:\n+            gLogger.error( \"Failed to add files to transformation\", \"%s %s\" % ( transID, res['Message'] ) )\n+            failed[lfn] = res['Message']\n+        else:\n+          for lfn in lfns:\n+            successful[lfn] = True\n+\n+    res = S_OK( {'Successful':successful, 'Failed':failed } )\n+    return res\n+\n+  def _filterFileByMetadata( self, metadatadict ):\n+    \"\"\"Pass the input metadatadict through those currently active\"\"\"\n+    result = []\n+    queries = self.filters\n+    catalog = FileCatalog()\n+    gLogger.info( 'Filter file by queries', queries )\n+    res = catalog.getMetadataFields()\n+\n+    if not res['OK']:\n+      gLogger.error( \"Error in getMetadataFields: %s\" % res['Message'] )\n+      return res\n+    if not res['Value']:\n+      gLogger.error( \"Error: no metadata fields defined\" )\n+      return res\n+    typeDict = res['Value']['FileMetaFields']\n+    typeDict.update( res['Value']['DirectoryMetaFields'] )\n+\n+    for transID, query in queries:","path":"TransformationSystem/DB/TransformationDB.py","position":295,"original_position":279,"commit_id":"7a51fc1b39a9e4aee0f75b7d83af3656b421f2c5","original_commit_id":"46bd2e9dd65f05fb65bbc9e64d53ed2ceae63598","user":{"login":"arrabito","id":6996265,"avatar_url":"https://avatars.githubusercontent.com/u/6996265?v=3","gravatar_id":"","url":"https://api.github.com/users/arrabito","html_url":"https://github.com/arrabito","followers_url":"https://api.github.com/users/arrabito/followers","following_url":"https://api.github.com/users/arrabito/following{/other_user}","gists_url":"https://api.github.com/users/arrabito/gists{/gist_id}","starred_url":"https://api.github.com/users/arrabito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arrabito/subscriptions","organizations_url":"https://api.github.com/users/arrabito/orgs","repos_url":"https://api.github.com/users/arrabito/repos","events_url":"https://api.github.com/users/arrabito/events{/privacy}","received_events_url":"https://api.github.com/users/arrabito/received_events","type":"User","site_admin":false},"body":"It's a list of tuples","created_at":"2016-11-28T15:54:43Z","updated_at":"2016-11-28T15:54:43Z","html_url":"https://github.com/DIRACGrid/DIRAC/pull/3180#discussion_r89810266","pull_request_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3180","_links":{"self":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/comments/89810266"},"html":{"href":"https://github.com/DIRACGrid/DIRAC/pull/3180#discussion_r89810266"},"pull_request":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3180"}}},"pull_request":{"url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3180","id":94623953,"html_url":"https://github.com/DIRACGrid/DIRAC/pull/3180","diff_url":"https://github.com/DIRACGrid/DIRAC/pull/3180.diff","patch_url":"https://github.com/DIRACGrid/DIRAC/pull/3180.patch","issue_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/3180","number":3180,"state":"open","locked":false,"title":"[WIP] [v6r17] Introduce meta-filters in TS","user":{"login":"arrabito","id":6996265,"avatar_url":"https://avatars.githubusercontent.com/u/6996265?v=3","gravatar_id":"","url":"https://api.github.com/users/arrabito","html_url":"https://github.com/arrabito","followers_url":"https://api.github.com/users/arrabito/followers","following_url":"https://api.github.com/users/arrabito/following{/other_user}","gists_url":"https://api.github.com/users/arrabito/gists{/gist_id}","starred_url":"https://api.github.com/users/arrabito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arrabito/subscriptions","organizations_url":"https://api.github.com/users/arrabito/orgs","repos_url":"https://api.github.com/users/arrabito/repos","events_url":"https://api.github.com/users/arrabito/events{/privacy}","received_events_url":"https://api.github.com/users/arrabito/received_events","type":"User","site_admin":false},"body":"This PR is about the introduction of 'meta-filters' in the TS.\r\nAll the details are explained in the forum:\r\nhttps://groups.google.com/forum/?hl=en#!topic/diracgrid-develop/BAQYOgLNCAI\r\nAs I explained in my last post, even if I already have in mind some improvements on the code, it should be safe to merge it, since the new functionality is optional. Moreover, it has been already successfully tested in the production setup of CTA. Also unit and integration tests pass.","created_at":"2016-11-21T14:22:49Z","updated_at":"2016-11-28T15:54:43Z","closed_at":null,"merged_at":null,"merge_commit_sha":"31b010fcb96d1b9e3e838ea77cb57bb4e92282ba","assignee":null,"assignees":[],"milestone":null,"commits_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3180/commits","review_comments_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3180/comments","review_comment_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/comments{/number}","comments_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/3180/comments","statuses_url":"https://api.github.com/repos/DIRACGrid/DIRAC/statuses/7a51fc1b39a9e4aee0f75b7d83af3656b421f2c5","head":{"label":"arrabito:TSwithFilters","ref":"TSwithFilters","sha":"7a51fc1b39a9e4aee0f75b7d83af3656b421f2c5","user":{"login":"arrabito","id":6996265,"avatar_url":"https://avatars.githubusercontent.com/u/6996265?v=3","gravatar_id":"","url":"https://api.github.com/users/arrabito","html_url":"https://github.com/arrabito","followers_url":"https://api.github.com/users/arrabito/followers","following_url":"https://api.github.com/users/arrabito/following{/other_user}","gists_url":"https://api.github.com/users/arrabito/gists{/gist_id}","starred_url":"https://api.github.com/users/arrabito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arrabito/subscriptions","organizations_url":"https://api.github.com/users/arrabito/orgs","repos_url":"https://api.github.com/users/arrabito/repos","events_url":"https://api.github.com/users/arrabito/events{/privacy}","received_events_url":"https://api.github.com/users/arrabito/received_events","type":"User","site_admin":false},"repo":{"id":19857142,"name":"DIRAC","full_name":"arrabito/DIRAC","owner":{"login":"arrabito","id":6996265,"avatar_url":"https://avatars.githubusercontent.com/u/6996265?v=3","gravatar_id":"","url":"https://api.github.com/users/arrabito","html_url":"https://github.com/arrabito","followers_url":"https://api.github.com/users/arrabito/followers","following_url":"https://api.github.com/users/arrabito/following{/other_user}","gists_url":"https://api.github.com/users/arrabito/gists{/gist_id}","starred_url":"https://api.github.com/users/arrabito/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/arrabito/subscriptions","organizations_url":"https://api.github.com/users/arrabito/orgs","repos_url":"https://api.github.com/users/arrabito/repos","events_url":"https://api.github.com/users/arrabito/events{/privacy}","received_events_url":"https://api.github.com/users/arrabito/received_events","type":"User","site_admin":false},"private":false,"html_url":"https://github.com/arrabito/DIRAC","description":"DIRAC Grid","fork":true,"url":"https://api.github.com/repos/arrabito/DIRAC","forks_url":"https://api.github.com/repos/arrabito/DIRAC/forks","keys_url":"https://api.github.com/repos/arrabito/DIRAC/keys{/key_id}","collaborators_url":"https://api.github.com/repos/arrabito/DIRAC/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/arrabito/DIRAC/teams","hooks_url":"https://api.github.com/repos/arrabito/DIRAC/hooks","issue_events_url":"https://api.github.com/repos/arrabito/DIRAC/issues/events{/number}","events_url":"https://api.github.com/repos/arrabito/DIRAC/events","assignees_url":"https://api.github.com/repos/arrabito/DIRAC/assignees{/user}","branches_url":"https://api.github.com/repos/arrabito/DIRAC/branches{/branch}","tags_url":"https://api.github.com/repos/arrabito/DIRAC/tags","blobs_url":"https://api.github.com/repos/arrabito/DIRAC/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/arrabito/DIRAC/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/arrabito/DIRAC/git/refs{/sha}","trees_url":"https://api.github.com/repos/arrabito/DIRAC/git/trees{/sha}","statuses_url":"https://api.github.com/repos/arrabito/DIRAC/statuses/{sha}","languages_url":"https://api.github.com/repos/arrabito/DIRAC/languages","stargazers_url":"https://api.github.com/repos/arrabito/DIRAC/stargazers","contributors_url":"https://api.github.com/repos/arrabito/DIRAC/contributors","subscribers_url":"https://api.github.com/repos/arrabito/DIRAC/subscribers","subscription_url":"https://api.github.com/repos/arrabito/DIRAC/subscription","commits_url":"https://api.github.com/repos/arrabito/DIRAC/commits{/sha}","git_commits_url":"https://api.github.com/repos/arrabito/DIRAC/git/commits{/sha}","comments_url":"https://api.github.com/repos/arrabito/DIRAC/comments{/number}","issue_comment_url":"https://api.github.com/repos/arrabito/DIRAC/issues/comments{/number}","contents_url":"https://api.github.com/repos/arrabito/DIRAC/contents/{+path}","compare_url":"https://api.github.com/repos/arrabito/DIRAC/compare/{base}...{head}","merges_url":"https://api.github.com/repos/arrabito/DIRAC/merges","archive_url":"https://api.github.com/repos/arrabito/DIRAC/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/arrabito/DIRAC/downloads","issues_url":"https://api.github.com/repos/arrabito/DIRAC/issues{/number}","pulls_url":"https://api.github.com/repos/arrabito/DIRAC/pulls{/number}","milestones_url":"https://api.github.com/repos/arrabito/DIRAC/milestones{/number}","notifications_url":"https://api.github.com/repos/arrabito/DIRAC/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/arrabito/DIRAC/labels{/name}","releases_url":"https://api.github.com/repos/arrabito/DIRAC/releases{/id}","deployments_url":"https://api.github.com/repos/arrabito/DIRAC/deployments","created_at":"2014-05-16T13:20:03Z","updated_at":"2014-05-28T09:22:45Z","pushed_at":"2016-11-25T20:03:00Z","git_url":"git://github.com/arrabito/DIRAC.git","ssh_url":"git@github.com:arrabito/DIRAC.git","clone_url":"https://github.com/arrabito/DIRAC.git","svn_url":"https://github.com/arrabito/DIRAC","homepage":"http://diracgrid.org","size":42179,"stargazers_count":0,"watchers_count":0,"language":"Python","has_issues":false,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":0,"mirror_url":null,"open_issues_count":0,"forks":0,"open_issues":0,"watchers":0,"default_branch":"integration"}},"base":{"label":"DIRACGrid:rel-v6r17","ref":"rel-v6r17","sha":"bf52c4c3a8cffc3d5b23a9da9111ee8bbafdee6c","user":{"login":"DIRACGrid","id":694842,"avatar_url":"https://avatars.githubusercontent.com/u/694842?v=3","gravatar_id":"","url":"https://api.github.com/users/DIRACGrid","html_url":"https://github.com/DIRACGrid","followers_url":"https://api.github.com/users/DIRACGrid/followers","following_url":"https://api.github.com/users/DIRACGrid/following{/other_user}","gists_url":"https://api.github.com/users/DIRACGrid/gists{/gist_id}","starred_url":"https://api.github.com/users/DIRACGrid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DIRACGrid/subscriptions","organizations_url":"https://api.github.com/users/DIRACGrid/orgs","repos_url":"https://api.github.com/users/DIRACGrid/repos","events_url":"https://api.github.com/users/DIRACGrid/events{/privacy}","received_events_url":"https://api.github.com/users/DIRACGrid/received_events","type":"Organization","site_admin":false},"repo":{"id":1576831,"name":"DIRAC","full_name":"DIRACGrid/DIRAC","owner":{"login":"DIRACGrid","id":694842,"avatar_url":"https://avatars.githubusercontent.com/u/694842?v=3","gravatar_id":"","url":"https://api.github.com/users/DIRACGrid","html_url":"https://github.com/DIRACGrid","followers_url":"https://api.github.com/users/DIRACGrid/followers","following_url":"https://api.github.com/users/DIRACGrid/following{/other_user}","gists_url":"https://api.github.com/users/DIRACGrid/gists{/gist_id}","starred_url":"https://api.github.com/users/DIRACGrid/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/DIRACGrid/subscriptions","organizations_url":"https://api.github.com/users/DIRACGrid/orgs","repos_url":"https://api.github.com/users/DIRACGrid/repos","events_url":"https://api.github.com/users/DIRACGrid/events{/privacy}","received_events_url":"https://api.github.com/users/DIRACGrid/received_events","type":"Organization","site_admin":false},"private":false,"html_url":"https://github.com/DIRACGrid/DIRAC","description":"DIRAC Grid","fork":false,"url":"https://api.github.com/repos/DIRACGrid/DIRAC","forks_url":"https://api.github.com/repos/DIRACGrid/DIRAC/forks","keys_url":"https://api.github.com/repos/DIRACGrid/DIRAC/keys{/key_id}","collaborators_url":"https://api.github.com/repos/DIRACGrid/DIRAC/collaborators{/collaborator}","teams_url":"https://api.github.com/repos/DIRACGrid/DIRAC/teams","hooks_url":"https://api.github.com/repos/DIRACGrid/DIRAC/hooks","issue_events_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/events{/number}","events_url":"https://api.github.com/repos/DIRACGrid/DIRAC/events","assignees_url":"https://api.github.com/repos/DIRACGrid/DIRAC/assignees{/user}","branches_url":"https://api.github.com/repos/DIRACGrid/DIRAC/branches{/branch}","tags_url":"https://api.github.com/repos/DIRACGrid/DIRAC/tags","blobs_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/blobs{/sha}","git_tags_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/tags{/sha}","git_refs_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/refs{/sha}","trees_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/trees{/sha}","statuses_url":"https://api.github.com/repos/DIRACGrid/DIRAC/statuses/{sha}","languages_url":"https://api.github.com/repos/DIRACGrid/DIRAC/languages","stargazers_url":"https://api.github.com/repos/DIRACGrid/DIRAC/stargazers","contributors_url":"https://api.github.com/repos/DIRACGrid/DIRAC/contributors","subscribers_url":"https://api.github.com/repos/DIRACGrid/DIRAC/subscribers","subscription_url":"https://api.github.com/repos/DIRACGrid/DIRAC/subscription","commits_url":"https://api.github.com/repos/DIRACGrid/DIRAC/commits{/sha}","git_commits_url":"https://api.github.com/repos/DIRACGrid/DIRAC/git/commits{/sha}","comments_url":"https://api.github.com/repos/DIRACGrid/DIRAC/comments{/number}","issue_comment_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/comments{/number}","contents_url":"https://api.github.com/repos/DIRACGrid/DIRAC/contents/{+path}","compare_url":"https://api.github.com/repos/DIRACGrid/DIRAC/compare/{base}...{head}","merges_url":"https://api.github.com/repos/DIRACGrid/DIRAC/merges","archive_url":"https://api.github.com/repos/DIRACGrid/DIRAC/{archive_format}{/ref}","downloads_url":"https://api.github.com/repos/DIRACGrid/DIRAC/downloads","issues_url":"https://api.github.com/repos/DIRACGrid/DIRAC/issues{/number}","pulls_url":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls{/number}","milestones_url":"https://api.github.com/repos/DIRACGrid/DIRAC/milestones{/number}","notifications_url":"https://api.github.com/repos/DIRACGrid/DIRAC/notifications{?since,all,participating}","labels_url":"https://api.github.com/repos/DIRACGrid/DIRAC/labels{/name}","releases_url":"https://api.github.com/repos/DIRACGrid/DIRAC/releases{/id}","deployments_url":"https://api.github.com/repos/DIRACGrid/DIRAC/deployments","created_at":"2011-04-06T11:47:53Z","updated_at":"2016-10-24T10:57:22Z","pushed_at":"2016-11-27T23:12:31Z","git_url":"git://github.com/DIRACGrid/DIRAC.git","ssh_url":"git@github.com:DIRACGrid/DIRAC.git","clone_url":"https://github.com/DIRACGrid/DIRAC.git","svn_url":"https://github.com/DIRACGrid/DIRAC","homepage":"http://diracgrid.org","size":62743,"stargazers_count":53,"watchers_count":53,"language":"Python","has_issues":true,"has_downloads":true,"has_wiki":true,"has_pages":false,"forks_count":97,"mirror_url":null,"open_issues_count":103,"forks":97,"open_issues":103,"watchers":53,"default_branch":"integration"}},"_links":{"self":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3180"},"html":{"href":"https://github.com/DIRACGrid/DIRAC/pull/3180"},"issue":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/3180"},"comments":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/issues/3180/comments"},"review_comments":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3180/comments"},"review_comment":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/comments{/number}"},"commits":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/pulls/3180/commits"},"statuses":{"href":"https://api.github.com/repos/DIRACGrid/DIRAC/statuses/7a51fc1b39a9e4aee0f75b7d83af3656b421f2c5"}}}}
{"actor":{"display_login":"arrabito"}}