Commit 336fc868 authored by LE GAC Renaud's avatar LE GAC Renaud
Browse files

Update deploy.py to add option commit, remove otpion all and to minimize input requests.

parent 6f0e5799
......@@ -43,7 +43,14 @@
EXAMPLE
> cd ...limbra/scripts
> run -S test_limbra script deploy.py data/my_institute.csv
Dry run:
> run -S test_limbra script deploy.py -t data/my_institute.csv
> run -S test_limbra script deploy.py -a data/my_institute.csv
> run -S test_limbra script deploy.py -H data/my_institute.csv
Commit change in the database:
> run -S test_limbra script deploy.py -taHc data/my_institute.csv
AUTHOR
R. Le Gac -- Jul 2017
......@@ -76,19 +83,15 @@ def create_affiliation(opt):
opt (argparse.Namespace): options
"""
rep = raw_input("\tDo you want to create affiliation keys [y/N]: ")
if rep != "y":
return
rep = raw_input("\tEnter the inspirehep identifier for your institute: ")
if not rep.isdigit():
aff = raw_input("\tEnter the inspirehep identifier for your institute: ")
if not aff.isdigit():
print "\t\tERROR: invalid answer!"
# ........................................................................
#
# get and process inspirehep record
#
record = load_record("inspirehep.net", int(rep))
record = load_record("inspirehep.net", aff)
# extract keys defining the affiliation
# u and v are the main keys use in inspirehep and cds
......@@ -108,14 +111,6 @@ def create_affiliation(opt):
if not is_key_add:
print "\t\tAffiliation keys already exist!"
# ........................................................................
#
# commit
#
rep = raw_input("\n\tDo you want to commit database changes [y/N]: ")
if rep == "y":
db.commit()
def create_harvesters(opt, dfi, dfh):
"""Create the harvesters in the database.
......@@ -142,10 +137,6 @@ def create_harvesters(opt, dfi, dfh):
- collection
"""
rep = raw_input("\tDo you want to create harvesters [y/N]: ")
if rep != "y":
return
# ........................................................................
#
# check that all collaborations are defined
......@@ -271,7 +262,7 @@ def create_harvesters(opt, dfi, dfh):
data["controller"] = "articles"
li = ["a %s" % el.strip() for el in people.split(",")]
collection = "find (%s) and tc p and not tc c " % " or ".join(li)
collection = "find %s and tc p and not tc c " % " or ".join(li)
if len(row.hal_hidden) > 0:
collection = collection.replace("find", "find cc Hal Hidden")
......@@ -283,7 +274,7 @@ def create_harvesters(opt, dfi, dfh):
# proceeding
data["controller"] = "proceedings"
collection = "find (%s) and tc c " % " or ".join(li)
collection = "find %s and tc c " % " or ".join(li)
if len(row.hal_hidden) > 0:
collection = collection.replace("find", "find cc Hal Hidden")
......@@ -294,14 +285,6 @@ def create_harvesters(opt, dfi, dfh):
continue
# ........................................................................
#
# commit
#
rep = raw_input("\n\tDo you want to commit database changes [y/N]: ")
if rep == "y":
db.commit()
def create_teams_projects(opt, dfi):
"""Create the teams / projects structure in the database.
......@@ -311,10 +294,6 @@ def create_teams_projects(opt, dfi):
dfi (pandas.DataFrame): institute parameter
"""
rep = raw_input("\tDo you want to create teams/projects [y/N]: ")
if rep != "y":
return
# ........................................................................
#
# teams / projects
......@@ -359,14 +338,6 @@ def create_teams_projects(opt, dfi):
else:
print "\t\tRelation %s/%s already exist!" % (team, project)
# ........................................................................
#
# commit
#
rep = raw_input("\n\tDo you want to commit database changes [y/N]: ")
if rep == "y":
db.commit()
def harvesters(opt):
"""Create the DataFrame with the harvesters definitions.
......@@ -392,6 +363,10 @@ def harvesters(opt):
"scripts",
opt.path_harvesters)
if not os.path.exists(path):
print "\n\tFile {0} don't exist!".format(path)
sys.exit(1)
dh = (pd.read_csv(path)
.dropna(how="all", axis="index")
.drop("comment", axis="columns"))
......@@ -455,6 +430,10 @@ def institute(opt):
"scripts",
opt.institute)
if not os.path.exists(path):
print "\n\tFile {0} don't exist!".format(path)
sys.exit(1)
df = pd.read_csv(path)
# rename columns
......@@ -480,8 +459,6 @@ def institute(opt):
if __name__ == "__main__":
print "\n%s\nStart deploy" % ("."*80,)
# pandas options and matplotlib style
pd.set_option("display.encoding", "utf-8")
pd.set_option("display.width", 150)
......@@ -495,10 +472,9 @@ if __name__ == "__main__":
help="create the affiliation keys [%(default)s].")
PARSER.add_argument(
"--all",
"-c", "--commit",
action="store_true",
help="create everything [%(default)s]. "
"Equivalent to --affiliation --teams --harvesters.")
help="commit change to the database [%(default)s]. ")
PARSER.add_argument(
"-H", "--harvesters",
......@@ -526,17 +502,31 @@ if __name__ == "__main__":
OPT = PARSER.parse_args()
DFH = harvesters(OPT)
if not (OPT.harvesters or OPT.teams or OPT.affiliation):
print "\n\tPlease select an option!"
print "\tPossible ones are --affiliation, --harvesters or --teams"
sys.exit(1)
print "\n%s\nStart deploy" % ("."*80,)
DFI = institute(OPT)
DFH = harvesters(OPT)
if OPT.teams or OPT.all:
if OPT.teams:
create_teams_projects(OPT, DFI)
if OPT.harvesters or OPT.all:
if OPT.harvesters:
create_harvesters(OPT, DFI, DFH)
if OPT.affiliation or OPT.all:
if OPT.affiliation:
create_affiliation(OPT)
if OPT.commit():
print "\n\tChange are committed to the database."
db.commit()
else:
print "\n\tDry run, the database is not modified."
print "\nEnd deploy\n%s\n" % ("."*80, )
sys.exit(0)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment