Esempio n. 1
0
    def gen_flash_images(self):
        work_dir = self.config.get_str('gapy/work_dir')

        # Go through all the specified flashes to generate image and stimuli if needed
        for flash_path in self.config.get_py('runner/flash_devices'):

            traces.info('Building stimuli for flash ' + flash_path)

            flash_config = self.config.get(flash_path)
            if flash_config is None:
                raise errors.InputError('Invalid flash device: ' + flash_path)

            if flash_config.get('content/partitions') is not None:

                for name, partition in flash_config.get('content/partitions').get_items().items():

                    type_name = partition.get_str('type')

                    if type_name is not None:
                        if type_name == 'readfs':
                            gen_readfs.main(config=self.config, partition_config=partition)
                        elif type_name == 'lfs':
                            gen_lfs.main(config=self.config, partition_config=partition)
                        elif type_name == 'hostfs':
                            work_dir = self.config.get_str('gapy/work_dir')
                            for file in partition.get('files').get_dict():
                                shutil.copy(file, work_dir)
                        else:
                            raise errors.InputError('Invalid partition type: ' + type_name)

            if flash_config.get('content/image') is not None:
                gen_flash_image.main(config=self.config, flash_config=flash_config)
Esempio n. 2
0
    def _open_output(self, filename):

        try:
            self.output = open(filename, "w", encoding="utf-8")
        except ValueError:
            raise errors.InputError("Output file encoding is not supported.")
        except:
            raise errors.InputError("Output file couldn't be opened.")
 def check_input(self, dataframe, lookup, classifier_type, topics, n_grams,
                 features, text_column):
     if dataframe == None or lookup == None or classifier_type == None or topics == None or n_grams == None or features == None:
         raise errors.InputError("Please provide all necessary information")
     if not isinstance(text_column,
                       str) or text_column not in dataframe.columns:
         raise errors.InputError("That column does not exist")
     return (dataframe, lookup, str(topics), classifier_type, str(n_grams),
             str(features), str(text_column))
 def check_input(self, dataframe, lookup, topics, passes, min_probability,
                 text_column):
     if dataframe == None or lookup == None or topics == None or passes == None or min_probability == None:
         raise errors.InputError("Please provide all necessary information")
     if not isinstance(text_column,
                       str) or text_column not in dataframe.columns:
         raise errors.InputError("That column does not exist")
     return (dataframe, lookup, str(topics), str(passes), min_probability,
             str(text_column))
Esempio n. 5
0
    def get_boot_flash(self):
        flash_path = self.config.get_str("runner/boot/device")
        if flash_path is None:
            raise errors.InputError('The path to the flash device must be specified when booting from flash')

        flash_config = self.config.get(flash_path)
        if flash_config is None:
            raise errors.InputError('Invalid flash device specified for boot: ' + flash_path)

        return flash_config
Esempio n. 6
0
def _parse_date(dt_str):
    if dt_str is None:
        return None
    try:
        d, m, y = [int(x) for x in dt_str.split('/')]
        if y < 2013:
            raise errors.InputError('Wrong year %s for param %s' % (y, dt_str))
        return datetime.date(year=y, month=m, day=d)
    except ValueError, e:
        raise errors.InputError('Wrong date param %s: %s' %
                                (dt_str, unicode(e)))
Esempio n. 7
0
def main():
    try:
        log.info("<--------------START----------------->")

        log.info("Get Address based on Latitude and Longitude.")
        location_res = getlocation()
        _places_list = []
        city = location_res.get_cityname()
        state = location_res.get_statecode()
        if not city or not state:
            raise (errors.InputError().message, errors.InputError().expression)
        log.info(
            "Address extracted based on latitude and longitude => '%s,%s'" %
            (city, state))
        origin = ('%s %s' % (city, state))
        _places_list.append(origin)
        destination = ('%s %s' % (__destination_city__, __destination_state__))
        log.info("Now get the distance between %s and %s" %
                 (origin, destination))
        dist_req = distance_request.DistanceRequest(origin, destination)
        dist_res = distance_response.DistanceResponse()
        distance.Distance(dist_req, dist_res)
        _distance = dist_res.get_distance()
        _duration = dist_res.get_duration()
        if not _distance or not _duration:
            raise errors.Error(
                "Could not get distance or duration for the given destination.",
                "%s,%s" % (_distance, _duration))
        else:
            _places_list.append(destination)
        log.info(" Distance and duration between %s and %s is %s and %s" %
                 (origin, destination, _distance, _duration))
        weather_url = weather.get_weatherurl()
        output_format = weather.get_weatheroutputformat()
        log.info(_places_list)
        for place in _places_list:
            log.info("Invoke weather API for location %s" %
                     (place.split(",")[0]))
            weather_req = weather_request.WeatherRequest()
            weather_req.set_url(weather_url)
            weather_req.set_city(place.rsplit(" ", maxsplit=1)[0])
            weather_req.set_state(place.rsplit(" ", maxsplit=1)[1])
            weather_req.set_format(output_format)
            weather_res = weather_response.WeatherResponse()
            weather.Weather(weather_req, weather_res)
            _weatherResponse(weather_res)

        log.info("<---------------END------------------>")
    except errors.Error as err:
        print("%s %s" % (err.message, err.expression))
