<s> '''<STR_LIT>''' <EOL> import requests <EOL> import json <EOL> import datetime <EOL> import dateutil . parser <EOL> import urllib <EOL> import os <EOL> import pytz <EOL> from Empire . cloudservices . github import GithubOrg , GithubRepo , GithubCommit <EOL> from repos . base import RepoSource , RepoCommit , RepoPatch <EOL> from repos . diffparser import DiffParser <EOL> import logging <EOL> logger = logging . getLogger ( '<STR_LIT>' ) <EOL> owner = '<STR_LIT>' <EOL> repo = '<STR_LIT>' <EOL> class GithubSource ( RepoSource ) : <EOL> def __init__ ( self , creds = None , host = '<STR_LIT>' , owner = '<STR_LIT>' , repo = '<STR_LIT>' ) : <EOL> self . _last_date = None <EOL> self . _last_identifier = None <EOL> self . _no_more_requests_until = None <EOL> github_org = GithubOrg ( host , owner , creds ) <EOL> self . _github_repo = GithubRepo ( github_org , repo ) <EOL> def processSinceIdentifier ( self , identifier , commit_started_callback , patch_callback , commit_finished_callback , path = None ) : <EOL> since_datetime = datetime . datetime . utcnow ( ) <EOL> since_datetime = since_datetime . replace ( tzinfo = pytz . UTC , hour = <NUM_LIT:0> , minute = <NUM_LIT:0> , second = <NUM_LIT:0> ) <EOL> if identifier : <EOL> try : <EOL> since_datetime = dateutil . parser . parse ( identifier ) <EOL> except Exception as e : <EOL> logger . error ( "<STR_LIT>" , identifier ) <EOL> commits = self . _github_repo . commits ( since_datetime , path = path ) <EOL> self . processCommits ( commits , <EOL> commit_started_callback = commit_started_callback , <EOL> patch_callback = patch_callback , <EOL> commit_finished_callback = commit_finished_callback ) ; <EOL> if self . _last_date : <EOL> return self . _last_date . isoformat ( ) <EOL> if since_datetime : <EOL> return since_datetime . isoformat ( ) <EOL> return None <EOL> def processCommits ( self , commits , commit_started_callback , patch_callback , commit_finished_callback ) : <EOL> if commits is None : <EOL> return None <EOL> commits = commits [ : : - <NUM_LIT:1> ] <EOL> logger . debug ( "<STR_LIT>" , len ( commits ) ) <EOL> for github_commit in commits : <EOL> logger . debug ( "<STR_LIT>" , github_commit . sha ) <EOL> if github_commit . sha : <EOL> github_commit = self . _github_repo . commit ( github_commit . sha ) <EOL> repo_commit = RepoCommit ( ) ; <EOL> repo_commit . url = github_commit . html_url <EOL> repo_commit . repo_source = self <EOL> if github_commit . date is not None : <EOL> self . _last_date = dateutil . parser . parse ( github_commit . date ) <EOL> repo_commit . date = self . _last_date <EOL> self . _last_date += datetime . timedelta ( seconds = <NUM_LIT:1> ) <EOL> repo_commit . identifier = self . _last_date . isoformat ( ) <EOL> repo_commit . committer_email = github_commit . committer_email <EOL> repo_commit . committer_name = github_commit . committer_name <EOL> repo_commit . username = github_commit . committer_login <EOL> repo_commit . message = github_commit . message <EOL> repo_commit . sha = github_commit . sha <EOL> commit_started_callback ( repo_commit ) <EOL> if github_commit . files : <EOL> for file_info in github_commit . files : <EOL> if file_info . get ( '<STR_LIT>' ) : <EOL> filename = committer_username = None <EOL> diff = DiffParser ( file_info [ '<STR_LIT>' ] ) <EOL> repo_patch = RepoPatch ( repo_commit = repo_commit ) <EOL> repo_patch . diff = diff <EOL> repo_patch . filename = file_info . get ( "<STR_LIT:filename>" ) <EOL> patch_callback ( repo_patch ) <EOL> commit_finished_callback ( repo_commit ) <EOL> logger . debug ( "<STR_LIT>" ) <EOL> logger . debug ( "<STR_LIT>" ) <EOL> if __name__ == "<STR_LIT:__main__>" : <EOL> from Empire . creds import CredentialManager <EOL> credentials_file = "<STR_LIT>" <EOL> credential_key = os . environ . get ( '<STR_LIT>' ) <EOL> if credential_key is None : <EOL> credential_key = getpass . getpass ( '<STR_LIT>' ) <EOL> credential_manager = CredentialManager ( credentials_file , credential_key ) <EOL> creds = credential_manager . get_or_create_credentials_for ( "<STR_LIT>" , "<STR_LIT:password>" ) <EOL> test = GithubSource ( creds ) ; <EOL> def cstart ( commit ) : <EOL> print commit <EOL> def pstart ( patch ) : <EOL> print "<STR_LIT>" , patch . filename <EOL> def cend ( commit ) : <EOL> pass <EOL> test . processSinceIdentifier ( "<STR_LIT>" , cstart , pstart , cend ) ; </s>
