#27 Add Update Command
Closed 2 years ago by zbyszek. Opened 7 years ago by mich181189.
fedora-rust/ mich181189/rust2rpm add-update  into  master

file modified
+29
@@ -175,6 +175,8 @@ 

                          help="Distribution target")

      parser.add_argument("-p", "--patch", action="store_true",

                          help="Do initial patching of Cargo.toml")

+     parser.add_argument("-u", "--update", action="store_true",

+                         help="check for and apply updates to spec file")

      parser.add_argument("crate", help="crates.io name")

      parser.add_argument("version", nargs="?", help="crates.io version")

      args = parser.parse_args()
@@ -182,6 +184,16 @@ 

      if args.patch:

          editor = detect_editor()

  

+     # If the -u flag is specified, the crate is currently a spec file

+     spec_file = None

+     if args.update:

+         spec_file = args.crate

that's not always like this.... sometimes it's rust-%crate, sometimes it's %crate

Ah hehe - this is actually because I was using this like:

rust2rpm -u rust-sdl.spec

and in that case args.crate actually contains the spec file name - then we pull the crate out of the spec file.

I did it this way precisely because it takes a lot of parsing to get it right otherwise, and I didn't really want to have to get the crate if the version hasn't changed

+         with open(args.crate) as f:

+             for line in f:

+                 if line.startswith("%global crate"):

+                     args.crate = line[13:].strip()

+                     break

+ 

      if args.version is None:

          # Now we need to get latest version

          url = requests.compat.urljoin(API_URL, "crates/{}/versions".format(args.crate))
@@ -189,6 +201,23 @@ 

          req.raise_for_status()

          args.version = req.json()["versions"][0]["num"]

  

+     if args.update:

+         spec_file_contents = []

+         with open(spec_file) as f:

+             for line in f:

+                 if line.startswith("Version:"):

+                     versionstring = line[8:].strip()

+                     if args.version == versionstring:

+                         print("Already up to date")

+                         exit(1)

+                     spec_file_contents.append("Version:        {}\n".format(args.version))

that's not enough for update, you should always update (Build)Requires as well

I thought about that, but sometimes I've patched the requires lines so I figured it would make more sense to not touch them (as a first pass)

Maybe it should apply all the patches then parse out the requires from the patched crate...

+                     print("Updating to {}".format(args.version))

+                 else:

+                     spec_file_contents.append(line)

+         with open(spec_file, "w") as f:

+             f.writelines(spec_file_contents)

+     exit(0)

and this exits unconditionally :)

Gah fail! I must admit when I wrote this line I wondered if I had got the indentation right!

Damn significant whitespace language! ;-)

+ 

      if not os.path.isdir(CACHEDIR):

          os.mkdir(CACHEDIR)

      cratef_base = "{}-{}.crate".format(args.crate, args.version)

Feel free to reject this if you have something else in mind.

This commit adds a new option - -u/--update which when set and a spec file
is passed in, parses out the version and crate from the spec file, and checks
for updates, modifying the spec file if needed to update the package.

It does not change any dependencies since these may have been manually
modified.

that's not always like this.... sometimes it's rust-%crate, sometimes it's %crate

that's not enough for update, you should always update (Build)Requires as well

and this exits unconditionally :)

Ah hehe - this is actually because I was using this like:

rust2rpm -u rust-sdl.spec

and in that case args.crate actually contains the spec file name - then we pull the crate out of the spec file.

I did it this way precisely because it takes a lot of parsing to get it right otherwise, and I didn't really want to have to get the crate if the version hasn't changed

I thought about that, but sometimes I've patched the requires lines so I figured it would make more sense to not touch them (as a first pass)

Maybe it should apply all the patches then parse out the requires from the patched crate...

Gah fail! I must admit when I wrote this line I wondered if I had got the indentation right!

Damn significant whitespace language! ;-)

This is 4 years old at this point… Even if there are some good ideas, it'll need to be done from scratch anyway. I'll close it to keep the pull request list tidy.

Pull-Request has been closed by zbyszek

2 years ago
Metadata