def create_project(filename, overwrite=False): """Create a new project with the path <filename>. If <overwrite> is False, raise an OSError if this path already exists. Args: filename (str): File path to create project file at. Must end with .cwp overwrite (bool, optional): Whether or not to overwrite an existing project with <filename>. Raises an OSError if path already exists and this is false. Defaults to false. Returns: A chipwhisperer project object. Raises: OSError: filename exists and overwrite is False. """ filename = project.ensure_cwp_extension(filename) if os.path.isfile(filename) and (overwrite == False): raise OSError("File " + filename + " already exists") # If the user gives a relative path including ~, expand to the absolute path filename = os.path.abspath(os.path.expanduser(filename)) proj = project.Project() proj.setFilename(filename) return proj
def open_project(filename): """Load an existing project from disk. Args: filename (str): Path to project file. Returns: A chipwhisperer project object. Raises: OSError: filename does not exist. """ filename = project.ensure_cwp_extension(filename) proj = project.Project() proj.load(filename) return proj
def openProject(filename): """Load an existing project from disk. Raise an IOError if no such project exists. """ if not os.path.isfile(filename): raise IOError("File " + filename + " does not exist or is not a file") proj = project.ProjectFormat() proj.load(filename) return proj
def import_project(filename, file_type='zip', overwrite=False): """Import and open a project. Will import the **filename** by extracting to the current working directory. Currently support file types: * zip Args: filename (str): The file name to import. file_type (str): The type of file that is being imported. Default is zip. overwrite (bool): Whether or not to overwrite the project given as the **import_as** project. .. versionadded:: 5.1 Add **import_project** function. """ # extract name from input file input_dir, input_file = os.path.split(filename) input_file_root, input_file_ext = os.path.splitext(input_file) input_abs_path = os.path.abspath(filename) # use the appropriate type of import if file_type == 'zip': with ZipFile(input_abs_path, 'r') as project_zip: output_path = None for path in project_zip.namelist(): root, ext = os.path.splitext(path) if ext == '.cwp': directory, project_name = os.path.split(root) output_path = ''.join([project_name, '.cwp']) # check if name already exists in projects if os.path.isfile(output_path) and (overwrite == False): raise OSError("File " + output_path + " already exists") # extract the project.cwp file and project_data directory to # the PROJECT_DIR project_zip.extractall(path=os.getcwd()) if output_path is None: raise ValueError( 'Zipfile does not contain a .cwp file, so it cannot be imported' ) else: raise ValueError( 'Import from file type not supported: {}'.format(file_type)) proj = project.Project() proj.load(output_path) return proj
def createProject(filename, overwrite=False): """Create a new project with the path <filename>. If <overwrite> is False, raise an IOError if this path already exists. """ if os.path.isfile(filename) and (overwrite == False): raise IOError("File " + filename + " already exists") proj = project.ProjectFormat() proj.setFilename(filename) return proj