def edit(args): fkt = "edit.edit" # parse arguments try: opts, args = getopt.getopt(args, "hd", ["help"]) except getopt.GetoptError as err: print(err) # will print something like "option -a not recognized" sys.exit(2) promtall = False if len(args) == 0: promtall = True # Read the current id from current-file id = readcid() # read the invoice-data from object-files fol_obj = os.path.join(fol_invobjects,id) objdata = invdata for i in objdata: f = open(os.path.join(fol_obj,i[0]), "r") i[1] = f.readline() f.close() # edit the data if promtall == False: count = 0 for i in args: for k in objdata: if i == k[0]: try: k[1] = args[count+1] except: mprint(fkt,1,"Wrong arguments given") count = count +1 # Promt through all the data else: for i in objdata: print(i[2]+":\n "+i[1]) k = input(" >") if len(k) != 0: i[1] = k # write the data back for i in objdata: f = open(os.path.join(fol_obj,i[0]), "w") f.write(i[1]) f.close()
def new(args): fkt = "new.new" # parse options try: opts, args = getopt.getopt(args, "hd", ["help"]) except getopt.GetoptError as err: print(err) # will print something like "option -a not recognized" sys.exit(2) for o,a in opts: if o == "-d": writedefaults = True else: print("Undefined Arg or Option: "+ o) sys.exit(2) if len(args) != 1: mprint(fkt,1,"Exactly one argument required. bye ...") sys.exit(4) else: i_id = args[0] # check whether a folder with the given id exists if os.path.exists(os.path.join(fol_invobjects,i_id)) == True: mprint(fkt,1,"Invoice Id exists. Exiting ...") sys.exit(4) # check whether a .inv folder exits: if os.path.exists(fol) == False: mprint(fkt,1,"No Repo exits. bye ...") sys.exit(4) else: mprint(fkt,1,"Creating a new Invobject ...") # Create the Object-folder fol_instanz = os.path.join(fol_invobjects,i_id) os.mkdir(fol_instanz) # Create invoice data files for i in invdata: os.mknod(os.path.join(fol_instanz,i[0])) # feed the files with the hardcoded defaults if writedefaults == True: for i in invdata: f = open(os.path.join(fol_instanz,i[0]), "w") f.write(str(i[1])) f.close # Set the current id f = open(fil_cur, "w") f.write(i_id) f.close()
def create(): fkt = "create.create" if os.path.isfile(fil_cur) == False: mprint(fkt,1,"Current Invoice id doesnt exists. Exiting") sys.exit(5) # Read the current id from current-file id = readcid() # read the blueprint tex-file try: texfile = open(fil_pattern, "r") except: mprint(fkt,1,"No blueprint exists. Exiting") sys.exit() texfilestr = texfile.read() # read the invoice-data from object-files fol_obj = os.path.join(fol_invobjects,id) objdata = invdata for i in objdata: f = open(os.path.join(fol_obj,i[0]), "r") i[1] = f.readline() f.close() # create the substitute - list for i in objdata: i[0] = r"\$" + i[0] # substitute ! texfilestr = subinstr(objdata,texfilestr) # create output tex-file fil_texsrc = os.path.join(fol_obj,"src.tex") f = open(fil_texsrc, "w") f.write(texfilestr) f.close mprint(fkt,1,"Texfile written.") # creating the pdf in the root-folder writepdf(fil_texsrc)