Exemplo n.º 1
0
def cartdel(user, req, cart_id):
	user_id = int(user)
	cnx = myemsldb_connect(myemsl_schema_versions=['1.6'])
	sql = """
	select person_id, state from myemsl.cart where cart_id = %(cart_id)i;
	"""
	sys.stderr.write("SQL: %s\n" %(sql))
	cursor = cnx.cursor()
	cursor.execute(sql, {'person_id':user_id, 'cart_id':int(cart_id)})
	rows = cursor.fetchall()
	common_allowed_states = ['email', 'downloading', 'download_expiring', 'expiring', 'ingest']
	common_allowed_states = dict([(i, 1) for i in common_allowed_states])
	state = 'expired'
	for row in rows:
		state = row[1]
		if not ((user_id in admin_users and (state == 'admin_notified' or state in common_allowed_states)) or (int(row[0]) == user_id and state in common_allowed_states)):
			return 403
	logger.debug("Cart delete %s" %(cart_id))
	if state != 'download_expiring' and state != 'expiring' or state != 'expired':
		new_state = 'expiring'
		if state == 'downloading':
			new_state = 'download_expiring'
		sql = "update myemsl.cart set state=%(new_state)s where cart_id = %(cart_id)s;"
		sys.stderr.write("SQL: %s\n" %(sql))
		cursor = cnx.cursor()
		cursor.execute(sql, {'cart_id':int(cart_id), 'new_state':new_state})
		cnx.commit()
#FIXME make configurable
		res = servicepoke.poke('/var/tmp/myemsl_cartd', 'cart_process2', 1)
	return 200
Exemplo n.º 2
0
def cartdel(user, req, cart_id):
    user_id = int(user)
    cnx = myemsldb_connect(myemsl_schema_versions=['1.6'])
    sql = """
	select person_id, state from myemsl.cart where cart_id = %(cart_id)i;
	"""
    sys.stderr.write("SQL: %s\n" % (sql))
    cursor = cnx.cursor()
    cursor.execute(sql, {'person_id': user_id, 'cart_id': int(cart_id)})
    rows = cursor.fetchall()
    common_allowed_states = [
        'email', 'downloading', 'download_expiring', 'expiring', 'ingest'
    ]
    common_allowed_states = dict([(i, 1) for i in common_allowed_states])
    state = 'expired'
    for row in rows:
        state = row[1]
        if not ((user_id in admin_users and
                 (state == 'admin_notified' or state in common_allowed_states))
                or
                (int(row[0]) == user_id and state in common_allowed_states)):
            return 403
    logger.debug("Cart delete %s" % (cart_id))
    if state != 'download_expiring' and state != 'expiring' or state != 'expired':
        new_state = 'expiring'
        if state == 'downloading':
            new_state = 'download_expiring'
        sql = "update myemsl.cart set state=%(new_state)s where cart_id = %(cart_id)s;"
        sys.stderr.write("SQL: %s\n" % (sql))
        cursor = cnx.cursor()
        cursor.execute(sql, {'cart_id': int(cart_id), 'new_state': new_state})
        cnx.commit()
        #FIXME make configurable
        res = servicepoke.poke('/var/tmp/myemsl_cartd', 'cart_process2', 1)
    return 200
Exemplo n.º 3
0
def cartresubmit(user, req, cart_id):
	user_id = int(user)
	if not user_id in admin_users:
		return 403
	cnx = myemsldb_connect(myemsl_schema_versions=['1.6'])
	sql = """
	lock table myemsl.cart;
	"""
	sys.stderr.write("SQL: %s\n" %(sql))
	cursor = cnx.cursor()
	cursor.execute(sql, {'person_id':user_id})
	sql = """
	update myemsl.cart set state='submitted', last_mtime = now() where cart_id = %(cart_id)i and state='admin_notified' returning cart_id;
	"""
	sys.stderr.write("SQL: %s\n" %(sql))
	cursor = cnx.cursor()
	cursor.execute(sql, {'cart_id':int(cart_id)})
	rows = cursor.fetchall()
	for row in rows:
		cnx.commit()
#FIXME make configurable
		res = servicepoke.poke('/var/tmp/myemsl_cartd', 'cart_process2', 1)
		return 200
	return 404
