Python os.path.pardir() Examples

The following are 30 code examples of os.path.pardir(). You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may also want to check out all available functions/classes of the module os.path , or try the search function .
Example #1
Source File: mcafee_esm_case_polling.py    From resilient-community-apps with MIT License 6 votes vote down vote up
def build_incident_dto(self, headers, case_id):
        current_path = os.path.dirname(os.path.realpath(__file__))
        default_temp_file = join(current_path, pardir, "data/templates/esm_incident_mapping.jinja")
        template_file = self.options.get("incident_template", default_temp_file)

        try:
            with open(template_file, 'r') as template:
                log.debug("Reading template file")

                case_details = case_get_case_detail(self.options, headers, case_id)
                log.debug("Case details in dict form: {}".format(case_details))

                incident_template = template.read()

                return template_functions.render(incident_template, case_details)

        except jinja2.exceptions.TemplateSyntaxError:
            log.info("'incident_template' is not set correctly in config file.") 
Example #2
Source File: res_utils.py    From android-project-combine with Apache License 2.0 6 votes vote down vote up
def find_package_name_dir_up(parent_path):
    for file_name in listdir(parent_path):
        if isdir(file_name):
            continue

        if file_name == 'AndroidManifest.xml':
            for line in open(join(parent_path, file_name), 'r'):
                package_name_re_result = PACKAGE_NAME_RE.search(line)
                if package_name_re_result is not None:
                    return package_name_re_result.groups()[0]

        if file_name == 'build.gradle':
            for line in open(join(parent_path, file_name), 'r'):
                application_id_re_result = APPLICATION_ID_RE.search(line)
                if application_id_re_result is not None:
                    return application_id_re_result.groups()[0]

    return find_package_name_dir_up(abspath(join(parent_path, pardir))) 
Example #3
Source File: model.py    From EvilOSX with GNU General Public License v3.0 6 votes vote down vote up
def wrap_loader(loader_name, loader_options, payload):
        """:return: The loader which will load the (configured and encrypted) payload.

        :type loader_name: str
        :type loader_options: dict
        :type payload: str
        :rtype: str
        """
        loader_path = path.realpath(path.join(
            path.dirname(__file__), path.pardir, "bot", "loaders", loader_name, "install.py")
        )
        loader = ""

        with open(loader_path, "r") as input_file:
            for line in input_file:
                if line.startswith("LOADER_OPTIONS = "):
                    loader += "LOADER_OPTIONS = {}\n".format(str(loader_options))
                elif line.startswith("PAYLOAD_BASE64 = "):
                    loader += "PAYLOAD_BASE64 = \"{}\"\n".format(b64encode(payload.encode()).decode())
                else:
                    loader += line

        return loader 
Example #4
Source File: tests.py    From weibo-analysis-system with MIT License 6 votes vote down vote up
def getComment(request):
        pass
        # if request.method == "GET":
        # text = request.GET.get("commentId")
        # resp = list(Target.objects.values('uid', 'cookie', 'add_time'))
        # uid = int(resp[0]["uid"])
        # cookie = {"Cookie": resp[0]["cookie"]}
        # wb = Weibo(uid,cookie)
        # print("数据库不存在该评论,正在爬虫生成")
        # mm = wb.get_comment_info(text)


      
# Create your tests here.
# with urllib.request.urlopen("https://wx2.sinaimg.cn/large/" + '893ea4cely1g2kbqkzuzyj21hc0u0q9p', timeout=30) as response, open("893ea4cely1g2kbqkzuzyj21hc0u0q9p.jpg", 'wb') as f_save:
#     f_save.write(response.read())
#     f_save.flush()
#     f_save.close()
# print (path.dirname(path.abspath("__file__")))
# print (path.pardir)
# print (path.join(path.dirname("__file__"),path.pardir))
# print (path.abspath(path.join(path.dirname("__file__"),path.pardir)))
# print (path.abspath(path.join(os.getcwd(), "../../webview/static/"))) 
Example #5
Source File: gui.py    From EvilOSX with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self):
        super(_HomeTab, self).__init__()

        self._layout = QHBoxLayout()
        self.setLayout(self._layout)

        message_label = QLabel("""\
        Welcome to <b>EvilOSX</b>:<br/>
        An evil RAT (Remote Administration Tool) for macOS / OS X.<br/><br/><br/>

        Author: Marten4n6<br/>
        License: GPLv3<br/>
        Version: <b>{}</b>
        """.format(VERSION))
        logo_label = QLabel()

        logo_path = path.join(path.dirname(__file__), path.pardir, path.pardir, "data", "images", "logo_334x600.png")
        logo_label.setPixmap(QPixmap(logo_path))

        self._layout.setAlignment(Qt.AlignCenter)
        self._layout.setSpacing(50)
        self._layout.addWidget(message_label)
        self._layout.addWidget(logo_label) 