Esempio n. 8
0
def assertAimAxis(jnt=None, aim=None):
    '''Assert the given axis is the axis aiming at child nodes

    Attributes:
        jnt -- Joint in scene to check
        aim -- Character "x"|"y"|"z". Axis expected to aim at child
    '''
    if not isinstance(jnt, pm.nt.Joint):
        raise errors.InputError('jnt', jnt, pm.nt.Joint)

    if aim.lower() not in ['x', 'y', 'z']:
        raise errors.InputError('aim', aim, '"x", "y" or "z"')
    aim = aim.lower()

    children = jnt.getChildren()
    if not children:
        raise errors.ObjectError(jnt, 'Child nodes', children)

    if len(children) > 1:
        raise errors.ObjectError(jnt, 'One child', children)

    # Place locator as child to jnt and zero it
    loc = pm.spaceLocator()
    pm.parent(loc, jnt)
    loc.setTranslation(0)
    loc.setRotation([0, 0, 0])

    # Get magnitude of vector to child
    jnt_pos = pm.dt.Vector(pm.xform(jnt, q=1, ws=1, t=1))
    chld_pos = pm.dt.Vector(pm.xform(children[0], q=1, ws=1, t=1))
    vec = chld_pos - jnt_pos

    # Move it along expected axis
    if aim == 'x':
        loc.tx.set(vec.length())
    if aim == 'y':
        loc.ty.set(vec.length())
    if aim == 'z':
        loc.tz.set(vec.length())
    loc_pos = pm.xform(loc, q=1, ws=1, t=1)

    # Remove locator from the scene
    pm.delete(loc)

    for l, p in zip(loc_pos, chld_pos):
        if round(l, 6) != round(p, 6):
            return False
    return True
Esempio n. 9
0
def rest_post_json(baseURL, uri, thejson, user, password):
    proxies = {
        "http": None,
        "https": None,
    }
    appformat = 'application/json'
    headers = {'content-type': appformat, 'accept': appformat}
    restURI = baseURL + uri
    logging.info(restURI)
    try:
        r = requests.post(restURI,
                          data=thejson,
                          headers=headers,
                          proxies=proxies,
                          auth=(user, password),
                          verify=False)
        # print "HTTP response code is: " + str(r.status_code)
        if r.status_code == 200:
            return json.dumps(r.json(), indent=2)
        else:
            raise errors.InputError(restURI,
                                    "HTTP status code: " + str(r.status_code))
    except errors.InputError as err:
        logging.error("Exception raised: " + str(type(err)))
        logging.error(err.expression)
        logging.error(err.message)
        return
Esempio n. 10
0
 def __gen_debug_info(self, full_config, gvsoc_config):
     for binary in full_config.get('**/debug_binaries').get_dict():
         if os.system('pulp-pc-info --file %s --all-file %s' %
                      (binary.replace('.debugInfo', ''), binary)) != 0:
             raise errors.InputError(
                 'Error while generating debug symbols information, make sure the toolchain and the binaries are accessible '
             )