Exemplo n.º 4
0
def cartsubmit(user, req, cart_id, email_addr):
	user_id = int(user)
	cnx = myemsldb_connect(myemsl_schema_versions=['1.6'])
	sql = """
	select person_id, state = 'ingest' from myemsl.cart where person_id = %(person_id)i and cart_id = %(cart_id)i;
	"""
	sys.stderr.write("SQL: %s\n" %(sql))
	cursor = cnx.cursor()
	cursor.execute(sql, {'person_id':user_id, 'cart_id':int(cart_id)})
	rows = cursor.fetchall()
	for row in rows:
		if int(row[0]) != user_id or row[1] != True:
			return 403
	logger.debug("Cart submit %s" %(cart_id))
	sql = """
	update myemsl.cart set last_mtime = now(), submit_time = now(), state='submitted', email_address=%(email_addr)s where cart_id = %(cart_id)s;
	"""
	sys.stderr.write("SQL: %s\n" %(sql))
	cursor = cnx.cursor()
	cursor.execute(sql, {'cart_id':int(cart_id), 'email_addr':email_addr})
	cnx.commit()
#FIXME make configurable
	res = servicepoke.poke('/var/tmp/myemsl_cartd', 'cart_process2', 1)
	return 200
Exemplo n.º 5
0
def cartresubmit(user, req, cart_id):
    user_id = int(user)
    if not user_id in admin_users:
        return 403
    cnx = myemsldb_connect(myemsl_schema_versions=['1.6'])
    sql = """
	lock table myemsl.cart;
	"""
    sys.stderr.write("SQL: %s\n" % (sql))
    cursor = cnx.cursor()
    cursor.execute(sql, {'person_id': user_id})
    sql = """
	update myemsl.cart set state='submitted', last_mtime = now() where cart_id = %(cart_id)i and state='admin_notified' returning cart_id;
	"""
    sys.stderr.write("SQL: %s\n" % (sql))
    cursor = cnx.cursor()
    cursor.execute(sql, {'cart_id': int(cart_id)})
    rows = cursor.fetchall()
    for row in rows:
        cnx.commit()
        #FIXME make configurable
        res = servicepoke.poke('/var/tmp/myemsl_cartd', 'cart_process2', 1)
        return 200
    return 404
Exemplo n.º 6
0
def cartsubmit(user, req, cart_id, email_addr):
    user_id = int(user)
    cnx = myemsldb_connect(myemsl_schema_versions=['1.6'])
    sql = """
	select person_id, state = 'ingest' from myemsl.cart where person_id = %(person_id)i and cart_id = %(cart_id)i;
	"""
    sys.stderr.write("SQL: %s\n" % (sql))
    cursor = cnx.cursor()
    cursor.execute(sql, {'person_id': user_id, 'cart_id': int(cart_id)})
    rows = cursor.fetchall()
    for row in rows:
        if int(row[0]) != user_id or row[1] != True:
            return 403
    logger.debug("Cart submit %s" % (cart_id))
    sql = """
	update myemsl.cart set last_mtime = now(), submit_time = now(), state='submitted', email_address=%(email_addr)s where cart_id = %(cart_id)s;
	"""
    sys.stderr.write("SQL: %s\n" % (sql))
    cursor = cnx.cursor()
    cursor.execute(sql, {'cart_id': int(cart_id), 'email_addr': email_addr})
    cnx.commit()
    #FIXME make configurable
    res = servicepoke.poke('/var/tmp/myemsl_cartd', 'cart_process2', 1)
    return 200
Exemplo n.º 7
0
#!/usr/bin/python
import servicepoke
error = servicepoke.poke('/tmp/poke.sock', 'foo')
if error:
	print error
Exemplo n.º 8
0
#!/usr/bin/python
import servicepoke
error = servicepoke.poke('/tmp/poke.sock', 'foo')
if error:
    print error
