当前位置: 首页>>代码示例>>Python>>正文


Python Experiment.public_access_implies_distribution方法代码示例

本文整理汇总了Python中tardis.tardis_portal.models.Experiment.public_access_implies_distribution方法的典型用法代码示例。如果您正苦于以下问题:Python Experiment.public_access_implies_distribution方法的具体用法?Python Experiment.public_access_implies_distribution怎么用?Python Experiment.public_access_implies_distribution使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tardis.tardis_portal.models.Experiment的用法示例。


在下文中一共展示了Experiment.public_access_implies_distribution方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: has_experiment_download_access

# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import public_access_implies_distribution [as 别名]
def has_experiment_download_access(request, experiment_id):
    if Experiment.safe.owned_and_shared(request) \
                      .filter(id=experiment_id) \
                      .exists():
        return True
    else:
        exp = Experiment.objects.get(id=experiment_id)
        return Experiment.public_access_implies_distribution(exp.public_access)
开发者ID:JMSS-IT-11-2012,项目名称:mytardis,代码行数:10,代码来源:decorators.py

示例2: clean

# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import public_access_implies_distribution [as 别名]
    def clean(self):
        cleaned_data = super(RightsForm, self).clean()
        public_access = cleaned_data.get("public_access")
        license_ = cleaned_data.get("license")

        if license_ is None:
            # Only data which is not distributed can have no explicit licence
            suitable = not Experiment.public_access_implies_distribution(public_access)
        else:
            suitable = license_ in License.get_suitable_licenses(public_access)

        if not suitable:
            raise forms.ValidationError("Selected license it not suitable " + "for public access level.")

        return cleaned_data
开发者ID:JMSS-IT-11-2012,项目名称:mytardis,代码行数:17,代码来源:forms.py

示例3: run

# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import public_access_implies_distribution [as 别名]
def run():
    if getpass.getuser() != "mytardis" or "SUDO_USER" not in os.environ:
        print "Usage: sudo -u mytardis _datafiledescriptord " + \
            "mytardis_install_dir auth_provider " + \
            "socket_path exp_id datafile_id"
        sys.exit(1)

    if len(sys.argv) < 6:
        print "Usage: sudo -u mytardis _datafiledescriptord " + \
            "mytardis_install_dir auth_provider " + \
            "socket_path exp_id datafile_id"
        sys.exit(1)

    _mytardis_install_dir = sys.argv[1].strip('"')
    _auth_provider = sys.argv[2]
    _socket_path = sys.argv[3]
    _experiment_id = int(sys.argv[4])
    _datafile_id = int(sys.argv[5])

    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    try:
        os.remove(_socket_path)
    except OSError:
        pass
    sock.bind(_socket_path)
    os.chmod(_socket_path, 0666)
    sock.listen(1)
    conn, addr = sock.accept()

    utils.setup_mytardis_paths(_mytardis_install_dir)

    from tardis.tardis_portal.models import Dataset_File, Experiment

    found_user = False
    mytardis_user = None
    exp_public = False
    exp_owned_or_shared = False
    staff_or_superuser = False
    found_datafile_in_experiment = False
    try:
        mytardis_user = utils.get_user(os.environ['SUDO_USER'], _auth_provider)
        # logger.debug("Primary MyTardis username: " + mytardis_user.username)
        found_user = True
        staff_or_superuser = mytardis_user.is_staff or \
            mytardis_user.is_superuser
        if not staff_or_superuser:
            exp = Experiment.objects.get(id=_experiment_id)
            exp_public = Experiment.public_access_implies_distribution(
                exp.public_access)
            experiments_owned_or_shared = Experiment \
                .safe.owned_and_shared(mytardis_user)
            exp_owned_or_shared = experiments_owned_or_shared \
                .filter(id=_experiment_id).exists()
            for df in exp.get_datafiles():
                if df.id == _datafile_id:
                    found_datafile_in_experiment = True
                    break
        df = Dataset_File.objects.get(id=_datafile_id)
        r = df.get_preferred_replica()
        filepath = r.get_absolute_filepath()

        # The following line blocks, waiting for client to start up
        # and send its request:
        file_descriptor_request = conn.recv(1024)
        if staff_or_superuser or (found_datafile_in_experiment and
                                  (exp_public or exp_owned_or_shared)):
            fds = [file(filepath, 'rb')]
            message = "Success"
        elif not found_datafile_in_experiment:
            fds = []
            message = "Datafile (ID %s) does not belong " + \
                "to experiment (ID %s)." % \
                (str(_datafile_id), str(_experiment_id))
        else:
            fds = []
            # message = "Access to datafile %s denied for user %s." %
            # (str(_datafile_id),os.environ['SUDO_USER'])
            message = "Access denied for user " + \
                os.environ['SUDO_USER'] + " " + \
                str(sys.argv)
        fdsend.sendfds(conn, message, fds=fds)
    except ObjectDoesNotExist:
        message = "User " + os.environ['SUDO_USER'] + \
            " was not found in MyTardis."
        fdsend.sendfds(conn, message, fds=[])
    except:
        message = traceback.format_exc()
        fdsend.sendfds(conn, message, fds=[])

    conn.close()

    try:
        os.remove(_socket_path)
    except OSError:
        pass