Esempio n. 11
0
def main():
    arfns = args
    if not len(arfns):
        raise errors.InputError("No input archives provided! " \
                                "Here's your summary: NOTHING!")
    print "Making summary plot of %d files" % len(arfns)
    if options.numrows is None:
        numrows = int(np.ceil(len(arfns) / float(options.numcols)))
    else:
        numrows = options.numrows
    layout = (options.numcols, numrows)
    numpanels = np.prod(layout)
    arfs = get_archives(arfns, options.sortkeys)
    numfigs = int(np.ceil(len(arfns) / float(numpanels)))
    for fignum in range(numfigs):
        arfs_toplot = arfs[fignum * numpanels:(fignum + 1) * numpanels]
        fig = plt.figure(figsize=(8,11), FigureClass=SummaryFigure,
                arfs=arfs_toplot, scale_indep=options.scale_indep, \
                show_template=options.show_template, \
                centre_prof=options.centre_prof, layout=layout, \
                infotext=options.info_text)
        fig.text(0.94, 0.02, "%d / %d" % (fignum + 1, numfigs), size='small')
        fig.connect_event_triggers()
        fig.plot()
        if options.savefn:
            if numfigs > 1:
                fn, ext = os.path.splitext(options.savefn)
                plt.savefig(fn + ("_page%d" % (fignum + 1)) + ext,
                            papertype='a4')
            else:
                plt.savefig(options.savefn, papertype='a4')
        fig.canvas.mpl_connect('key_press_event', \
                lambda ev: ev.key in ('q', 'Q') and plt.close(fig))
    if options.interactive:
        plt.show()
Esempio n. 12
0
    def __get_platform_path(self):

        if self.platform_path is None:

            if self.platform_tool == 'vsim':
                plt_path_name = 'VSIM_PATH'
                plt_path = os.environ.get('VSIM_PATH')
            else:
                plt_path_name = 'XCSIM_PATH'
                plt_path = os.environ.get('XCSIM_PATH')

            platform_path_name = self.plt_config.get_str('path_envvar')
            if platform_path_name is not None:
                envvar = os.environ.get(platform_path_name)
                if envvar is not None:
                    plt_path = envvar
                    plt_path_name = plt_path_name

            if plt_path is None:
                if platform_path_name is None:
                    raise errors.InputError(
                        "No platform found, VSIM_PATH is not defined.")
                else:
                    raise errors.InputError(
                        "No platform found, neither %s nor VSIM_PATH is defined."
                        % (platform_path_name))

            if not os.path.exists(plt_path):
                raise errors.InputError("ERROR: %s=%s path does not exist" %
                                        (plt_path_name, plt_path))

            self.platform_path = plt_path

            os.environ['PULP_PATH'] = plt_path
            os.environ['TB_PATH'] = plt_path
            os.environ['VSIM_PLATFORM'] = plt_path
            os.environ['VSIM_PLATFORM'] = plt_path

            if self.platform_tool == 'vsim':
                pass
            else:
                os.environ['XCSIM_PLATFORM'] = plt_path

            self.platform_path = plt_path

        return self.platform_path
Esempio n. 13
0
def get_route_info_full(req):
    route_id = req.GET['route_id']
    from_date = _parse_date(req.GET.get('from_date'))
    to_date = _parse_date(req.GET.get('to_date'))
    if from_date and to_date and from_date > to_date:
        raise errors.InputError('from_date %s cannot be after to_date %s' %
                                (from_date, to_date))
    filters = Filters(from_date=from_date, to_date=to_date)
    stats = _get_route_info_full(route_id, filters)
    stats.sort(key=_get_info_sort_key)
    return json_resp(stats)
Esempio n. 14
0
def check_type(obj=None, attr=None, types=[]):
    ''' Check an objects type

    Attributes:
        obj -- Object to check
        attr -- Attribute that object is passed into. String
        types -- List of types that obj needs to be
    '''
    for t in types:
        if isinstance(obj, t):
            return True
    raise errors.InputError(attr, type(obj), types)
class Combine:
    def __init__(self, dataframe, datediff=10):
        self.datediff= self.check_input(self, datediff)
        self.datediff = datediff
        self.dataframe = dataframe
        self.dataframe.show()
        self.split()
        self.combine()
    
    def self.check_input(self, datediff):
        if not isinstance(datediff, int) or datediff < 0:
            raise errors.InputError("The date differences cannot be smaller than 0")
        return datediff