Exemplo n.º 9
0
def notify(transaction, writer):
    # FIXME make configurable
    res = servicepoke.poke("/var/tmp/myemsl_elasticsearch", "simple_items", 1)
    transaction = int(transaction)
    sql = """
select type, name, p.group_id is not NULL as proposal from (with recursive t(group_id) as (select group_id from myemsl.group_items, myemsl.files where transaction=%(trans)s and myemsl.group_items.item_id = myemsl.files.item_id group by group_id
union                                 
select parent_id as group_id from myemsl.subgroups as s, t where s.child_id = t.group_id
) select t.group_id, type, name from t, myemsl.groups as g where t.group_id = g.group_id
) as g left join eus.proposals as p on p.group_id = g.group_id;
	"""
    group_ids_for_item_id_sql = """
SELECT
  type,
  name,
  p.group_id is not NULL AS proposal
FROM (
  WITH RECURSIVE 
    t(group_id)
  AS (
    SELECT
      group_id
    FROM
      myemsl.group_items 
    WHERE
      myemsl.group_items.item_id = %(item_id)s 
    GROUP BY
      group_id                          
    UNION                                 
    SELECT
      parent_id AS group_id
    FROM
      myemsl.subgroups AS s,
      t
    WHERE
      s.child_id = t.group_id
  )
  SELECT
    t.group_id,
    type,
    name
  FROM 
    t,
    myemsl.groups AS g
  WHERE
    t.group_id = g.group_id
) as g
LEFT JOIN
  eus.proposals AS p ON p.group_id = g.group_id;
"""
    sys.stderr.write("SQL: %s\n" % (sql))
    cnx = myemsldb_connect(myemsl_schema_versions=["1.0"])
    cursor = cnx.cursor()
    cursor.execute(sql, {"trans": transaction})
    rows = cursor.fetchall()
    groups = []
    proposals = []
    for row in rows:
        type = row[0]
        name = row[1]
        is_proposal = row[2]
        groups.append([type, name])
        if is_proposal:
            proposals.append(name)
    sql = """
	select subdir, name, item_id from myemsl.files where transaction=%(trans)s;
	"""
    cursor = cnx.cursor()
    cursor.execute(sql, {"trans": transaction})
    rows = cursor.fetchall()
    filenames = []
    file_groups = {}
    for row in rows:
        subdir = row[0]
        name = row[1]
        if subdir == None:
            subdir = ""
        if subdir != "":
            subdir = "%s/" % (subdir)
        cursor = cnx.cursor()
        cursor.execute(group_ids_for_item_id_sql, {"item_id": row[2]})
        file_groups["%s%s" % (subdir, name)] = cursor.fetchall()
        filenames.append("%s%s" % (subdir, name))
    sql = """
	select submitter from myemsl.transactions where transaction=%(trans)s;
	"""
    cursor = cnx.cursor()
    cursor.execute(sql, {"trans": transaction})
    rows = cursor.fetchall()
    submitter = None
    for row in rows:
        submitter = row[0]
    nntp = nntplib.NNTP(config.get("notification", "nntp_server"))
    f = tempfile.TemporaryFile(mode="w+")
    f.write("From: svc-myemsl <*****@*****.**>\n")
    f.write("Newsgroups: local.myemsl.incoming.notifications\n")
    f.write("Subject: %s\n" % (transaction))
    f.write("Mime-Version: 1.0\n")
    f.write("Content-Type: text/plain; charset=US-ASCII\n")
    f.write("Content-Transfer-Encoding: 7bit\n\n")
    f.write('<?xml version="1.0"?>\n')
    f.write('<myemsl version="1.0.0">\n')
    f.write("  <submitter>%s</submitter>\n" % (submitter))
    f.write("  <transaction>%s</transaction>\n" % (transaction))
    f.write("  <groups>\n")
    for (type, name) in groups:
        f.write("    <group><type>%s</type><name>%s</name></group>\n" % (type, name))
    f.write("  </groups>\n")
    f.write("  <proposals>\n")
    for name in proposals:
        f.write("    <proposal>%s</proposal>\n" % (name))
    f.write("  </proposals>\n")
    f.write("  <files>\n")
    for n in filenames:
        f.write("    <file>\n      <name>%s</name>\n      <groups>\n" % (n))
        for (type, name, is_proposal) in file_groups[n]:
            f.write("        <group><type>%s</type><name>%s</name></group>\n" % (type, name))
        f.write("      </groups>\n    </file>\n")
    f.write("  </files>\n")
    f.write("</myemsl>\n")
    f.seek(0)
    nntp.post(f)
    writer.write("OK")
    return 0