Example #6
Source File: unittestgui.py    From spyder-unittest with MIT License 6 votes vote down vote up
def test():
    """
    Run widget test.

    Show the unittest widgets, configured so that our own tests are run when
    the user clicks "Run tests".
    """
    from spyder.utils.qthelpers import qapplication
    app = qapplication()
    widget = UnitTestWidget(None)

    # set wdir to .../spyder_unittest
    wdir = osp.abspath(osp.join(osp.dirname(__file__), osp.pardir))
    widget.config = Config('pytest', wdir)

    # add wdir's parent to python path, so that `import spyder_unittest` works
    rootdir = osp.abspath(osp.join(wdir, osp.pardir))
    widget.pythonpath = [rootdir]

    widget.resize(800, 600)
    widget.show()
    sys.exit(app.exec_()) 
Example #7
Source File: microsoft_security_graph_alerts_integrations.py    From resilient-community-apps with MIT License 6 votes vote down vote up
def build_incident_dto(alert, custom_temp_file=None):
    current_path = os.path.dirname(os.path.realpath(__file__))
    if custom_temp_file:
        template_file = custom_temp_file
    else:
        default_temp_file = join(current_path, pardir, "data/templates/msg_incident_mapping.jinja")
        template_file = default_temp_file

    try:
        with open(template_file, 'r') as template:
            log.debug("Reading template file")
            incident_template = template.read()

            return template_functions.render(incident_template, alert)

    except jinja2.exceptions.TemplateSyntaxError:
        log.info("'incident_template' is not set correctly in config file.") 
Example #8
Source File: api.py    From indra with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def _load_data():
    """Load the data from the csv in data.

    The "gene_id" is the Entrez gene id, and the "approved_symbol" is the
    standard gene symbol. The "hms_id" is the LINCS ID for the drug.

    Returns
    -------
    data : list[dict]
        A list of dicts of row values keyed by the column headers extracted from
        the csv file, described above.
    """
    # Get the cwv reader object.
    csv_path = path.join(HERE, path.pardir, path.pardir, 'resources',
                         DATAFILE_NAME)
    data_iter = list(read_unicode_csv(csv_path))

    # Get the headers.
    headers = data_iter[0]

    # For some reason this heading is oddly formatted and inconsistent with the
    # rest, or with the usual key-style for dicts.
    headers[headers.index('Approved.Symbol')] = 'approved_symbol'
    return [{header: val for header, val in zip(headers, line)}
            for line in data_iter[1:]] 
Example #9
Source File: test_toolchain.py    From calmjs with GNU General Public License v2.0 6 votes vote down vote up
def test_toolchain_standard_build_dir_remapped(self):
        """
        This can either be caused by relative paths or symlinks.  Will
        result in the manually specified build_dir being remapped to its
        real location
        """

        fake = mkdtemp(self)
        real = mkdtemp(self)
        real_base = basename(real)
        spec = Spec()
        spec['build_dir'] = join(fake, pardir, real_base)

        with pretty_logging(stream=StringIO()) as s:
            with self.assertRaises(NotImplementedError):
                self.toolchain(spec)

        self.assertIn("realpath of 'build_dir' resolved to", s.getvalue())
        self.assertEqual(spec['build_dir'], real) 
Example #10
Source File: loaders.py    From misp42splunk with GNU Lesser General Public License v3.0 6 votes vote down vote up
def split_template_path(template):
    """Split a path into segments and perform a sanity check.  If it detects
    '..' in the path it will raise a `TemplateNotFound` error.
    """
    pieces = []
    for piece in template.split('/'):
        if path.sep in piece \
           or (path.altsep and path.altsep in piece) or \
           piece == path.pardir:
            raise TemplateNotFound(template)
        elif piece and piece != '.':
            pieces.append(piece)
    return pieces 
Example #11
Source File: slack_common.py    From resilient-community-apps with MIT License 5 votes vote down vote up
def get_template_file_path(path):
    """
    Get template file path.
    :param path:
    :return: template_file_path
    """
    if not isinstance(path, string_types):
        raise ValueError("Variable 'path' type must be a string {}".format(path))

    current_path = os.path.dirname(os.path.realpath(__file__))
    template_file_path = join(current_path, pardir, path)
    return template_file_path 