Esempio n. 16
0
def assertAimingAt(a=None, b=None, axis=None, log=False):
    '''Assert a aims at b along axis

    Attributes:
        a -- Object a. [pm.nt.Transform, pm.nt.Joint]
        b -- Object b. [pm.nt.Transform, pm.nt.Joint]
        axis -- axis aiming at b. 'x' 'y' or 'z'
    '''
    general.check_type(a, 'a', [pm.nt.Transform, pm.nt.Joint])
    general.check_type(b, 'b', [pm.nt.Transform, pm.nt.Joint])
    general.check_type(axis, 'axis', [str])

    if axis not in ['x', 'y', 'z']:
        raise errors.InputError(axis, 'axis', ['x', 'y', 'z'])

    pos_a = pm.dt.Vector(pm.xform(a, q=1, ws=1, rp=1))
    pos_b = pm.dt.Vector(pm.xform(b, q=1, ws=1, rp=1))
    vec = pos_b - pos_a

    if not vec.length() > 0:
        raise errors.ObjectError(a, 'Different position than b',
                                 'Same position as b')

    loc = pm.spaceLocator()
    pm.parent(loc, a)
    loc.setTranslation(0)
    loc.setRotation([0, 0, 0])
    if axis == 'x':
        loc.tx.set(vec.length())
    elif axis == 'y':
        loc.ty.set(vec.length())
    elif axis == 'z':
        loc.tz.set(vec.length())

    pos_loc = pm.dt.Vector(pm.xform(loc, q=1, ws=1, rp=1))
    pm.delete(loc)

    if log:
        str_1 = 'pos_a: ', pos_a
        str_2 = 'pos_b: ', pos_b
        str_3 = 'pos_loc: ', pos_loc
        general.logging.debug(str_1)
        general.logging.debug(str_2)
        general.logging.debug(str_3)

    return general.assertAlmostEquals(pos_loc, pos_b, 3)
Esempio n. 17
0
def operationFunc(args, config=None):
	if config.get_str('root_dir') is None:
		return

	traces.info('Generating LittleFS image')
	
	cmd = 'mklfs -b 262144 -r 4 -p 4 -s 10485760 -c %s -i %s' % (config.get_str('root_dir'), args.output)

	traces.info('Generating LittleFS images with command:')
	traces.info('  ' + cmd)

	stdout = None if traces.verbose else subprocess.PIPE

	if subprocess.run(shlex.split(cmd), stdout=stdout).returncode != 0:
		raise errors.InputError('Failed to generate LittleFS image')

	if config is not None:
		config.set('enabled', True)
Esempio n. 18
0
    def new_user(self, name, mail, password, description=""):
        """ create a new user """
        MAX_LEN_PASSWORD = 255

        enc_password = conn.ccdCrypto.hashPassword(password)
        if len(enc_password) > MAX_LEN_PASSWORD:
            raise errors.InputError("Password exceeds limit of %d chars." %
                                    MAX_LEN_PASSWORD)

        validate_name(name)
        validate_mail(mail)
        validate_description(description)

        pld = dict(name=name,
                   mail=mail,
                   password=enc_password,
                   description=description)
        resp_t = comm.sendpacket(self, op=conn.ccdlib.OP_NEWUSER, pld=pld)
        return resp_t[-1]
Esempio n. 19
0
    def profile_likelihood(self, pl_directory, size=0.3, num_per_row=3):
        """
        compile any pdf, jpg and png files
        in directory into a latex pdf document
        :return:
        """
        if isinstance(self.file_types, str):
            self.file_types = [self.file_types]

        files = self.search_recursive(pl_directory)

        if files is []:
            raise errors.InputError(
                '''Cannot locate pdf, jpg or png files in "{}". Please 
                give the full path to where your model selection results are
                 plotted. 
                '''.format(pl_directory)
            )
        doc = pylatex.Document(self.filename, documentclass='article')

        for k, v in files.items():
            assert isinstance(v, list)
            if v is not None:
                with doc.create(pylatex.Figure(
                        position='htbp!',
                        width=pylatex.NoEscape(r'\linewidth'))) as fig:
                    # [fig.add_image(i) for i in v]
                    for i in range(len(v)):
                        with doc.create(pylatex.SubFigure(
                                width=pylatex.NoEscape(str(size) + r'\linewidth'))) as sub:
                            sub.add_image(v[i])
                            sub.add_caption(os.path.split(v[i])[1])
                        if i is not 0 and i % num_per_row is 0:
                            doc.append(pylatex.NoEscape(r'\break'))
                            # sub.add_label(i)
                            #         # fig.add_caption(os.path.join(*Path(v[i]).parts[-3:-1]))

                        doc.append(pylatex.NoEscape(r'\hfill'))
                    fig.add_caption(os.path.split(k)[1])

        doc.generate_pdf()
        LOG.info('PDF generated at "{}"'.format(doc.default_filepath))
