def __init__(self, create=False): ''' Initialize zoom project using the cwd of the caller. args: create: will initialize a new project if true else just load raises: ZoomError: project already exists (if creating) ZoomError: no project exists (if loading) ZoomError: failed to write zoomfile ''' self.name = None self.modules = [] self.deps = [] self.root = None self.path = os.getcwd() self.rel_path = None self._log = logging.getLogger('zoom') if create: self.name = os.path.basename(self.path) self.root = self.path try: zoom_io.create_proj_file(self.path, self.serialize()) except IOError: raise ZoomError('zoom project already exists') self._save() else: state = None try: self.root, state = zoom_io.load_proj_file(self.path) self.rel_path = zoom_io.relative_path(self.root) except IOError: raise ZoomError('not inside a zoom project') self.deserialize(state)
def __init__(self, root, path, url): ''' Initializes zoom dependency from serialized state. args: root: root of the ZoomProject path: path to the dependency (relative path) url: url of the dependency ''' # correct path if not path: path = relative_path(root) super(ZoomDependency, self).__init__(root, path, url)
def __init__(self, root, path, url): ''' Initializes zoom module from serialized state. args: root: root of the ZoomProject path: path to a module (relative path) url: url of the module to track ''' # correct path if not path: mod_name = url.split('/')[-1] # just in case there is an extension if '.' in mod_name: mod_name = mod_name.split('.')[0] path = os.path.join(relative_path(root), mod_name) super(ZoomModule, self).__init__(root, path, url)