Exemple #1
0
 def __init__(self, args):
     callbacks = MqttCallbacks()
     callbacks.on_message = self.on_message
     self.mqtt_manager = MqttManager(args, callbacks)
     self.git_manager = GitManager()
     self.device_state = State()
     self.device_state.blobset = BlobsetState()
     self.device_state.blobset.blobs = {}
     self.device_state.blobset.blobs['codebase'] = BlobBlobsetState()
     self.update_state(None, None, None)
     self.git_manager.restore()
     self.update_state("steady", self.git_manager.steady(None))
Exemple #2
0
 def __init__(self, repo='.', build_directory='./build', **env):
   '''Initialize'''
   self.git_manager = GitManager(repo)
   self.commit_targets = []
   self.build_directory = os.path.abspath(build_directory)
   self.compilation_options = dict(build_directory = self.build_directory)
   self.linking_options = {}
   os.environ.update(env)
Exemple #3
0
class GitCompiler:
  '''The main honcho - the compiler that travels through time and compiles your commits.'''

  def __init__(self, repo='.', build_directory='./build', **env):
    '''Initialize'''
    self.git_manager = GitManager(repo)
    self.commit_targets = []
    self.build_directory = os.path.abspath(build_directory)
    self.compilation_options = dict(build_directory = self.build_directory)
    self.linking_options = {}
    os.environ.update(env)

  def add_commit_targets(self, **kwargs):
    '''Add commit targets to compile.'''
    self.commit_targets.extend(self.git_manager.get_commits(**kwargs))

  def remove_commit_targets(filter_function):
    '''Remove commit targets that cause the given function to return a truthy value.'''
    self.commit_targets[:] = [commit for commit in self.commit_targets if not filter_function(commit)]


  def set_compilation_task(self, task, **kwargs):
    '''Set the compilation task (the thing that'll compile each commit)'''
    self.compilation_task = task
    if kwargs:
      self.compilation_options.update(kwargs)

  def set_linking_task(self, task, **kwargs):
    '''Set the linking task (the thing that'll link the outputs of the compilation task)'''
    self.linking_task = task
    if kwargs:
      self.linking_options.update(kwargs)

  def compile(self, link=False, **additional_compilation_args):
    '''Compile (and link unless specified otherwise)!
       TODO: Thread this out with an observer to output progress.
    '''
    options = self.compilation_options.copy()
    if additional_compilation_args:
      options.update(additional_compilation_args)
    self.compilation_output = self.compilation_task(self.commit_targets, options, self.git_manager)
    if link: 
      self.link(self.compilation_output)

  def link(self, compilation_output):
    '''Link compilation output!'''
    self.linking_task(self.commit_targets, compilation_output, self.linking_options, self.git_manager)
Exemple #4
0
class UdmiAgent:

    def __init__(self, args):
        callbacks = MqttCallbacks()
        callbacks.on_message = self.on_message
        self.mqtt_manager = MqttManager(args, callbacks)
        self.git_manager = GitManager()
        self.device_state = State()
        self.device_state.blobset = BlobsetState()
        self.device_state.blobset.blobs = {}
        self.device_state.blobset.blobs['codebase'] = BlobBlobsetState()
        self.update_state(None, None, None)
        self.git_manager.restore()
        self.update_state("steady", self.git_manager.steady(None))

    def send_state(self):
        self.mqtt_manager.update_state(self.device_state.to_dict())

    def update_state(self, stage, result, status=None):
        blob = self.device_state.blobset.blobs['codebase']
        blob.stage = stage
        blob.result = result
        if status:
            blob.status = Common.Entry()
            blob.status.message = status
        else:
            blob.status = None
        self.send_state()

    def steady_state(self, target):
        self.update_state("steady", self.git_manager.steady(target))

    def fetch_target(self, target):
        self.update_state("fetch", self.git_manager.fetch(target))

    def apply_target(self, target):
        self.update_state("apply", self.git_manager.apply(target))

    def config_codebase(self, blob):
        stage = blob.stage
        target = blob.target
        self.update_state(stage, None, None)
        try:
            if stage == 'steady' or not stage:
                self.steady_state(target)
                print('steady state')
            elif stage == 'fetch':
                self.fetch_target(target)
            elif stage == 'apply':
                self.apply_target(target)
            else:
                raise Exception('unknown blob stage', stage)
        except Exception as e:
            print("Reporting exception", str(e))
            self.update_state(stage, None, str(e))

    def config_message(self, payload):
        config = Config.from_dict(payload)
        blobset = config.blobset
        if not blobset:
            print('ignoring config with no blobset')
            return
        if 'codebase' in blobset.blobs:
            self.config_codebase(blobset.blobs['codebase'])
        else:
            print('no codebase in blobset blobs')

    def on_message(self, topic, message):
        if topic == 'config':
            return self.config_message(message)
        print('Received unknown message topic {}'.format(topic))

    def loop(self):
        return self.mqtt_manager.loop()