Esempio n. 20
0
def rest_post_xml(baseURL, uri, thexml, user, password):
    proxies = {
        "http": None,
        "https": None,
    }
    appformat = 'application/xml'
    headers = {'content-type': appformat, 'accept': appformat}
    restURI = baseURL + uri
    try:
        r = requests.post(restURI, data=thexml, headers=headers, proxies=proxies, auth=(user, password), verify=False)
        # print "HTTP response code is: " + str(r.status_code)
        if r.status_code == 200:
            response_xml = xml.dom.minidom.parseString(r.content)
            return response_xml.toprettyxml()
        else:
            raise errors.InputError(restURI, "HTTP status code: " + str(r.status_code))
    except errors.InputError as err:
        print "Exception raised: " + str(type(err))
        print err.expression
        print err.message
        return
 def check_input(self, dataframe, lookup, topics, passes, decay, iterations,
                 min_probability, text_column):
     if dataframe == None or lookup == None or topics == None or passes == None or min_probability == None:
         raise errors.InputError("Please provide all necessary information")
     if topics not in self.possible_topics:
         raise errors.InputError(
             "We do not have a topic with that number of topics")
     if passes not in self.possible_passes:
         raise errors.InputError(
             "We do not have a topic with that number of passes")
     if decay is not None and decay not in self.possible_decay:
         raise errors.InputError(
             "We do not have a topic with that decay rate")
     if iterations is not None and iterations not in self.possible_iterations:
         raise errors.InputError(
             "We do not have a topic with that iteration rate")
     if not isinstance(text_column,
                       str) or text_column not in dataframe.columns:
         raise errors.InputError("That column does not exist")
     return (dataframe, lookup, str(topics), str(passes), str(decay),
             str(iterations), min_probability, str(text_column))
Esempio n. 22
0
    def conf(self):

        boot_mode = self.config.get_str("runner/boot/mode")
        if boot_mode is None:
            raise errors.InputError('The boot mode has to be specified')

        binary = self.config.get_str('runner/boot-loader')

        # If we boot from flash, store the boot binary information in the specified flash
        if boot_mode == 'flash':
            flash_config = self.get_boot_flash()
            flash_config.set('content/boot-loader', binary)

        work_dir = self.config.get_str('gapy/work_dir')

        # Go through all the specified flashes to generate image and stimuli if needed
        for flash_path in self.config.get_py('runner/flash_devices'):

            traces.info('Building stimuli for flash ' + flash_path)

            flash_config = self.config.get(flash_path)
            if flash_config is None:
                raise errors.InputError('Invalid flash device: ' + flash_path)

            gen_image = False
            flash_image = self.args.force

            # The flash can contain the boot binary and several partitions for FS
            if flash_config.get('content/boot-loader') is not None:

                gen_image = True

            if flash_config.get('content/partitions') is not None:

                for name, partition in flash_config.get(
                        'content/partitions').get_items().items():

                    gen_image = True

                    type_name = partition.get_str('type')
                    if type_name is None:
                        raise errors.InputError('No partition type found')

                    if type_name not in ['hostfs'] and (
                        (partition.get('files') is not None
                         and len(partition.get('files').get_dict()) != 0) or
                        (partition.get_str('root_dir'))):
                        flash_image = True

                    img_path = os.path.join(
                        work_dir,
                        flash_path.replace('/', '.') + '.' + name + '.img')
                    partition.set('image', img_path)

            if gen_image:
                img_path = os.path.join(work_dir,
                                        flash_path.replace('/', '.') + '.img')
                flash_config.set('content/image', img_path)
                flash_config.set('content/flash', flash_image)

            stim_format = flash_config.get_str("models/%s/stimuli/format" %
                                               self.args.platform)

            if stim_format is not None:
                file_name = flash_config.get_str("models/%s/stimuli/file" %
                                                 self.args.platform)
                if file_name is None:
                    file_name = flash_path.replace('/',
                                                   '.') + '.' + stim_format

                file_path = os.path.join(work_dir, file_name)

                flash_config.set("content/stimuli/format", stim_format)
                flash_config.set("content/stimuli/file", file_path)