Example #12
Source File: loaders.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def split_template_path(template):
    """Split a path into segments and perform a sanity check.  If it detects
    '..' in the path it will raise a `TemplateNotFound` error.
    """
    pieces = []
    for piece in template.split('/'):
        if path.sep in piece \
           or (path.altsep and path.altsep in piece) or \
           piece == path.pardir:
            raise TemplateNotFound(template)
        elif piece and piece != '.':
            pieces.append(piece)
    return pieces 
Example #13
Source File: config.py    From flyingpigeon with Apache License 2.0 5 votes vote down vote up
def top_level(self):
        """ return the top level directory of a WPS bird """
        return abspath(join(self._base, pardir)) 
Example #14
Source File: test_Resilient_Event_Subscriber.py    From resilient-community-apps with MIT License 5 votes vote down vote up
def test_get_template_file(self):
        current_path = os.path.dirname(os.path.realpath(__file__))
        default_template = join(current_path, pardir, "fn_mcafee_opendxl/data/templates/_mcafee_event_epo_threat_response.jinja2")

        expected_dict = {
            "/mcafee/event/epo/threat/response": default_template
        }
        actual_dict = get_topic_template_dict()

        expected_dict["/mcafee/event/epo/threat/response"] = os.path.abspath(expected_dict.get("/mcafee/event/epo/threat/response"))
        actual_dict["/mcafee/event/epo/threat/response"] = os.path.abspath(actual_dict.get("/mcafee/event/epo/threat/response"))

        assert actual_dict == expected_dict 
Example #15
Source File: loaders.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def split_template_path(template):
    """Split a path into segments and perform a sanity check.  If it detects
    '..' in the path it will raise a `TemplateNotFound` error.
    """
    pieces = []
    for piece in template.split('/'):
        if path.sep in piece \
           or (path.altsep and path.altsep in piece) or \
           piece == path.pardir:
            raise TemplateNotFound(template)
        elif piece and piece != '.':
            pieces.append(piece)
    return pieces 
Example #16
Source File: loaders.py    From data with GNU General Public License v3.0 5 votes vote down vote up
def split_template_path(template):
    """Split a path into segments and perform a sanity check.  If it detects
    '..' in the path it will raise a `TemplateNotFound` error.
    """
    pieces = []
    for piece in template.split('/'):
        if path.sep in piece \
           or (path.altsep and path.altsep in piece) or \
           piece == path.pardir:
            raise TemplateNotFound(template)
        elif piece and piece != '.':
            pieces.append(piece)
    return pieces 
Example #17
Source File: loaders.py    From PhonePi_SampleServer with MIT License 5 votes vote down vote up
def split_template_path(template):
    """Split a path into segments and perform a sanity check.  If it detects
    '..' in the path it will raise a `TemplateNotFound` error.
    """
    pieces = []
    for piece in template.split('/'):
        if path.sep in piece \
           or (path.altsep and path.altsep in piece) or \
           piece == path.pardir:
            raise TemplateNotFound(template)
        elif piece and piece != '.':
            pieces.append(piece)
    return pieces 
Example #18
Source File: res_utils.py    From android-project-combine with Apache License 2.0 5 votes vote down vote up
def find_package_name(subdir):
    res_path = abspath(join(subdir, pardir))
    parent_path = abspath(join(res_path, pardir))
    return find_package_name_dir_up(parent_path) 
Example #19
Source File: loaders.py    From planespotter with MIT License 5 votes vote down vote up
def split_template_path(template):
    """Split a path into segments and perform a sanity check.  If it detects
    '..' in the path it will raise a `TemplateNotFound` error.
    """
    pieces = []
    for piece in template.split('/'):
        if path.sep in piece \
           or (path.altsep and path.altsep in piece) or \
           piece == path.pardir:
            raise TemplateNotFound(template)
        elif piece and piece != '.':
            pieces.append(piece)
    return pieces 
Example #20
Source File: utils.py    From convert-eprime with MIT License 5 votes vote down vote up
def get_config_path():
    """
    Returns the path to test datasets, terminated with separator.

    Based on function by Yaroslav Halchenko used in Neurosynth Python package.
    """
    return abspath(join(dirname(__file__), pardir, pardir, 'config_files') + sep) 
Example #21
Source File: utils.py    From convert-eprime with MIT License 5 votes vote down vote up
def get_resource_path():
    """
    Based on function by Yaroslav Halchenko used in Neurosynth Python package.
    """
    return abspath(join(dirname(__file__), pardir, 'resources') + sep) 