开发者ID:grischa,项目名称:mytardisfs,代码行数:97,代码来源:datafiledescriptord.py

示例4: run

# 需要导入模块: from tardis.tardis_portal.models import Experiment [as 别名]
# 或者: from tardis.tardis_portal.models.Experiment import public_access_implies_distribution [as 别名]
def run():
    if getpass.getuser() != "mytardis" or "SUDO_USER" not in os.environ:
        print "Usage: sudo -u mytardis _datafiledescriptord " + \
            "mytardis_install_dir auth_provider " + \
            "socket_path exp_id datafile_id"
        sys.exit(1)

    if len(sys.argv) < 6:
        print "Usage: sudo -u mytardis _datafiledescriptord " + \
            "mytardis_install_dir auth_provider " + \
            "socket_path exp_id datafile_id"
        sys.exit(1)

    _mytardis_install_dir = sys.argv[1].strip('"')
    _auth_provider = sys.argv[2]
    _socket_path = sys.argv[3]
    _experiment_id = int(sys.argv[4])
    _datafile_id = int(sys.argv[5])

    sock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
    try:
        os.remove(_socket_path)
    except OSError:
        pass
    sock.bind(_socket_path)
    os.chmod(_socket_path, 0666)
    sock.listen(1)
    conn, addr = sock.accept()

    sys.path.append(_mytardis_install_dir)
    for egg in os.listdir(os.path.join(_mytardis_install_dir, "eggs")):
        sys.path.append(os.path.join(_mytardis_install_dir, "eggs", egg))

    os.environ.setdefault("DJANGO_SETTINGS_MODULE", 'tardis.settings')

    from tardis.tardis_portal.models import DataFile, Experiment
    from tardis.tardis_portal.models import UserAuthentication

    found_user = False
    mytardis_user = None
    exp_public = False
    exp_owned_or_shared = False
    staff_or_superuser = False
    found_datafile_in_experiment = False
    try:
        user_auth = UserAuthentication.objects\
            .get(username=os.environ['SUDO_USER'],
                 authenticationMethod=_auth_provider)
        mytardis_user = user_auth.userProfile.user
        # logger.debug("Primary MyTardis username: " + mytardis_user.username)
        found_user = True
        staff_or_superuser = mytardis_user.is_staff or \
            mytardis_user.is_superuser
        if not staff_or_superuser:
            exp = Experiment.objects.get(id=_experiment_id)
            exp_public = Experiment.public_access_implies_distribution(
                exp.public_access)
            experiments_owned_or_shared = Experiment \
                .safe.owned_and_shared(mytardis_user)
            exp_owned_or_shared = experiments_owned_or_shared \
                .filter(id=_experiment_id).exists()
            for df in exp.get_datafiles():
                if df.id == _datafile_id:
                    found_datafile_in_experiment = True
                    break
        df = DataFile.objects.get(id=_datafile_id)
        fileobject = df.file_object

        # The following line blocks, waiting for client to start up
        # and send its request:
        file_descriptor_request = conn.recv(1024)
        if staff_or_superuser or (found_datafile_in_experiment and
                                  (exp_public or exp_owned_or_shared)):
            fds = [fileobject]
            message = "Success"
        elif not found_datafile_in_experiment:
            fds = []
            message = "Datafile (ID %s) does not belong " + \
                "to experiment (ID %s)." % \
                (str(_datafile_id), str(_experiment_id))
        else:
            fds = []
            # message = "Access to datafile %s denied for user %s." %
            # (str(_datafile_id),os.environ['SUDO_USER'])
            message = "Access denied for user " + \
                os.environ['SUDO_USER'] + " " + \
                str(sys.argv)
        fdsend.sendfds(conn, message, fds=fds)
    except ObjectDoesNotExist:
        # FIXME: It could actually be the datafile which
        # is not found.
        message = "User " + os.environ['SUDO_USER'] + \
            " was not found in MyTardis " \
            "for authentication method " + _auth_provider
        fdsend.sendfds(conn, message, fds=[])
    except:
        message = traceback.format_exc()
        fdsend.sendfds(conn, message, fds=[])

    conn.close()
#.........这里部分代码省略.........
开发者ID:monash-merc,项目名称:mytardisfs,代码行数:103,代码来源:datafiledescriptord.py


注:本文中的tardis.tardis_portal.models.Experiment.public_access_implies_distribution方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。