Esempio n. 23
0
    def prepare_document(self, directory, subdirs=False, file_types='.png'):
        """
        compile any pdf, jpg and png files
        in directory into a latex pdf document
        :return:
        """
        if subdirs not in [True, False]:
            raise errors.InputError('subdirs argument should be either True or False')

        if isinstance(file_types, str):
            file_types = [file_types]


        if subdirs:
            files = self.search_recursive(directory)

        else:
            files = self.search()

        if files is []:
            raise errors.InputError(
                '''Cannot locate pdf, jpg or png files in "{}". Please 
                give the full path to where your model selection results are
                 plotted. 
                '''.format(directory)
            )
        doc = pylatex.Document(self.filename, documentclass='article')

        for k, v in files.items():
            assert isinstance(v, list)
            if v is not None:
                with doc.create(pylatex.Section(os.path.join(*Path(k).parts[-1:]))):
                    doc.append(k)
                    doc.append(pylatex.NoEscape(r'\\*'))
                    if len(v) == 1:
                        with doc.create(
                                pylatex.Figure(
                                    position='htbp!',
                                    width=pylatex.NoEscape(r'0.3\linewidth'))
                        ) as fig:
                            
                            fig.add_image(v[0])
                            fig.add_caption(os.path.join(*Path(v[0]).parts[-2:]))
                            # fig.add_label(v[0])
                    else:
                        with doc.create(pylatex.Figure(
                                position='htbp!',
                                width=pylatex.NoEscape(r'\linewidth'),
                                )
                        ) as fig:
                            for i in range(len(v)):
                                with doc.create(
                                        pylatex.SubFigure(
                                            width=pylatex.NoEscape(r'0.3\linewidth')
                                        )
                                ) as sub:
                                    sub.add_image(v[i])
                                    # sub.add_caption('')
                                if i % 3 == 0:
                                    doc.append(pylatex.NoEscape(r'\break'))
                                    # sub.add_label(i)
                            fig.add_caption(os.path.join(*Path(v[i]).parts[-3:-1]))
                    doc.append(pylatex.NoEscape(r'\hfill'))


        doc.generate_pdf()
        LOG.info('PDF generated at "{}"'.format(doc.default_filepath))
Esempio n. 24
0
 def _read_syscalls(self, filename):
     try:
         with open(filename, "r", encoding="utf-8") as file:
             self.syscalls_list = [line[:-1] for line in file]
     except:
         raise errors.InputError("Syscalls file couldn't be opened.")
 def check_text_column(self, dataframe, text_column):
     if not isinstance(text_column,
                       str) or text_column not in dataframe.columns:
         raise errors.InputError("That column does not exist")
     return text_column
Esempio n. 26
0
    def download_from_ccd(self, filename, dst, force):
        """
        download file from ccd

        input:
            filename        path of the file to download
            dst             destination, where to store file at

        """
        SYM_SHARED = "$shared"
        SYM_HOME = "$home"

        if not validate_filename(dst):
            raise errors.InputError(message='Invalid path %s' % dst)

        if self.project:
            proj_dir = './outdir/project_%d/' % self.project
        else:
            proj_dir = '/tmp/'

        logger.info('Using project dir %s', proj_dir)

        # source, aka file to upload
        path = filename.split("/")
        root = path[0]
        logger.info('Path: %s', path)

        # location where to download from
        if root == SYM_SHARED:
            logger.info('From shared dir')
            subpath = "/".join(path[1:])
            name = os.path.join(SYM_SHARED, subpath)
            plg_id = "0"

        elif root == SYM_HOME:
            logger.info('From home dir')
            subpath = "/".join(path[1:])
            name = os.path.join(SYM_HOME, subpath)
            plg_id = "0"

        else:
            logger.info('From plg dir')
            plg = self._findPlugin(root)
            if not plg:
                raise errors.InvalidServerPath(message=root)
            logger.info('Found Plugin: %s', plg)
            plg_id = plg.id

            name = "/".join(path[1:])

        logger.info('Dwlnd src: %s', name)

        # get file
        pld = dict(fn=name)
        resp = comm.sendpacket(self,
                               op=conn.ccdlib.OP_DOWNLOAD,
                               plg=plg_id,
                               pld=pld)[-1]

        try:
            string = resp["content"]
            blob = base64.decodestring(string)
        except KeyError:
            raise Exception("Invalid payload format!")

        # store file
        if not os.path.exists(proj_dir):
            os.makedirs(proj_dir)
        # dst = "/tmp/%s" % fn
        dst = os.path.join(proj_dir, dst)
        with open(dst, "w+b") as f:
            f.write(blob)

        print("File successfully download to %s" % dst)