Example #22
Source File: test_utils.py    From calmjs.parse with MIT License 5 votes vote down vote up
def test_find_same_prefix(self):
        base = tempfile.mktemp()
        src = join(base, 'basesrc', 'source.js')
        tgt = join(base, 'basetgt', 'target.js')
        self.assertEqual([pardir, 'basetgt', 'target.js'], utils.normrelpath(
            src, tgt).split(sep)) 
Example #23
Source File: test_utils.py    From calmjs.parse with MIT License 5 votes vote down vote up
def test_find_double_parent(self):
        base = tempfile.mktemp()
        root = join(base, 'file.js')
        nested = join(base, 'src', 'dir', 'blahfile.js')

        self.assertEqual([pardir, pardir, 'file.js'], utils.normrelpath(
            nested, root).split(sep))
        self.assertEqual(['src', 'dir', 'blahfile.js'], utils.normrelpath(
            root, nested).split(sep)) 
Example #24
Source File: test_utils.py    From calmjs.parse with MIT License 5 votes vote down vote up
def test_find_common_same_base_parents_common(self):
        base = tempfile.mktemp()
        source = join(base, 'src', 'file.js')
        source_min = join(base, 'build', 'file.min.js')
        source_map = join(base, 'build', 'file.min.js.map')

        # mapping from source_map to source
        self.assertEqual([pardir, 'src', 'file.js'], utils.normrelpath(
            source_map, source).split(sep))
        # for pointing from source_map.source to the source_min
        self.assertEqual('file.min.js', utils.normrelpath(
            source_map, source_min)) 
Example #25
Source File: loaders.py    From luci-py with Apache License 2.0 5 votes vote down vote up
def split_template_path(template):
    """Split a path into segments and perform a sanity check.  If it detects
    '..' in the path it will raise a `TemplateNotFound` error.
    """
    pieces = []
    for piece in template.split('/'):
        if path.sep in piece \
           or (path.altsep and path.altsep in piece) or \
           piece == path.pardir:
            raise TemplateNotFound(template)
        elif piece and piece != '.':
            pieces.append(piece)
    return pieces 
Example #26
Source File: loaders.py    From luci-py with Apache License 2.0 5 votes vote down vote up
def split_template_path(template):
    """Split a path into segments and perform a sanity check.  If it detects
    '..' in the path it will raise a `TemplateNotFound` error.
    """
    pieces = []
    for piece in template.split('/'):
        if path.sep in piece \
           or (path.altsep and path.altsep in piece) or \
           piece == path.pardir:
            raise TemplateNotFound(template)
        elif piece and piece != '.':
            pieces.append(piece)
    return pieces 
Example #27
Source File: loaders.py    From luci-py with Apache License 2.0 5 votes vote down vote up
def split_template_path(template):
    """Split a path into segments and perform a sanity check.  If it detects
    '..' in the path it will raise a `TemplateNotFound` error.
    """
    pieces = []
    for piece in template.split('/'):
        if path.sep in piece \
           or (path.altsep and path.altsep in piece) or \
           piece == path.pardir:
            raise TemplateNotFound(template)
        elif piece and piece != '.':
            pieces.append(piece)
    return pieces 
Example #28
Source File: loaders.py    From luci-py with Apache License 2.0 5 votes vote down vote up
def split_template_path(template):
    """Split a path into segments and perform a sanity check.  If it detects
    '..' in the path it will raise a `TemplateNotFound` error.
    """
    pieces = []
    for piece in template.split('/'):
        if path.sep in piece \
           or (path.altsep and path.altsep in piece) or \
           piece == path.pardir:
            raise TemplateNotFound(template)
        elif piece and piece != '.':
            pieces.append(piece)
    return pieces 
Example #29
Source File: loaders.py    From luci-py with Apache License 2.0 5 votes vote down vote up
def split_template_path(template):
    """Split a path into segments and perform a sanity check.  If it detects
    '..' in the path it will raise a `TemplateNotFound` error.
    """
    pieces = []
    for piece in template.split('/'):
        if path.sep in piece \
           or (path.altsep and path.altsep in piece) or \
           piece == path.pardir:
            raise TemplateNotFound(template)
        elif piece and piece != '.':
            pieces.append(piece)
    return pieces 
Example #30
Source File: loaders.py    From Carnets with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def split_template_path(template):
    """Split a path into segments and perform a sanity check.  If it detects
    '..' in the path it will raise a `TemplateNotFound` error.
    """
    pieces = []
    for piece in template.split('/'):
        if path.sep in piece \
           or (path.altsep and path.altsep in piece) or \
           piece == path.pardir:
            raise TemplateNotFound(template)
        elif piece and piece != '.':
            pieces.append(piece)
    return pieces